diff --git a/basis/calendar/format/format.factor b/basis/calendar/format/format.factor index df8312d56f..a7f2c589a0 100644 --- a/basis/calendar/format/format.factor +++ b/basis/calendar/format/format.factor @@ -93,14 +93,21 @@ M: timestamp year. ( timestamp -- ) : timestamp>string ( timestamp -- str ) [ (timestamp>string) ] with-string-writer ; -: (write-gmt-offset) ( duration -- ) +: write-hhmm ( duration -- ) [ hh ] [ mm ] bi ; : write-gmt-offset ( gmt-offset -- ) dup instant <=> { { +eq+ [ drop "GMT" write ] } - { +lt+ [ "-" write before (write-gmt-offset) ] } - { +gt+ [ "+" write (write-gmt-offset) ] } + { +lt+ [ "-" write before write-hhmm ] } + { +gt+ [ "+" write write-hhmm ] } + } case ; + +: write-gmt-offset-number ( gmt-offset -- ) + dup instant <=> { + { +eq+ [ drop "+0000" write ] } + { +lt+ [ "-" write before write-hhmm ] } + { +gt+ [ "+" write write-hhmm ] } } case ; : timestamp>rfc822 ( timestamp -- str ) @@ -112,6 +119,12 @@ M: timestamp year. ( timestamp -- ) bi ] with-string-writer ; +: timestamp>git-time ( timestamp -- str ) + [ + [ { DAY " " MONTH " " D " " hh ":" mm ":" ss " " YYYY " " } formatted ] + [ gmt-offset>> write-gmt-offset-number ] bi + ] with-string-writer ; + : timestamp>http-string ( timestamp -- str ) #! http timestamp format #! Example: Tue, 15 Nov 1994 08:12:31 GMT