1+ @testitem " timedelta64" begin
2+ using Dates
3+ using CondaPkg
4+ CondaPkg. add (" numpy" )
5+
6+ td = pyimport (" numpy" ). timedelta64
7+ @testset for x in [
8+ - 1_000_000_000 ,
9+ - 1_000_000 ,
10+ - 1_000 ,
11+ - 1 ,
12+ 0 ,
13+ 1 ,
14+ 1_000 ,
15+ 1_000_000 ,
16+ 1_000_000_000 ,
17+ ], (Unit, unit, pyunit) in [
18+ (Nanosecond, :nanoseconds , :ns ),
19+ (Microsecond, :microseconds , :us ),
20+ (Millisecond, :milliseconds , :ms ),
21+ (Second, :seconds , :s ),
22+ (Minute, :minutes , :m ),
23+ (Hour, :hours , :h ),
24+ (Day, :days , :D ),
25+ (Week, :weeks , :W ),
26+ (Month, :months , :M ),
27+ (Year, :years , :Y ),
28+ ]
29+ y = pytimedelta64 (; [unit => x]. .. )
30+ y2 = pytimedelta64 (Unit (x))
31+ @test pyeq (Bool, y, y2)
32+ @test pyeq (Bool, y, td (x, " $pyunit " ))
33+ end
34+ end
35+
36+ @testitem " datetime64" begin
37+ using Dates
38+ using CondaPkg
39+ CondaPkg. add (" numpy" )
40+
41+ y = 2024
42+ m = 2
43+ d = 29
44+ h = 23
45+ min = 59
46+ s = 58
47+ ms = 999
48+ us = 998
49+ ns = 997
50+
51+ date = DateTime (y, m, d, h, min, s, ms)
52+ pydate = pydatetime64 (date)
53+ pydate2 = pydatetime64 (year = y, month = m, day = d, hour = h, minute = min, second = s, millisecond = ms)
54+ dt = date - Second (0 )
55+ pydate3 = pydatetime64 (dt)
56+ @test pyeq (Bool, pydate, pydate2)
57+ end
0 commit comments