Skip to content

Commit 95ba023

Browse files
authored
test: cover early-year ordinal format round trips
1 parent 7e1df9c commit 95ba023

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎tests/datetime/test_from_format.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,36 @@ def test_from_format_2_digit_year():
220220

221221
d = pendulum.from_format("99", "YY")
222222
assert d.year == 1999
223+
224+
225+
@pytest.mark.parametrize("fmt", ["YYYY-DDD", "YYYY-DDDD"])
226+
@pytest.mark.parametrize(
227+
"year,month,day",
228+
[
229+
(1, 1, 31),
230+
(99, 12, 31),
231+
(400, 2, 29),
232+
(999, 1, 31),
233+
(1000, 1, 31),
234+
(9999, 12, 31),
235+
],
236+
)
237+
def test_from_format_day_of_year_round_trip(fmt, year, month, day):
238+
expected = pendulum.datetime(year, month, day)
239+
240+
assert pendulum.from_format(expected.format(fmt), fmt) == expected
241+
242+
243+
def test_from_format_day_of_year_preserves_time_and_offset():
244+
d = pendulum.from_format(
245+
"0075-032 12:34:56.123456 +05:30", "YYYY-DDDD HH:mm:ss.SSSSSS Z"
246+
)
247+
248+
assert_datetime(d, 75, 2, 1, 12, 34, 56, 123456)
249+
assert d.utcoffset().total_seconds() == 19800
250+
251+
252+
@pytest.mark.parametrize("text", ["0001-366", "0400-367", "0000-031"])
253+
def test_from_format_day_of_year_rejects_invalid_dates(text):
254+
with pytest.raises(ValueError):
255+
pendulum.from_format(text, "YYYY-DDDD")

0 commit comments

Comments
 (0)