]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Dec 2008 18:00:44 +0000 (10:00 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Dec 2008 18:00:44 +0000 (10:00 -0800)
extra/math/binpack/binpack-docs.factor
extra/time/time.factor

index 36a29c7aa1fdfa7f44bc3b4da352ba2303221bc6..d995cab59d5f147ce6ac2868f25bce19f60459e7 100644 (file)
@@ -15,5 +15,5 @@ HELP: binpack*
 
 HELP: binpack!
 { $values { "items" sequence } { "quot" quotation } { "n" "number of bins" } { "bins" "packed bins" } } 
-{ $description "Packs a sequence of items into the specified number of bins, using the quotatino to determine the weight." } ;
+{ $description "Packs a sequence of items into the specified number of bins, using the quotation to determine the weight." } ;
 
index be19fb0919b75c14578a2c4101aab2240ecaee2e..52c01bdd885bf48cc50e85a612b18b8eea360e78 100644 (file)
@@ -1,18 +1,29 @@
 ! Copyright (C) 2008 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: accessors arrays calendar io kernel fry macros math
-math.functions math.parser peg.ebnf sequences strings vectors ;
+USING: accessors arrays calendar combinators io kernel fry 
+macros math math.functions math.parser peg.ebnf sequences 
+strings vectors ;
 
 IN: time
 
+: zero-pad 2 CHAR: 0 pad-left ; inline
+
 : >timestring ( timestamp -- string ) 
-    [ hour>> ] keep [ minute>> ] keep second>> 3array
-    [ number>string 2 CHAR: 0 pad-left ] map ":" join ; inline
+    [ hour>> ] [ minute>> ] [ second>> floor ] tri 3array
+    [ number>string zero-pad ] map ":" join ; inline
 
 : >datestring ( timestamp -- string )
-    [ month>> ] keep [ day>> ] keep year>> 3array
-    [ number>string 2 CHAR: 0 pad-left ] map "/" join ; inline
+    [ month>> ] [ day>> ] [ year>> ] tri 3array
+    [ number>string zero-pad ] map "/" join ; inline
+
+: >datetimestring ( timestamp -- string ) 
+    { [ day-of-week day-abbreviation3 ]
+      [ month>> month-abbreviation ]
+      [ day>> number>string zero-pad ]
+      [ >timestring ]
+      [ year>> number>string ]
+    } cleave 3array [ 2array ] dip append " " join ; inline
 
 : (week-of-year) ( timestamp day -- n )
     [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when
@@ -32,15 +43,15 @@ fmt-a     = "a"                  => [[ [ dup day-of-week day-abbreviation3 ] ]]
 fmt-A     = "A"                  => [[ [ dup day-of-week day-name ] ]] 
 fmt-b     = "b"                  => [[ [ dup month>> month-abbreviation ] ]]
 fmt-B     = "B"                  => [[ [ dup month>> month-name ] ]] 
-fmt-c     = "c"                  => [[ [ "Not yet implemented" throw ] ]]
-fmt-d     = "d"                  => [[ [ dup day>> number>string 2 CHAR: 0 pad-left ] ]] 
-fmt-H     = "H"                  => [[ [ dup hour>> number>string 2 CHAR: 0 pad-left ] ]]
-fmt-I     = "I"                  => [[ [ dup hour>> 12 > [ 12 - ] when number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-c     = "c"                  => [[ [ dup >datetimestring ] ]] 
+fmt-d     = "d"                  => [[ [ dup day>> number>string zero-pad ] ]] 
+fmt-H     = "H"                  => [[ [ dup hour>> number>string zero-pad ] ]]
+fmt-I     = "I"                  => [[ [ dup hour>> dup 12 > [ 12 - ] when number>string zero-pad ] ]] 
 fmt-j     = "j"                  => [[ [ dup day-of-year number>string ] ]] 
-fmt-m     = "m"                  => [[ [ dup month>> number>string 2 CHAR: 0 pad-left ] ]] 
-fmt-M     = "M"                  => [[ [ dup minute>> number>string 2 CHAR: 0 pad-left ] ]] 
-fmt-p     = "p"                  => [[ [ dup hour>> 12 < [ "AM" ] [ "PM" ] ? ] ]] 
-fmt-S     = "S"                  => [[ [ dup second>> round number>string 2 CHAR: 0 pad-left ] ]] 
+fmt-m     = "m"                  => [[ [ dup month>> number>string zero-pad ] ]] 
+fmt-M     = "M"                  => [[ [ dup minute>> number>string zero-pad ] ]] 
+fmt-p     = "p"                  => [[ [ dup hour>> 12 < "AM" "PM" ? ] ]] 
+fmt-S     = "S"                  => [[ [ dup second>> round number>string zero-pad ] ]] 
 fmt-U     = "U"                  => [[ [ dup week-of-year-sunday ] ]] 
 fmt-w     = "w"                  => [[ [ dup day-of-week number>string ] ]] 
 fmt-W     = "W"                  => [[ [ dup week-of-year-monday ] ]]