calendar simplifications

release
erg 2006-09-03 22:01:12 +00:00
parent 9e67f14fd5
commit 733ab3c5ac
5 changed files with 26 additions and 119 deletions

View File

@ -3,14 +3,11 @@ USING: kernel modules namespaces sequences ;
"calendar"
[
{
{ [ unix? macosx? not and ] [ "os-unix.factor" , "os-linux.factor" , ] }
{ [ macosx? ] [ "os-unix.factor" , "os-macosx.factor" , ] }
{ [ unix? ] [ "os-unix.factor" , ] }
{ [ win32? ] [ "os-win32.factor" , ] }
} cond
"calendar.factor" ,
] { } make
{ "test/calendar.factor" }
provide

View File

@ -1,15 +0,0 @@
IN: calendar
BEGIN-STRUCT: tm
FIELD: int sec ! Seconds: 0-59 (K&R says 0-61?)
FIELD: int min ! Minutes: 0-59
FIELD: int hour ! Hours since midnight: 0-23
FIELD: int mday ! Day of the month: 1-31
FIELD: int mon ! Months *since* january: 0-11
FIELD: int year ! Years since 1900
FIELD: int wday ! Days since Sunday (0-6)
FIELD: int yday ! Days since Jan. 1: 0-365
FIELD: int isdst ! +1 Daylight Savings Time, 0 No DST,
END-STRUCT

View File

@ -1,48 +0,0 @@
IN: calendar
USING: alien arrays compiler errors kernel math ;
TYPEDEF: uint time_t
BEGIN-STRUCT: tm
FIELD: int sec ! Seconds: 0-59 (K&R says 0-61?)
FIELD: int min ! Minutes: 0-59
FIELD: int hour ! Hours since midnight: 0-23
FIELD: int mday ! Day of the month: 1-31
FIELD: int mon ! Months *since* january: 0-11
FIELD: int year ! Years since 1900
FIELD: int wday ! Days since Sunday (0-6)
FIELD: int yday ! Days since Jan. 1: 0-365
FIELD: int isdst ! +1 Daylight Savings Time, 0 No DST,
FIELD: long gmtoff
FIELD: char* zone
END-STRUCT
FUNCTION: time_t time ( time_t* t ) ;
FUNCTION: tm* localtime ( time_t* clock ) ;
FUNCTION: size_t strftime ( char* buf, size_t maxsize, char* format, tm* timeptr ) ;
BEGIN-STRUCT: t
FIELD: long tv_sec
FIELD: long tv_usec
END-STRUCT
BEGIN-STRUCT: tz
FIELD: int tz_minuteswest
FIELD: int tz_dsttime
END-STRUCT
FUNCTION: int gettimeofday ( t* timeval, tz* timezone ) ;
: machine-gmt-offset
"t" <c-object> "tz" <c-object> 2dup gettimeofday
zero? [ nip tz-tz_minuteswest 60 / neg ] [ 2drop 0 ] if ;
\ gettimeofday compile
: timezone-name
get-time tm-zone ;
: gmt-offset
get-time tm-gmtoff 3600 / ;

View File

@ -2,31 +2,32 @@ IN: calendar
USING: alien arrays compiler errors kernel math ;
TYPEDEF: uint time_t
BEGIN-STRUCT: t
FIELD: long tv_sec
FIELD: long tv_usec
BEGIN-STRUCT: tm
FIELD: int sec ! Seconds: 0-59 (K&R says 0-61?)
FIELD: int min ! Minutes: 0-59
FIELD: int hour ! Hours since midnight: 0-23
FIELD: int mday ! Day of the month: 1-31
FIELD: int mon ! Months *since* january: 0-11
FIELD: int year ! Years since 1900
FIELD: int wday ! Days since Sunday (0-6)
FIELD: int yday ! Days since Jan. 1: 0-365
FIELD: int isdst ! +1 Daylight Savings Time, 0 No DST,
FIELD: long gmtoff
FIELD: char* zone
END-STRUCT
FUNCTION: time_t time ( time_t* t ) ;
FUNCTION: tm* localtime ( time_t* clock ) ;
: get-time
f time <uint> localtime ;
BEGIN-STRUCT: t
FIELD: long tv_sec
FIELD: long tv_usec
END-STRUCT
: timezone-name
get-time tm-zone ;
! BEGIN-STRUCT: tz
! FIELD: int tz_minuteswest
! FIELD: int tz_dsttime
! END-STRUCT
! FUNCTION: int gettimeofday ( t* timeval, tz* timezone ) ;
! : machine-gmt-offset
! "t" <c-object> "tz" <c-object> 2dup gettimeofday
! zero? [ nip tz-tz_minuteswest 60 / neg ] [ 2drop 0 ] if ;
: gmt-offset
get-time tm-gmtoff 3600 / ;

View File

@ -1,36 +1,8 @@
IN: calendar
USING: alien kernel math win32-api ;
: tz "_TIME_ZONE_INFORMATION" <c-object> dup GetTimeZoneInformation
TIME_ZONE_ID_INVALID = [
win32-error
] when alien-address 4 + <alien> alien>u16-string ;
! TYPEDEF: longlong time_t
! TYPEDEF: longlong __time64_t
! TYPEDEF: int errno_t
!
! BEGIN-STRUCT: tm
! FIELD: int tm_sec; ! Seconds: 0-59 (K&R says 0-61?)
! FIELD: int tm_min; ! Minutes: 0-59
! FIELD: int tm_hour; ! Hours since midnight: 0-23
! FIELD: int tm_mday; ! Day of the month: 1-31
! FIELD: int tm_mon; ! Months *since* january: 0-11
! FIELD: int tm_year; ! Years since 1900
! FIELD: int tm_wday; ! Days since Sunday (0-6)
! FIELD: int tm_yday; ! Days since Jan. 1: 0-365
! FIELD: int tm_isdst ! +1 Daylight Savings Time, 0 No DST,
! END-STRUCT
!
! FUNCTION: errno_t _localtime64_s ( tm* _tm, __time64_t *time ) ;
: gmt-offset
"TIME_ZONE_INFORMATION" <c-object> dup GetTimeZoneInformation drop
dup TIME_ZONE_INFORMATION-Bias swap TIME_ZONE_INFORMATION-DaylightBias +
60 /f neg ;