49 lines
1.2 KiB
Forth
49 lines
1.2 KiB
Forth
\ Linux timestamp support
|
|
\
|
|
\ Works for Unix Epoch 32-bit timestamps after March 1972.
|
|
|
|
: ostime \ (-- s)
|
|
zero 13 oscall1 ;
|
|
|
|
: tstamp_conv \ (lintime -- d s)
|
|
68256000 - \ start on Mar 1, 1972,
|
|
TIMEZONE @ +
|
|
86400 UM/MOD swap \ days s
|
|
;
|
|
|
|
: time_conv \ (s -- s m h)
|
|
60 UM/MOD \ s m
|
|
60 UM/MOD \ s m h
|
|
;
|
|
|
|
: date_conv \ (days--yr,mo,day) days are form March 1, 1972
|
|
1461 UM/MOD 4 * push \ push years (from March 1972)
|
|
365 UM/MOD pop + 1972 + swap \ (--yrs,days) add years within this quad
|
|
dup 0 = if ( drop 3 29 ; ) thanx
|
|
31 - neg? if ( 32 + 3 swap ; ) thanx
|
|
30 - neg? if ( 31 + 4 swap ; ) thanx
|
|
31 - neg? if ( 32 + 5 swap ; ) thanx
|
|
30 - neg? if ( 31 + 6 swap ; ) thanx
|
|
31 - neg? if ( 32 + 7 swap ; ) thanx
|
|
31 - neg? if ( 32 + 8 swap ; ) thanx
|
|
30 - neg? if ( 31 + 9 swap ; ) thanx
|
|
31 - neg? if ( 32 + 10 swap ; ) thanx
|
|
30 - neg? if ( 31 + 11 swap ; ) thanx
|
|
31 - neg? if ( 32 + 12 swap ; ) thanx
|
|
swap 1+ swap
|
|
31 - neg? if ( 32 + 1 swap ; ) thanx
|
|
2 swap ;
|
|
|
|
: time. \ (s m h --)
|
|
2 u.r $3A emit 2 u.r $3A emit 2 u.r sp ;
|
|
|
|
: date. \ (y m d--)
|
|
swap rot
|
|
. $2D emit 2 u.r $2D emit 2 u.r sp ;
|
|
|
|
: now ostime tstamp_conv time_conv time. date_conv date. ;
|
|
|
|
|
|
sync
|
|
|