Last active
January 29, 2017 09:00
-
-
Save serashioda/3619a51d4c66cabeec55ada8ea16e24a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import datefinder | |
from dateutil.relativedelta import relativedelta | |
def date_rollback(large_string, date_formatter): | |
dates = list(datefinder.find_dates(large_string)) | |
result = large_string | |
for date in dates: | |
to_find = date.strftime("%m/%d/%Y") | |
rollback = date - relativedelta(years=100) | |
datemod = rollback.strftime(date_formatter) | |
result = result.replace(str(to_find), str(datemod)) | |
return result | |
result = date_rollback("I moved to the U.S. on 06/21/1993 but moved to Nevada on 07/12/2008.", "%d/%m/%Y") | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write a function that takes two arguments, one large string and one smaller string. | |
The larger string will contain (amongst other text) dates of the format MM/DD/YYYY. | |
The smaller string will contain a date format, like "%b %d, %Y" or "%d/%m/%Y" or any valid date format string. | |
Your job will be to return the large text string with the dates rolled back by one century and formatted with whatever format was in the smaller string. | |
The dates you should consider will be any year between 1100 and 9999 AD. | |
Submit this thru canvas on the class website, you should be able to find the assignment...I will post a link |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment