Merge remote-tracking branch 'upstream/master' into sys-windows-2

This commit is contained in:
Thomas la Cour
2024-07-26 10:45:09 +02:00
2 changed files with 358 additions and 32 deletions

View File

@@ -6,6 +6,43 @@ import dt "core:time/datetime"
is_leap_year :: time.is_leap_year
@test
test_time_and_date_formatting :: proc(t: ^testing.T) {
buf: [64]u8
{
now := time.Time{_nsec=min(i64)} // 1677-09-21 00:12:44.145224192 +0000 UTC
d := time.Duration(now._nsec)
testing.expect_value(t, time.to_string_hms (now, buf[:]), "00:12:44")
testing.expect_value(t, time.to_string_hms_12 (now, buf[:]), "00:12:44 am")
testing.expect_value(t, time.to_string_hms_12 (now, buf[:], {"㏂", "㏘"}), "00:12:44㏂")
testing.expect_value(t, time.to_string_hms (d, buf[:]), "00:12:44")
testing.expect_value(t, time.to_string_yyyy_mm_dd(now, buf[:]), "1677-09-21")
testing.expect_value(t, time.to_string_yy_mm_dd (now, buf[:]), "77-09-21")
testing.expect_value(t, time.to_string_dd_mm_yyyy(now, buf[:]), "21-09-1677")
testing.expect_value(t, time.to_string_dd_mm_yy (now, buf[:]), "21-09-77")
testing.expect_value(t, time.to_string_mm_dd_yyyy(now, buf[:]), "09-21-1677")
testing.expect_value(t, time.to_string_mm_dd_yy (now, buf[:]), "09-21-77")
}
{
now := time.Time{_nsec=max(i64)} // 2262-04-11 23:47:16.854775807 +0000 UTC
d := time.Duration(now._nsec)
testing.expect_value(t, time.to_string_hms (now, buf[:]), "23:47:16")
testing.expect_value(t, time.to_string_hms_12 (now, buf[:]), "11:47:16 pm")
testing.expect_value(t, time.to_string_hms_12 (now, buf[:], {"㏂", "㏘"}), "11:47:16㏘")
testing.expect_value(t, time.to_string_hms (d, buf[:]), "23:47:16")
testing.expect_value(t, time.to_string_yyyy_mm_dd(now, buf[:]), "2262-04-11")
testing.expect_value(t, time.to_string_yy_mm_dd (now, buf[:]), "62-04-11")
testing.expect_value(t, time.to_string_dd_mm_yyyy(now, buf[:]), "11-04-2262")
testing.expect_value(t, time.to_string_dd_mm_yy (now, buf[:]), "11-04-62")
testing.expect_value(t, time.to_string_mm_dd_yyyy(now, buf[:]), "04-11-2262")
testing.expect_value(t, time.to_string_mm_dd_yy (now, buf[:]), "04-11-62")
}
}
@test
test_ordinal_date_roundtrip :: proc(t: ^testing.T) {
testing.expect(t, dt.unsafe_ordinal_to_date(dt.unsafe_date_to_ordinal(dt.MIN_DATE)) == dt.MIN_DATE, "Roundtripping MIN_DATE failed.")