Today, we released an update to the GT.M POSIX plugin that includes a binding to the POSIX mktime() function. This makes it easy to convert between UNIX time, local time and $horolog, as well as to determine whether Daylight Savings Time is in effect, as demonstrated by the small program below (apologies for line wraps; please write to me off-list if you want me to mail you the program):
kbhaskar@bhaskark:~$ mumps -run gtm7969demo
$horolog=63250,61861 which is 2014:03:04:17:11:01:TUE
UNIX time from $horolog=1393971061
Day of the week is Tuesday
Day of the year (0=January 1) is 62
Daylight Savings Time is not in effect
$horolog from UNIX time=63250,61861
kbhaskar@bhaskark:~$
You will find the latest POSIX plugin in the folder at
http://sourceforge.net/projects/fis-gtm/files/Plugins/posix/ and the tarball contains a readme with documentation as well as instructions for building & installation.
Regards
-- Bhaskar
--
GT.M - Rock solid. Lightning fast. Secure. No compromises.
-------------------------------------------------------------------
gtm7969demo
; demonstrate converting $horologtime to unixtime
set now=$horolog write "$horolog=",now
set tmp=$zdate(now,"YYYY:MM:DD:24:60:SS:DAY") ; translate $horolog into normal time of day
write " which is ",tmp,!
; the $piece()s of tmp in call to mktime() are broken-down time as defined by POSIX - notice needed offsets
set isdst=-1
set retval=$>mposix.mktime($piece(tmp,":",1)-1900,$piece(tmp,":",2)-1,+$piece(tmp,":",3),+$piece(tmp,":",4),+$piece(tmp,":",5),+$piece(tmp,":",6),.wday,.yday,.isdst,.tvsec,.errno)
write "UNIX time from $horolog=",tvsec,!
write "Day of the week is ",$piece("Sun,Mon,Tues,Wednes,Thurs,Fri,Satur",",",1+wday),"day",!
write "Day of the year (0=January 1) is ",yday,!
write "Daylight Savings Time is ",$select('isdst:"not ",1:""),"in effect",!
; convert the tvsec returned by mktime() into the current time
set retval=$>mposix.localtime(tvsec,.sec,.min,.hour,.mday,.mon,.year,.wday,.yday,.isdst,.errno)
; convert the current time back to $horolog
write "$horolog from UNIX time=",$$FUNC^%DATE(mon+1_"/"_mday_"/"_(1900+year))_","_($$FUNC^%TI($translate($justify(hour,2)_$justify(min,2)," ",0))+sec),!
quit
-------------------------------------------------------------------