aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas la Cour <tlc@hyrtwol.dk>2024-07-26 10:45:09 +0200
committerThomas la Cour <tlc@hyrtwol.dk>2024-07-26 10:45:09 +0200
commitb149b3d6c6d8749b4e33fb1b25e4f77140cf0eef (patch)
treea9824db06422367a03a34adccafc0a4e60d74668 /tests
parent03f3ea5a9e40b4636238ee840845b66a585ad5e4 (diff)
parent4e194d5dbdb40f5b0ea826c85b11303cdda81eda (diff)
Merge remote-tracking branch 'upstream/master' into sys-windows-2
Diffstat (limited to 'tests')
-rw-r--r--tests/core/time/test_core_time.odin37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/core/time/test_core_time.odin b/tests/core/time/test_core_time.odin
index aeae44ca1..c408bc582 100644
--- a/tests/core/time/test_core_time.odin
+++ b/tests/core/time/test_core_time.odin
@@ -7,6 +7,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.")
testing.expect(t, dt.unsafe_date_to_ordinal(dt.unsafe_ordinal_to_date(dt.MIN_ORD)) == dt.MIN_ORD, "Roundtripping MIN_ORD failed.")