gmt-offset now calls an alien function to deal with daylight savings and timezone

release
erg 2006-09-03 21:38:13 +00:00
parent b2feff018a
commit 9e67f14fd5
5 changed files with 106 additions and 18 deletions

View File

@ -1,16 +1,10 @@
IN: calendar
USING: arrays errors generic hashtables io kernel math
namespaces sequences strings prettyprint inspector ;
IN: calendar
TUPLE: timestamp year month day hour minute second gmt-offset ;
TUPLE: dt year month day hour minute second ;
SYMBOL: gmt-offset
-6 gmt-offset set-global ! central time
LIBRARY: libc
FUNCTION: time_t time ( time_t* t ) ;
: month-names
{
"Not a month" "January" "February" "March" "April" "May" "June"
@ -198,7 +192,7 @@ M: number +second ( timestamp n -- timestamp )
over set-timestamp-gmt-offset ;
: >local-time ( timestamp -- timestamp )
gmt-offset get convert-timezone ;
gmt-offset convert-timezone ;
: >gmt ( timestamp -- timestamp )
0 convert-timezone ;
@ -283,3 +277,4 @@ M: number +second ( timestamp n -- timestamp )
dup timestamp-minute unparse 2 CHAR: 0 pad-left write ":" write
timestamp-second >fixnum unparse 2 CHAR: 0 pad-left write " GMT" write
] string-out ;

View File

@ -1,13 +1,15 @@
USING: kernel modules sequences ;
"calendar"
USING: kernel modules namespaces sequences ;
{
{ [ win32? ] [ { "os-win32.factor" } ] }
{ [ t ] [ { "os-unix.factor" } ] }
} cond
{
"calendar.factor"
} append
"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

@ -0,0 +1,15 @@
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

@ -0,0 +1,48 @@
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

@ -1,4 +1,32 @@
IN: calendar
USING: alien ;
USING: alien arrays compiler errors kernel math ;
TYPEDEF: uint time_t
BEGIN-STRUCT: t
FIELD: long tv_sec
FIELD: long tv_usec
END-STRUCT
FUNCTION: time_t time ( time_t* t ) ;
FUNCTION: tm* localtime ( time_t* clock ) ;
: get-time
f time <uint> localtime ;
! 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 ;