]> gitweb.factorcode.org Git - factor.git/commitdiff
strftime: Some fixes to support week-of-year.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 13 Oct 2008 13:19:21 +0000 (06:19 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 13 Oct 2008 13:19:21 +0000 (06:19 -0700)
extra/time/time-docs.factor
extra/time/time.factor

index b0ca12e9c6f02c07e766646e7b63c19bb586e977..8fbc59e315fb5317f36f52816c4b51d38569a0fd 100644 (file)
@@ -27,9 +27,9 @@ ARTICLE: "strftime" "Formatted timestamps"
     { "%M"     "Minute as a decimal number [00,59]." }
     { "%p"     "Either AM or PM." }
     { "%S"     "Second as a decimal number [00,59]." }
-    { "%U"     "Week number of the year (Sunday as the first day of the week) as a decimal numberb [00,53]." }
+    { "%U"     "Week number of the year (Sunday as the first day of the week) as a decimal number [00,53]." }
     { "%w"     "Weekday as a decimal number [0(Sunday),6]." }
-    { "%W"     "Week number of the year (Monday as the first day of the week) as a decimal numberb [00,53]." }
+    { "%W"     "Week number of the year (Monday as the first day of the week) as a decimal number [00,53]." }
     { "%x"     "Date representation." }
     { "%X"     "Time representation." }
     { "%y"     "Year without century as a decimal number [00,99]." }
index d0411bd5bf9e72b6caaf9fad399071737d159c19..be19fb0919b75c14578a2c4101aab2240ecaee2e 100644 (file)
@@ -14,13 +14,13 @@ IN: time
     [ month>> ] keep [ day>> ] keep year>> 3array
     [ number>string 2 CHAR: 0 pad-left ] map "/" join ; inline
 
-: week-of-year-sunday ( timestamp -- n )
-    dup clone 1 >>month 1 >>day day-of-week dup 0 > [ 7 swap - ] when 
+: (week-of-year) ( timestamp day -- n )
+    [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when
     [ day-of-year ] dip 2dup < [ 0 2nip ] [ - 7 / 1+ >fixnum ] if ;
 
-: week-of-year-monday ( timestamp -- n )
-    dup clone 1 >>month 1 >>day day-of-week dup 1 > [ 7 swap - ] when 
-    [ day-of-year ] dip 2dup < [ 0 2nip ] [ - 7 / 1+ >fixnum ] if ;
+: week-of-year-sunday ( timestamp -- n ) 0 (week-of-year) ; inline
+
+: week-of-year-monday ( timestamp -- n ) 1 (week-of-year) ; inline
 
 
 <PRIVATE
@@ -41,9 +41,9 @@ fmt-m     = "m"                  => [[ [ dup month>> number>string 2 CHAR: 0 pad
 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-U     = "U"                  => [[ [ "Not yet implemented" throw ] ]] 
+fmt-U     = "U"                  => [[ [ dup week-of-year-sunday ] ]] 
 fmt-w     = "w"                  => [[ [ dup day-of-week number>string ] ]] 
-fmt-W     = "W"                  => [[ [ "Not yet implemented" throw ] ]] 
+fmt-W     = "W"                  => [[ [ dup week-of-year-monday ] ]] 
 fmt-x     = "x"                  => [[ [ dup >datestring ] ]] 
 fmt-X     = "X"                  => [[ [ dup >timestring ] ]] 
 fmt-y     = "y"                  => [[ [ dup year>> 100 mod number>string ] ]]