]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar.format: Add a word to output times in the format that git uses. Rename a...
authorDoug Coleman <doug.coleman@gmail.com>
Sun, 31 May 2015 22:08:51 +0000 (15:08 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Sun, 31 May 2015 22:08:51 +0000 (15:08 -0700)
basis/calendar/format/format.factor

index df8312d56ffd247f9949469447d728ca1c6d5ac9..a7f2c589a03f8e81e1aba13d629d311d56576afe 100644 (file)
@@ -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