diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-03-22 17:22:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 17:22:26 +0100 |
commit | 479ab1262e80bdf61d8e3b4b3c306aa4821f6ae6 (patch) | |
tree | 28b54b52beaf4c1e32cd8e79db97cdd045acc5db /tests/custom/03_stdlib/54_timegm | |
parent | fbe2722941f10bfb0883af216959445a5446cbd3 (diff) | |
parent | 171402fd6fc2bd27dd45e2dbf258734c53987508 (diff) |
Merge pull request #60 from jow-/time-functions
lib: add date and time related functions
Diffstat (limited to 'tests/custom/03_stdlib/54_timegm')
-rw-r--r-- | tests/custom/03_stdlib/54_timegm | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/custom/03_stdlib/54_timegm b/tests/custom/03_stdlib/54_timegm new file mode 100644 index 0000000..9c0b59a --- /dev/null +++ b/tests/custom/03_stdlib/54_timegm @@ -0,0 +1,54 @@ +The `timegm()` function performs the inverse operation of `gmtime()` +by taking a broken-down date and time dictionary and transforming it into +an epoch value, assuming UTC time. + +-- Testcase -- +{% + // check expected epoch + let d1 = { + "sec": 42, + "min": 51, + "hour": 13, + "mday": 22, + "mon": 3, + "year": 2022, + "wday": 2, + "yday": 81, + "isdst": 0 + }; + + // check that out of range values are normalized + let d2 = { + "sec": 33, + "min": 22, + "hour": 11, + "mday": 40, + "mon": 10, + "year": 2022, + "wday": 2, + "yday": 81, + "isdst": 0 + }; + + // check that everything except mday, mon, year is optional + let d3 = { + "mday": 1, + "mon": 1, + "year": 2000 + }; + + printf("%.J\n", [ + timegm(d1), + timegm(d2), + timegm(d3) + ]); +%} +-- End -- + +-- Expect stdout -- +[ + 1647957102, + 1667992953, + 946684800 +] +-- End -- |