calendar -- refactor printing the time

darcs
erg 2006-09-29 18:22:11 +00:00
parent f0f291d8ff
commit 82b312e316
1 changed files with 19 additions and 11 deletions

View File

@ -264,17 +264,25 @@ M: number +second ( timestamp n -- timestamp )
: print-year ( year -- )
12 [ 1+ print-month terpri ] each-with ;
: timestamp>http-string ( timestamp -- string )
#! http timestamp format
#! Example: Tue, 15 Nov 1994 08:12:31 GMT
>gmt
: (timestamp>string) ( timestamp -- )
dup day-of-week day-abbreviations3 nth write ", " write
dup timestamp-day unparse write bl
dup timestamp-month months-abbreviations nth write bl
dup timestamp-year unparse write bl
dup timestamp-hour unparse 2 CHAR: 0 pad-left write ":" write
dup timestamp-minute unparse 2 CHAR: 0 pad-left write ":" write
timestamp-second >fixnum unparse 2 CHAR: 0 pad-left write ;
: timestamp>string ( timestamp -- str )
[
dup day-of-week day-abbreviations3 nth write ", " write
dup timestamp-day unparse write bl
dup timestamp-month months-abbreviations nth write bl
dup timestamp-year unparse write bl
dup timestamp-hour unparse 2 CHAR: 0 pad-left write ":" write
dup timestamp-minute unparse 2 CHAR: 0 pad-left write ":" write
timestamp-second >fixnum unparse 2 CHAR: 0 pad-left write " GMT" write
(timestamp>string)
] string-out ;
: timestamp>http-string ( timestamp -- str )
#! http timestamp format
#! Example: Tue, 15 Nov 1994 08:12:31 GMT
>gmt [
(timestamp>string)
" GMT" write
] string-out ;