summaryrefslogtreecommitdiff
path: root/lib/mlibc/tests/ansi/timegm.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:00 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 17:28:32 -0500
commitbd5969fc876a10b18613302db7087ef3c40f18e1 (patch)
tree7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/tests/ansi/timegm.c
parenta95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff)
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/tests/ansi/timegm.c')
-rw-r--r--lib/mlibc/tests/ansi/timegm.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/mlibc/tests/ansi/timegm.c b/lib/mlibc/tests/ansi/timegm.c
new file mode 100644
index 0000000..f5af03e
--- /dev/null
+++ b/lib/mlibc/tests/ansi/timegm.c
@@ -0,0 +1,45 @@
+#include <time.h>
+#include <stdio.h>
+#include <assert.h>
+
+int main() {
+ struct tm soon = {};
+ soon.tm_sec = 0;
+ soon.tm_min = 0;
+ soon.tm_hour = 0;
+ soon.tm_mday = 1;
+ soon.tm_mon = 0;
+ soon.tm_year = 70;
+ time_t result;
+ time_t expected_result = 0;
+ // This should be epoch.
+ result = timegm(&soon);
+ printf("epoch: %ld\n", result);
+ assert(result == expected_result);
+
+ soon.tm_sec = 12;
+ soon.tm_min = 8;
+ soon.tm_hour = 16;
+ soon.tm_mday = 17;
+ soon.tm_mon = 4;
+ soon.tm_year = 122;
+ expected_result = 1652803692;
+ result = timegm(&soon);
+ // On my host, this returned 1652803692, verify this.
+ printf("epoch: %ld\n", result);
+ assert(result == expected_result);
+
+ soon.tm_sec = 45;
+ soon.tm_min = 42;
+ soon.tm_hour = 17;
+ soon.tm_mday = 16;
+ soon.tm_mon = 8;
+ soon.tm_year = 69;
+ expected_result = -9181035;
+ result = timegm(&soon);
+ // On my host, this returned -9181035, verify this.
+ printf("epoch: %ld\n", result);
+ assert(result == expected_result);
+
+ return 0;
+}