|
1 | | -@testitem "Date -> DateTime64" begin |
| 1 | +@testitem "DateTime64 from Date" begin |
2 | 2 | using Dates |
3 | 3 | using PythonCall: NumpyDates |
4 | 4 |
|
|
100 | 100 | end |
101 | 101 | end |
102 | 102 |
|
103 | | -@testitem "String -> DateTime64" begin |
| 103 | +@testitem "DateTime64 from String" begin |
104 | 104 | using Dates |
105 | 105 | using PythonCall: NumpyDates |
106 | 106 |
|
|
199 | 199 | end |
200 | 200 | end |
201 | 201 |
|
202 | | -@testitem "String and DateFormat -> DateTime64" begin |
| 202 | +@testitem "DateTime64 from String and DateFormat" begin |
203 | 203 | using Dates |
204 | 204 | using PythonCall: NumpyDates |
205 | 205 |
|
|
237 | 237 | end |
238 | 238 | end |
239 | 239 |
|
240 | | -@testitem "AbstractDateTime64 -> DateTime64" begin |
| 240 | +@testitem "DateTime64 from AbstractDateTime64" begin |
241 | 241 | using Dates |
242 | 242 | using PythonCall: NumpyDates |
243 | 243 |
|
|
255 | 255 | @test NumpyDates.unitpair(z) == NumpyDates.unitpair(:s) |
256 | 256 | end |
257 | 257 |
|
258 | | -@testitem "Integer -> DateTime64" begin |
| 258 | +@testitem "DateTime64 from Integer" begin |
259 | 259 | using Dates |
260 | 260 | using PythonCall: NumpyDates |
261 | 261 |
|
|
279 | 279 | @test Dates.DateTime(s2) == DateTime(1970, 1, 1, 1, 0, 0) |
280 | 280 | end |
281 | 281 |
|
282 | | -@testitem "DateTime -> DateTime64/InlineDateTime64" begin |
| 282 | +@testitem "DateTime64 from DateTime" begin |
283 | 283 | using Dates |
284 | 284 | using PythonCall: NumpyDates |
285 | 285 |
|
|
385 | 385 | @test NumpyDates.unitpair(inline_dyn) == NumpyDates.unitpair(usym) |
386 | 386 | end |
387 | 387 | end |
| 388 | + |
| 389 | +@testitem "DateTime64 show" begin |
| 390 | + using Dates |
| 391 | + using PythonCall: NumpyDates |
| 392 | + |
| 393 | + # Helper to get "showvalue" form by setting :typeinfo to the concrete type |
| 394 | + function showvalue_string(x) |
| 395 | + io = IOBuffer() |
| 396 | + show(IOContext(io, :typeinfo => typeof(x)), x) |
| 397 | + String(take!(io)) |
| 398 | + end |
| 399 | + |
| 400 | + # Helper to get the default Base.show output (with type wrapper) |
| 401 | + function show_string(x) |
| 402 | + io = IOBuffer() |
| 403 | + show(io, x) |
| 404 | + String(take!(io)) |
| 405 | + end |
| 406 | + |
| 407 | + # Cases: (kind, value, unit_symbol, expected_showvalue_string) |
| 408 | + cases = [ |
| 409 | + # 1) Days-aligned: prints Date in value form |
| 410 | + (Date(1999, 12, 31), :D, "\"1999-12-31\"", "DAYS"), |
| 411 | + |
| 412 | + # 2) Seconds-aligned: prints DateTime in value form |
| 413 | + (DateTime(1999, 12, 31, 23, 59, 59), :s, "\"1999-12-31T23:59:59\"", "SECONDS"), |
| 414 | + |
| 415 | + # 3) Sub-millisecond units: fall back to raw integer in value form |
| 416 | + (1, :us, "1", "MICROSECONDS"), |
| 417 | + (1, :ns, "1", "NANOSECONDS"), |
| 418 | + |
| 419 | + # 4) Calendar units (years/months): value form shows truncated Date |
| 420 | + (Date(2000, 2, 29), :Y, "\"2000-01-01\"", "YEARS"), |
| 421 | + (Date(1999, 12, 31), :M, "\"1999-12-01\"", "MONTHS"), |
| 422 | + |
| 423 | + # 5) NaT |
| 424 | + ("NaT", :D, "\"NaT\"", "DAYS"), |
| 425 | + ] |
| 426 | + |
| 427 | + @testset "$v $usym" for (v, usym, expected_val, ustr) in cases |
| 428 | + # Construct DateTime64 |
| 429 | + x = NumpyDates.DateTime64(v, usym) |
| 430 | + |
| 431 | + # showvalue checks |
| 432 | + s_val = showvalue_string(x) |
| 433 | + @test s_val == expected_val |
| 434 | + |
| 435 | + # default show checks |
| 436 | + s_def = show_string(x) |
| 437 | + @test s_def == "PythonCall.NumpyDates.DateTime64($expected_val, $ustr)" |
| 438 | + |
| 439 | + # and again with InlineDateTime64 |
| 440 | + x2 = NumpyDates.InlineDateTime64(v, usym) |
| 441 | + s_val2 = showvalue_string(x2) |
| 442 | + @test s_val2 == expected_val |
| 443 | + s_def2 = show_string(x2) |
| 444 | + @test s_def2 == |
| 445 | + "PythonCall.NumpyDates.InlineDateTime64{PythonCall.NumpyDates.$ustr}($expected_val)" |
| 446 | + end |
| 447 | +end |
0 commit comments