Skip to content

Commit 22ac8c7

Browse files
author
boraxpr
committed
83
1 parent 73f4954 commit 22ac8c7

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

83/test_timezone.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from datetime import datetime
2+
3+
from timezone import what_time_lives_pybites
4+
5+
6+
def test_what_time_lives_pybites_spanish_summertime():
7+
# AUS is 8 hours ahead of ES
8+
naive_utc_dt = datetime(2018, 4, 27, 22, 55, 0)
9+
aus_dt, es_dt = what_time_lives_pybites(naive_utc_dt)
10+
11+
assert aus_dt.year == 2018
12+
assert aus_dt.month == 4
13+
assert aus_dt.day == 28
14+
assert aus_dt.hour == 8
15+
assert aus_dt.minute == 55
16+
17+
assert es_dt.year == 2018
18+
assert es_dt.month == 4
19+
assert es_dt.day == 28
20+
assert es_dt.hour == 0
21+
assert es_dt.minute == 55
22+
23+
24+
def test_what_time_lives_pybites_spanish_wintertime():
25+
# AUS is 10 hours ahead of ES
26+
naive_utc_dt = datetime(2018, 11, 1, 14, 10, 0)
27+
aus_dt, es_dt = what_time_lives_pybites(naive_utc_dt)
28+
29+
assert aus_dt.year == 2018
30+
assert aus_dt.month == 11
31+
assert aus_dt.day == 2
32+
assert aus_dt.hour == 1
33+
assert aus_dt.minute == 10
34+
35+
assert es_dt.year == 2018
36+
assert es_dt.month == 11
37+
assert es_dt.day == 1
38+
assert es_dt.hour == 15
39+
assert es_dt.minute == 10

83/timezone.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from datetime import datetime
2+
3+
from pytz import timezone, utc
4+
5+
AUSTRALIA = timezone('Australia/Sydney')
6+
SPAIN = timezone('Europe/Madrid')
7+
# naive_utc_dt = datetime(2018, 4, 27, 22, 55, 0)
8+
9+
10+
def what_time_lives_pybites(naive_utc_dt):
11+
"""Receives a naive UTC datetime object and returns a two element
12+
tuple of Australian and Spanish (timezone aware) datetimes"""
13+
aware_dt = utc.localize(naive_utc_dt)
14+
aus_dt = aware_dt.astimezone(AUSTRALIA)
15+
es_dt = aware_dt.astimezone(SPAIN)
16+
return aus_dt,es_dt
17+
18+
19+
# aus_dt, es_dt = what_time_lives_pybites(naive_utc_dt)
20+
# print(aus_dt.__str__() + " //////" + es_dt.__str__())

0 commit comments

Comments
 (0)