From 82b312e31642f7c16cfd493fa54560d84eceeeb6 Mon Sep 17 00:00:00 2001 From: erg Date: Fri, 29 Sep 2006 18:22:11 +0000 Subject: [PATCH] calendar -- refactor printing the time --- contrib/calendar/calendar.factor | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/contrib/calendar/calendar.factor b/contrib/calendar/calendar.factor index aa881e7b88..70415eb1b5 100644 --- a/contrib/calendar/calendar.factor +++ b/contrib/calendar/calendar.factor @@ -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 ;