MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / test_precise_diff

Function test_precise_diff

tests/test_helpers.py:37–86  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

35
36
37def test_precise_diff() -> None:
38 dt1 = datetime(2003, 3, 1, 0, 0, 0)
39 dt2 = datetime(2003, 1, 31, 23, 59, 59)
40
41 diff = precise_diff(dt1, dt2)
42 assert_diff(diff, months=-1, seconds=-1)
43
44 diff = precise_diff(dt2, dt1)
45 assert_diff(diff, months=1, seconds=1)
46
47 dt1 = datetime(2012, 3, 1, 0, 0, 0)
48 dt2 = datetime(2012, 1, 31, 23, 59, 59)
49
50 diff = precise_diff(dt1, dt2)
51 assert_diff(diff, months=-1, seconds=-1)
52 assert diff.total_days == -30
53
54 diff = precise_diff(dt2, dt1)
55 assert_diff(diff, months=1, seconds=1)
56
57 dt1 = datetime(2001, 1, 1)
58 dt2 = datetime(2003, 9, 17, 20, 54, 47, 282310)
59
60 diff = precise_diff(dt1, dt2)
61 assert_diff(
62 diff,
63 years=2,
64 months=8,
65 days=16,
66 hours=20,
67 minutes=54,
68 seconds=47,
69 microseconds=282310,
70 )
71
72 dt1 = datetime(2017, 2, 17, 16, 5, 45, 123456)
73 dt2 = datetime(2018, 2, 17, 16, 5, 45, 123256)
74
75 diff = precise_diff(dt1, dt2)
76 assert_diff(
77 diff, months=11, days=30, hours=23, minutes=59, seconds=59, microseconds=999800
78 )
79
80 # DST
81 tz = timezone("America/Toronto")
82 dt1 = tz.datetime(2017, 3, 7)
83 dt2 = tz.datetime(2017, 3, 13)
84
85 diff = precise_diff(dt1, dt2)
86 assert_diff(diff, days=6, hours=0)
87
88
89def test_precise_diff_timezone() -> None:

Callers

nothing calls this directly

Calls 5

precise_diffFunction · 0.90
timezoneFunction · 0.90
datetimeFunction · 0.85
assert_diffFunction · 0.85
datetimeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…