Date & Time - pkoper/gtm-posix GitHub Wiki

time

$$time^posix() simply returns time(2) result. It does not set the errno value.

GTM>w $$time^posix()
1342962085
GTM>zwr
GTM>

mktime

$$mktime^posix(.n) takes the date specification in n array and returns mktime(3) result. It does not set the errno.

GTM>d localtime^posix(.n) zwr
errno=0
n("hour")=14
n("isdst")=1
n("mday")=22
n("min")=58
n("mon")=6
n("sec")=37
n("wday")=0
n("yday")=203
n("year")=112
GTM>k errno
GTM>w $$mktime^posix(.n)
1342961917
GTM>zwr
n("hour")=14
n("isdst")=1
n("mday")=22
n("min")=58
n("mon")=6
n("sec")=37
n("wday")=0
n("yday")=203
n("year")=112
GTM>

localtime

localtime^posix(.n,.t) takes an optional time in t and returns localtime(3) result by n reference.

GTM>d localtime^posix(.n) zwr
errno=0
n("hour")=15
n("isdst")=1
n("mday")=22
n("min")=2
n("mon")=6
n("sec")=14
n("wday")=0
n("yday")=203
n("year")=112
GTM>d localtime^posix(.n,900061917) zwr
errno=0
n("hour")=11
n("isdst")=1
n("mday")=10
n("min")=11
n("mon")=6
n("sec")=57
n("wday")=5
n("yday")=190
n("year")=98
GTM>

gmtime

gmtime^posix(.n,.t) is exactly the same as localtime^posix(.n,.t) but calls gmtime(3).

GTM>d gmtime^posix(.n) zwr
errno=0
n("hour")=13
n("isdst")=0
n("mday")=22
n("min")=10
n("mon")=6
n("sec")=3
n("wday")=0
n("yday")=203
n("year")=112
GTM>d gmtime^posix(.n,900061917) zwr
errno=0
n("hour")=9
n("isdst")=0
n("mday")=10
n("min")=11
n("mon")=6
n("sec")=57
n("wday")=5
n("yday")=190
n("year")=98
GTM>

clktime

clktime^posix(.clkid,.sec,.nsec) takes a stringified case insensitive clkid which is one of: "REALTIME", "MONOTONIC", "MONOTONIC_RAW", "PROCESS_CPUTIME_ID" or "THREAD_CPUTIME_ID" and calls clock_gettime(2).

Returns timespec.tv_sec and timespec.tv_nsec by reference in sec and nsec.

GTM>d clktime^posix("MONOTONIC",.s,.ns) zwr
errno=0
ns=940170087
s=127998
GTM>

clkres

clkres^posix(.clkid,.sec,.nsec) is same as clktime^posix(.clkid,.sec,.nsec) but for clock_getres(2).

GTM>d clktime^posix("MONOTONIC",.s,.ns) zwr
errno=0
ns=220169736
s=128318
GTM>

strftime

$$strftime^posix(.fmt,.n) takes the format in fmt and date specification in n array and returns strftime(3) result.

GTM>d localtime^posix(.n) zwr
errno=0
n("hour")=15
n("isdst")=1
n("mday")=22
n("min")=18
n("mon")=6
n("sec")=39
n("wday")=0
n("yday")=203
n("year")=112
GTM>k errno
GTM>w $$strftime^posix("%T %F",.n)
15:18:39 2012-07-22
GTM>zwr
errno=0
n("hour")=15
n("isdst")=1
n("mday")=22
n("min")=18
n("mon")=6
n("sec")=39
n("wday")=0
n("yday")=203
n("year")=112
GTM>