|
676 | 676 |
|
677 | 677 | @testitem "datetime" begin |
678 | 678 | using Dates |
| 679 | + using CondaPkg |
| 680 | + CondaPkg.add("numpy") |
| 681 | + |
679 | 682 | dt = pyimport("datetime") |
680 | 683 | x1 = pydate(2001, 2, 3) |
681 | 684 | @test pyisinstance(x1, dt.date) |
|
701 | 704 | x8 = pydatetime(2001, 2, 3, 4, 5, 6, 7) |
702 | 705 | dx = pytimedelta(366, 3661, 1) |
703 | 706 | pyeq(Bool, x8 - x6, dx) |
| 707 | + |
| 708 | + td = pyimport("datetime").timedelta |
| 709 | + @testset for x in [ |
| 710 | + -1_000_000_000, |
| 711 | + -1_000_000, |
| 712 | + -1_000, |
| 713 | + -1, |
| 714 | + 0, |
| 715 | + 1, |
| 716 | + 1_000, |
| 717 | + 1_000_000, |
| 718 | + 1_000_000_000, |
| 719 | + ], (Unit, unit, pyunit, factor) in [ |
| 720 | + (Microsecond, :microseconds, :microseconds, 1), |
| 721 | + (Millisecond, :milliseconds, :milliseconds, 1), |
| 722 | + (Second, :seconds, :seconds, 1), |
| 723 | + (Minute, :minutes, :seconds, 60), |
| 724 | + (Hour, :hours, :hours, 1), |
| 725 | + (Day, :days, :days, 1), |
| 726 | + (Week, :weeks, :days, 7) |
| 727 | + ] |
| 728 | + # for day and week units, skip large values due to overflow |
| 729 | + unit in [:days, :weeks] && abs(x) > 1_000_000 && continue |
| 730 | + y = pytimedelta(; [unit => x]...) |
| 731 | + y2 = pytimedelta(Unit(x)) |
| 732 | + @test pyeq(Bool, y, y2) |
| 733 | + @test pyeq(Bool, y, td(; [pyunit => x * factor]...)) |
| 734 | + end |
704 | 735 | end |
705 | 736 |
|
706 | 737 | @testitem "code" begin |
|
0 commit comments