]> gitweb.factorcode.org Git - factor.git/commitdiff
calendar.format: Add some utility words for implementing top.
authorDoug Coleman <doug.coleman@gmail.com>
Mon, 25 Feb 2013 02:29:00 +0000 (18:29 -0800)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 25 Feb 2013 02:30:18 +0000 (18:30 -0800)
basis/calendar/format/format.factor

index 2d856325856ff7b5c0b9f6f7d28dadb0ab3787fd..49bc1d86f0dfc10c0d5b53b52c5c0d7de204528d 100644 (file)
@@ -281,6 +281,12 @@ TYPED: timestamp>ymd ( timestamp: timestamp -- str )
 TYPED: timestamp>hms ( timestamp: timestamp -- str )\r
     [ (timestamp>hms) ] with-string-writer ;\r
 \r
+: (timestamp>hm) ( timestamp -- )\r
+    { hh ":" mm } formatted ;\r
+\r
+TYPED: timestamp>hm ( timestamp: timestamp -- str )\r
+    [ (timestamp>hm) ] with-string-writer ;\r
+\r
 TYPED: timestamp>ymdhms ( timestamp: timestamp -- str )\r
     [\r
         >gmt\r
@@ -299,3 +305,24 @@ TYPED: timestamp>ymdhms ( timestamp: timestamp -- str )
     ] with-string-writer ;\r
 \r
 M: timestamp present timestamp>string ;\r
+\r
+TYPED: duration>hm ( duration: duration -- string )\r
+    [ duration>hours >integer 24 mod pad-00 ]\r
+    [ duration>minutes >integer 60 mod pad-00 ] bi ":" glue ;\r
+\r
+TYPED: duration>human-readable ( duration: duration -- string )\r
+    [\r
+        [\r
+            duration>years >integer\r
+            [\r
+                [ number>string write ]\r
+                [ 1 > " years, " " year, " ? write ] bi\r
+            ] unless-zero\r
+        ] [\r
+            duration>days >integer 365 mod\r
+            [\r
+                [ number>string write ]\r
+                [ 1 > " days, " " day, " ? write ] bi\r
+            ] unless-zero\r
+        ] [ duration>hm write ] tri\r
+    ] with-string-writer ;\r