diff --git a/extra/time/time-docs.factor b/extra/time/time-docs.factor index b0ca12e9c6..8fbc59e315 100644 --- a/extra/time/time-docs.factor +++ b/extra/time/time-docs.factor @@ -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]." } diff --git a/extra/time/time.factor b/extra/time/time.factor index d0411bd5bf..be19fb0919 100644 --- a/extra/time/time.factor +++ b/extra/time/time.factor @@ -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 [[ [ 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 ] ]]