]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/calendar/format/format.factor
factor: trim using lists
[factor.git] / basis / calendar / format / format.factor
index 48a77d196214dd9bbd7ee5a06efeb384efdce555..456e6ea3930c058005b8544c279bb10510fb15ca 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008, 2010 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays calendar calendar.english combinators
+USING: accessors calendar calendar.english combinators
 formatting grouping io io.streams.string kernel make math
-math.order math.parser math.parser.private math.ranges present
+math.order math.parser math.parser.private ranges present
 quotations sequences splitting strings words ;
 IN: calendar.format
 
@@ -73,11 +73,11 @@ M: timestamp day.
     [ number>string ] [ month-name ] bi* swap " " glue 20 center. ;
 
 : days-header. ( -- )
-    day-abbreviations2 " " join print ;
+    day-abbreviations2 join-words print ;
 
 : days. ( year month -- )
     [ 1 (day-of-week) dup [ "   " write ] times ]
-    [ (days-in-month) ] 2bi [1,b] [
+    [ (days-in-month) ] 2bi [1..b] [
         [ day. ] [ + 7 mod zero? [ nl ] [ bl ] if ] bi
     ] with each nl ;
 
@@ -90,11 +90,11 @@ PRIVATE>
 GENERIC: year. ( obj -- )
 
 M: integer year.
-    dup number>string 64 center. nl 12 [1,b] [
+    dup number>string 64 center. nl 12 [1..b] [
         [
             [ month-name 20 center. ]
             [ days-header. days. nl nl ] bi
-        ] with-string-writer string-lines
+        ] with-string-writer split-lines
     ] with map 3 <groups>
     [ first3 [ "%-20s  %-20s  %-20s\n" printf ] 3each ] each ;
 
@@ -110,7 +110,7 @@ M: timestamp year. year>> year. ;
     [ hh:mm:ss ] with-string-writer ;
 
 : timestamp>ymdhms ( timestamp -- str )
-    [ clone >gmt YYYY-MM-DD " " hh:mm:ss ] with-string-writer ;
+    [ >gmt { YYYY-MM-DD " " hh:mm:ss } formatted ] with-string-writer ;
 
 : write-gmt-offset-hhmm ( gmt-offset -- )
     [ hour>> dup 0 < "-" "+" ? write abs write-00 ] [ mm ] bi ;
@@ -185,10 +185,10 @@ ALIAS: timestamp>rfc822 timestamp>rfc2822
     ] with-string-writer ;
 
 : timestamp>http-string ( timestamp -- str )
-    clone >gmt timestamp>rfc2822 ;
+    >gmt timestamp>rfc2822 ;
 
 : timestamp>cookie-string ( timestamp -- str )
-    clone >gmt timestamp>rfc1036 ;
+    >gmt timestamp>rfc1036 ;
 
 : write-timestamp ( timestamp -- )
     { DAY ", " D " " MONTH " " YYYY " " hh:mm:ss } formatted ;
@@ -238,7 +238,7 @@ M: integer elapsed-time
             [ first [ /mod ] [ dup ] if* ] [ second ] bi swap
             dup 0 > [ number>string prepend , ] [ 2drop ] if
         ] each drop
-    ] { } make [ "0s" ] [ reverse " " join ] if-empty ;
+    ] { } make [ "0s" ] [ reverse join-words ] if-empty ;
 
 M: real elapsed-time
     >integer elapsed-time ;