HOOK: gmt-offset os ( -- hours minutes seconds )
+HOOK: gmt os ( -- timestamp )
+
TUPLE: duration
{ year real }
{ month real }
: timestamp>micros ( timestamp -- n )
unix-1970 (time-) 1000000 * >integer ;
-: gmt ( -- timestamp )
- #! GMT time, right now
- unix-1970 system-micros microseconds time+ ;
-
: now ( -- timestamp ) gmt >local-time ;
: hence ( duration -- timestamp ) now swap time+ ;
: ago ( duration -- timestamp ) now swap time- ;
accessors classes.struct calendar.format math.functions ;
IN: calendar.windows
-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 ;
-
: timestamp>SYSTEMTIME ( timestamp -- SYSTEMTIME )
{
[ year>> ]
[ wDay>> ]
[ wHour>> ]
[ wMinute>> ]
- [ [ wSecond>> ] [ wMilliseconds>> 1000 /f ] bi + ]
- } cleave gmt-offset-duration <timestamp> ;
+ [ [ 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 ;
{ "set-string-nth-fast" "strings.private" "primitive_set_string_nth_fast" (( ch n string -- )) }
{ "(exit)" "system" "primitive_exit" (( n -- * )) }
{ "nano-count" "system" "primitive_nano_count" (( -- ns )) }
- { "system-micros" "system" "primitive_system_micros" (( -- us )) }
{ "(sleep)" "threads.private" "primitive_sleep" (( nanos -- )) }
{ "callstack-for" "threads.private" "primitive_callstack_for" (( context -- array )) }
{ "context-object-for" "threads.private" "primitive_context_object_for" (( n context -- obj )) }
windows.kernel32 kernel classes.struct calendar ;
IN: time.windows
-: windows-system-time ( -- SYSTEMTIME )
- SYSTEMTIME <struct> [ GetSystemTime ] keep ;
-
M: windows set-time
>gmt
timestamp>SYSTEMTIME SetSystemTime win32-error=0/f ;
static void *null_dll;
-u64 system_micros()
-{
- struct timeval t;
- gettimeofday(&t,NULL);
- return (u64)t.tv_sec * 1000000 + t.tv_usec;
-}
-
void sleep_nanos(u64 nsec)
{
timespec ts;
void signal_handler(int signal, siginfo_t* siginfo, void* uap);
void dump_stack_signal(int signal, siginfo_t* siginfo, void* uap);
-u64 system_micros();
u64 nano_count();
void sleep_nanos(u64 nsec);
void open_console();
namespace factor
{
-u64 system_micros()
-{
- SYSTEMTIME st;
- FILETIME ft;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- return (((s64)ft.dwLowDateTime
- | (s64)ft.dwHighDateTime<<32) - EPOCH_OFFSET) / 10;
-}
-
char *strerror(int err)
{
/* strerror() is not defined on WinCE */
#define snprintf _snprintf
#define snwprintf _snwprintf
-u64 system_micros();
void c_to_factor_toplevel(cell quot);
void open_console();
return (void *)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, args, 0, 0);
}
-u64 system_micros()
-{
- FILETIME t;
- GetSystemTimeAsFileTime(&t);
- return (((u64)t.dwLowDateTime | (u64)t.dwHighDateTime<<32)
- - EPOCH_OFFSET) / 10;
-}
-
u64 nano_count()
{
static double scale_factor;
inline static void early_init() {}
-u64 system_micros();
u64 nano_count();
void sleep_nanos(u64 nsec);
long getpagesize();
_(special_object) \
_(string) \
_(strip_stack_traces) \
- _(system_micros) \
_(tuple) \
_(tuple_boa) \
_(unimplemented) \
exit((int)to_fixnum(ctx->pop()));
}
-void factor_vm::primitive_system_micros()
-{
- ctx->push(from_unsigned_8(system_micros()));
-}
-
void factor_vm::primitive_nano_count()
{
u64 nanos = nano_count();
// run
void primitive_exit();
- void primitive_system_micros();
void primitive_nano_count();
void primitive_sleep();
void primitive_set_slot();