From 769af0673a716bbdbb48e0fa818b4e1b42211204 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sun, 31 May 2015 15:08:51 -0700 Subject: [PATCH] calendar.format: Add a word to output times in the format that git uses. Rename a paren word. --- basis/calendar/format/format.factor | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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