Skip to content

Commit 6bd1c4e

Browse files
committed
Added tests for explicit UTC offset.
1 parent 80e9bb3 commit 6bd1c4e

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

tests/test_date.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,26 @@ def jd():
4949
return 2451545.25 # 2000-01-01 18:00 UT
5050

5151

52-
def test_timezone_gmt(gmt_coords):
52+
def test_timezone_name_gmt(gmt_coords):
5353
assert date.timezone_name(*gmt_coords) == 'Europe/London'
5454

5555

56-
def test_timezone_pst(pst_coords):
56+
def test_timezone_name_pst(pst_coords):
5757
assert date.timezone_name(*pst_coords) == 'America/Los_Angeles'
5858

5959

60-
def test_localize(pst_coords):
60+
def test_localize_coords(pst_coords):
6161
dt = datetime(2000, 1, 1, 18)
6262
aware = date.localize(dt, *pst_coords)
6363
assert aware.tzinfo == ZoneInfo('America/Los_Angeles')
6464

6565

66+
def test_localize_offset(gmt_coords, jd):
67+
dt = datetime(2000, 1, 1, 10)
68+
aware = date.localize(dt, *gmt_coords, offset=-8.0)
69+
assert date.to_jd(aware) == jd
70+
71+
6672
def test_localize_dst(ambiguous_date, pst_coords):
6773
dt_no_dst = date.localize(ambiguous_date, *pst_coords, is_dst=False)
6874
dt_dst = date.localize(ambiguous_date, *pst_coords, is_dst=True)
@@ -77,15 +83,12 @@ def test_ambiguous(ambiguous_date, pst_date):
7783
assert date.ambiguous(pst_date) is False
7884

7985

80-
def test_to_jd(str_pst_date, gmt_date, pst_date, pst_coords, jd):
81-
jd_original = date.to_jd(jd)
82-
jd_from_str = date.to_jd(str_pst_date, *pst_coords)
83-
jd_gmt = date.to_jd(gmt_date)
84-
jd_pst = date.to_jd(pst_date)
85-
assert jd_original == jd
86-
assert jd_from_str == jd
87-
assert jd_gmt == jd
88-
assert jd_pst == jd
86+
def test_to_jd(str_pst_date, gmt_date, pst_date, pst_coords, gmt_coords, jd):
87+
assert date.to_jd(jd) == jd
88+
assert date.to_jd(str_pst_date, *pst_coords) == jd
89+
assert date.to_jd(str_pst_date, *gmt_coords, offset=-8.0) == jd
90+
assert date.to_jd(gmt_date) == jd
91+
assert date.to_jd(pst_date) == jd
8992

9093

9194
def test_to_datetime_gmt(gmt_date, str_gmt_date, gmt_coords, jd):
@@ -126,7 +129,7 @@ def test_to_datetime_gmt(gmt_date, str_gmt_date, gmt_coords, jd):
126129
assert utc_dt_from_jd.tzinfo == ZoneInfo('UTC')
127130

128131

129-
def test_to_datetime_pst(pst_date, str_pst_date, pst_coords, jd):
132+
def test_to_datetime_pst(pst_date, str_pst_date, pst_coords, gmt_coords, jd):
130133
dt_original = date.to_datetime(pst_date)
131134
assert dt_original.year == 2000
132135
assert dt_original.month == 1
@@ -153,3 +156,11 @@ def test_to_datetime_pst(pst_date, str_pst_date, pst_coords, jd):
153156
assert dt_from_jd.minute == 0
154157
assert dt_from_jd.second == 0
155158
assert dt_from_jd.tzinfo == ZoneInfo('America/Los_Angeles')
159+
160+
dt_from_offset = date.to_datetime(jd, *gmt_coords, offset=-8.0)
161+
assert dt_from_offset.year == 2000
162+
assert dt_from_offset.month == 1
163+
assert dt_from_offset.day == 1
164+
assert dt_from_offset.hour == 10
165+
assert dt_from_offset.minute == 0
166+
assert dt_from_offset.second == 0

0 commit comments

Comments
 (0)