refactor conversions
parent
4dedabeb44
commit
b3fcd179a0
|
@ -36,8 +36,12 @@ M: timestamp year. ( timestamp -- )
|
||||||
|
|
||||||
: pad-00 number>string 2 CHAR: 0 pad-left ;
|
: pad-00 number>string 2 CHAR: 0 pad-left ;
|
||||||
|
|
||||||
|
: pad-0000 number>string 4 CHAR: 0 pad-left ;
|
||||||
|
|
||||||
: write-00 pad-00 write ;
|
: write-00 pad-00 write ;
|
||||||
|
|
||||||
|
: write-0000 pad-0000 write ;
|
||||||
|
|
||||||
: (timestamp>string) ( timestamp -- )
|
: (timestamp>string) ( timestamp -- )
|
||||||
dup day-of-week day-abbreviations3 nth write ", " write
|
dup day-of-week day-abbreviations3 nth write ", " write
|
||||||
dup day>> number>string write bl
|
dup day>> number>string write bl
|
||||||
|
@ -107,18 +111,16 @@ M: timestamp year. ( timestamp -- )
|
||||||
60 / + *
|
60 / + *
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
|
: read-ymd ( -- y m d )
|
||||||
|
read-0000 "-" expect read-00 "-" expect read-00 ;
|
||||||
|
|
||||||
|
: read-hms ( -- h m s )
|
||||||
|
read-00 ":" expect read-00 ":" expect read-00 ;
|
||||||
|
|
||||||
: (rfc3339>timestamp) ( -- timestamp )
|
: (rfc3339>timestamp) ( -- timestamp )
|
||||||
read-0000 ! year
|
read-ymd
|
||||||
"-" expect
|
|
||||||
read-00 ! month
|
|
||||||
"-" expect
|
|
||||||
read-00 ! day
|
|
||||||
"Tt" expect
|
"Tt" expect
|
||||||
read-00 ! hour
|
read-hms
|
||||||
":" expect
|
|
||||||
read-00 ! minute
|
|
||||||
":" expect
|
|
||||||
read-00 ! second
|
|
||||||
read-rfc3339-gmt-offset ! timezone
|
read-rfc3339-gmt-offset ! timezone
|
||||||
<timestamp> ;
|
<timestamp> ;
|
||||||
|
|
||||||
|
@ -126,49 +128,25 @@ M: timestamp year. ( timestamp -- )
|
||||||
[ (rfc3339>timestamp) ] with-string-reader ;
|
[ (rfc3339>timestamp) ] with-string-reader ;
|
||||||
|
|
||||||
: (ymdhms>timestamp) ( -- timestamp )
|
: (ymdhms>timestamp) ( -- timestamp )
|
||||||
read-0000 ! year
|
read-ymd " " expect read-hms 0 <timestamp> ;
|
||||||
"-" expect
|
|
||||||
read-00 ! month
|
|
||||||
"-" expect
|
|
||||||
read-00 ! day
|
|
||||||
" " expect
|
|
||||||
read-00 ! hour
|
|
||||||
":" expect
|
|
||||||
read-00 ! minute
|
|
||||||
":" expect
|
|
||||||
read-00 ! second
|
|
||||||
0 ! timezone
|
|
||||||
<timestamp> ;
|
|
||||||
|
|
||||||
: ymdhms>timestamp ( str -- timestamp )
|
: ymdhms>timestamp ( str -- timestamp )
|
||||||
[ (ymdhms>timestamp) ] with-string-reader ;
|
[ (ymdhms>timestamp) ] with-string-reader ;
|
||||||
|
|
||||||
: (hms>timestamp) ( -- timestamp )
|
: (hms>timestamp) ( -- timestamp )
|
||||||
f f f
|
f f f read-hms f <timestamp> ;
|
||||||
read-00 ! hour
|
|
||||||
":" expect
|
|
||||||
read-00 ! minute
|
|
||||||
":" expect
|
|
||||||
read-00 ! second
|
|
||||||
f <timestamp> ;
|
|
||||||
|
|
||||||
: hms>timestamp ( str -- timestamp )
|
: hms>timestamp ( str -- timestamp )
|
||||||
[ (hms>timestamp) ] with-string-reader ;
|
[ (hms>timestamp) ] with-string-reader ;
|
||||||
|
|
||||||
: (ymd>timestamp) ( -- timestamp )
|
: (ymd>timestamp) ( -- timestamp )
|
||||||
read-0000 ! year
|
read-ymd f f f f <timestamp> ;
|
||||||
"-" expect
|
|
||||||
read-00 ! month
|
|
||||||
"-" expect
|
|
||||||
read-00 ! day
|
|
||||||
f f f f <timestamp> ;
|
|
||||||
|
|
||||||
: ymd>timestamp ( str -- timestamp )
|
: ymd>timestamp ( str -- timestamp )
|
||||||
[ (ymd>timestamp) ] with-string-reader ;
|
[ (ymd>timestamp) ] with-string-reader ;
|
||||||
|
|
||||||
|
|
||||||
: (timestamp>ymd) ( timestamp -- )
|
: (timestamp>ymd) ( timestamp -- )
|
||||||
dup timestamp-year number>string write
|
dup timestamp-year write-0000
|
||||||
"-" write
|
"-" write
|
||||||
dup timestamp-month write-00
|
dup timestamp-month write-00
|
||||||
"-" write
|
"-" write
|
||||||
|
@ -188,6 +166,7 @@ M: timestamp year. ( timestamp -- )
|
||||||
[ (timestamp>hms) ] with-string-writer ;
|
[ (timestamp>hms) ] with-string-writer ;
|
||||||
|
|
||||||
: timestamp>ymdhms ( timestamp -- str )
|
: timestamp>ymdhms ( timestamp -- str )
|
||||||
|
>gmt
|
||||||
[
|
[
|
||||||
dup (timestamp>ymd)
|
dup (timestamp>ymd)
|
||||||
" " write
|
" " write
|
||||||
|
|
Loading…
Reference in New Issue