factor/basis/calendar/windows/windows.factor

42 lines
1.2 KiB
Factor
Raw Normal View History

USING: calendar namespaces alien.c-types system
2009-08-29 14:39:48 -04:00
windows.kernel32 kernel math combinators windows.errors
2010-06-16 18:42:15 -04:00
accessors classes.struct calendar.format math.functions ;
2007-09-20 18:09:08 -04:00
IN: calendar.windows
2010-06-16 18:42:15 -04:00
: timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
{
[ year>> ]
[ month>> ]
[ day-of-week ]
[ day>> ]
[ hour>> ]
[ minute>> ]
[
second>> dup floor
[ nip >integer ]
[ - 1000 * >integer ] 2bi
]
} cleave \ SYSTEMTIME <struct-boa> ;
: SYSTEMTIME>timestamp ( SYSTEMTIME -- timestamp )
{
[ wYear>> ]
[ wMonth>> ]
[ wDay>> ]
[ wHour>> ]
[ wMinute>> ]
[ [ wSecond>> ] [ wMilliseconds>> 1000 / ] bi + ]
} cleave instant <timestamp> ;
M: windows gmt-offset ( -- hours minutes seconds )
TIME_ZONE_INFORMATION <struct>
dup GetTimeZoneInformation {
{ TIME_ZONE_ID_INVALID [ win32-error-string throw ] }
{ TIME_ZONE_ID_UNKNOWN [ Bias>> ] }
{ TIME_ZONE_ID_STANDARD [ Bias>> ] }
{ TIME_ZONE_ID_DAYLIGHT [ [ Bias>> ] [ DaylightBias>> ] bi + ] }
} case neg 60 /mod 0 ;
M: windows gmt
SYSTEMTIME <struct> [ GetSystemTime ] keep SYSTEMTIME>timestamp ;