strftime: Some fixes to support week-of-year.

db4
John Benediktsson 2008-10-13 06:19:21 -07:00
parent acbc658688
commit e9a36ebda3
2 changed files with 9 additions and 9 deletions

View 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]." }

View 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 ] ]]