diff --git a/extra/calendar/format/format.factor b/extra/calendar/format/format.factor index c1bd6427a7..89e09e0d0c 100755 --- a/extra/calendar/format/format.factor +++ b/extra/calendar/format/format.factor @@ -36,8 +36,12 @@ M: timestamp year. ( timestamp -- ) : pad-00 number>string 2 CHAR: 0 pad-left ; +: pad-0000 number>string 4 CHAR: 0 pad-left ; + : write-00 pad-00 write ; +: write-0000 pad-0000 write ; + : (timestamp>string) ( timestamp -- ) dup day-of-week day-abbreviations3 nth write ", " write dup day>> number>string write bl @@ -107,18 +111,16 @@ M: timestamp year. ( timestamp -- ) 60 / + * ] 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 ) - read-0000 ! year - "-" expect - read-00 ! month - "-" expect - read-00 ! day + read-ymd "Tt" expect - read-00 ! hour - ":" expect - read-00 ! minute - ":" expect - read-00 ! second + read-hms read-rfc3339-gmt-offset ! timezone ; @@ -126,49 +128,25 @@ M: timestamp year. ( timestamp -- ) [ (rfc3339>timestamp) ] with-string-reader ; : (ymdhms>timestamp) ( -- timestamp ) - read-0000 ! year - "-" expect - read-00 ! month - "-" expect - read-00 ! day - " " expect - read-00 ! hour - ":" expect - read-00 ! minute - ":" expect - read-00 ! second - 0 ! timezone - ; + read-ymd " " expect read-hms 0 ; : ymdhms>timestamp ( str -- timestamp ) [ (ymdhms>timestamp) ] with-string-reader ; : (hms>timestamp) ( -- timestamp ) - f f f - read-00 ! hour - ":" expect - read-00 ! minute - ":" expect - read-00 ! second - f ; + f f f read-hms f ; : hms>timestamp ( str -- timestamp ) [ (hms>timestamp) ] with-string-reader ; : (ymd>timestamp) ( -- timestamp ) - read-0000 ! year - "-" expect - read-00 ! month - "-" expect - read-00 ! day - f f f f ; + read-ymd f f f f ; : ymd>timestamp ( str -- timestamp ) [ (ymd>timestamp) ] with-string-reader ; - : (timestamp>ymd) ( timestamp -- ) - dup timestamp-year number>string write + dup timestamp-year write-0000 "-" write dup timestamp-month write-00 "-" write @@ -188,6 +166,7 @@ M: timestamp year. ( timestamp -- ) [ (timestamp>hms) ] with-string-writer ; : timestamp>ymdhms ( timestamp -- str ) + >gmt [ dup (timestamp>ymd) " " write