31 lines
903 B
Python
31 lines
903 B
Python
|
from datetime import datetime
|
||
|
from zoneinfo import ZoneInfo
|
||
|
|
||
|
from timedeltacal import timedeltacal
|
||
|
|
||
|
# Some basic tests. These serve as a specification. All the tests use timezone
|
||
|
# aware datetimes in a timezone with DST, since this is the most complex case.
|
||
|
# Naive datetimes and dates should work analogously.
|
||
|
|
||
|
def test_create_from_components():
|
||
|
d = timedeltacal(
|
||
|
years=1,
|
||
|
months=2,
|
||
|
weeks=3,
|
||
|
days=4,
|
||
|
hours=5,
|
||
|
minutes=6,
|
||
|
seconds=7,
|
||
|
microseconds=8
|
||
|
)
|
||
|
# I haven't decided on canonicalizing years to months, so for now I accept
|
||
|
# both:
|
||
|
assert d.months in (2, 14)
|
||
|
# But I am sure that I want to canonicalize weeks to days
|
||
|
assert d.days == 25
|
||
|
# Rest is straightforward:
|
||
|
assert d.hours == 5
|
||
|
assert d.minutes == 6
|
||
|
assert d.seconds == 7
|
||
|
assert d.microseconds == 8
|