Skip to content

Commit 77ede0b

Browse files
author
Calvin Gutierrez
committed
bite 128 complete
1 parent fe0ee49 commit 77ede0b

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

days/01-03-datetimes/bite128.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from datetime import datetime
2+
3+
THIS_YEAR = 2018
4+
5+
6+
def years_ago(date):
7+
"""Receives a date string of 'DD MMM, YYYY', for example: 8 Aug, 2015
8+
Convert this date str to a datetime object (use strptime).
9+
Then extract the year from the obtained datetime object and subtract
10+
it from the THIS_YEAR constant above, returning the int difference.
11+
So in this example you would get: 2018 - 2015 = 3"""
12+
ex_time = datetime.strptime(date, '%d %b, %Y')
13+
year_extract = ex_time.year
14+
return abs(year_extract - THIS_YEAR)
15+
16+
17+
def convert_eu_to_us_date(date):
18+
"""Receives a date string in European format of dd/mm/yyyy, e.g. 11/03/2002
19+
Convert it to an American date: mm/dd/yyyy (in this case 03/11/2002).
20+
To enforce the use of datetime's strptime / strftime (over slicing)
21+
the tests check if a ValueError is raised for invalid day/month/year
22+
ranges (no need to code this, datetime does this out of the box)"""
23+
eu_format = datetime.strptime(date, '%d/%m/%Y')
24+
usa_format = eu_format.strftime('%m/%d/%Y')
25+
return usa_format

days/01-03-datetimes/bite67.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,3 @@ def get_hundred_days_end_date():
1818
def get_days_between_pb_start_first_joint_pycon():
1919
days_between = pycon_date - pybites_founded
2020
return days_between.days
21-
22-
23-

days/01-03-datetimes/playground.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
datetime # imports use of date and time ; year,month ,day , hours , minutes, seconds , milliseconds
33
from datetime import date # imports use of just date ; year , month , day
44
from datetime import timedelta
5+
import time
56

67

78
def main():
@@ -21,8 +22,7 @@ def main():
2122
pomodoro_1 = timedelta(seconds=1)
2223
play_time = timedelta(seconds=30)
2324
print(play_time - pomodoro_1)
24-
day100 = timedelta(days=100)
25-
print(day100)
25+
print(time.strptime("02/12/1996 5:53", "%m/%d/%Y %H:%M"))
2626

2727

2828

0 commit comments

Comments
 (0)