diff -r cf00d8f4970c -r 2b434f626099 AbstractTime.st --- a/AbstractTime.st Tue Sep 02 15:30:25 2014 +0200 +++ b/AbstractTime.st Fri Sep 05 16:14:06 2014 +0200 @@ -962,9 +962,135 @@ !AbstractTime methodsFor:'printing & storing'! +addBasicPrintBindingsTo:aDictionary language:languageOrNil + "private print support: add bindings for printing to aDictionary. + languageOrNil can be #en, #fr, #de or nil for the current language. + Here only basic bindings are added - no timezone am am/pm stuff, + which doesn't make sense for TimeDuration. + + bindings: + %h hours, 00..23 (i.e. european) 0-padded to length 2 + %m minutes, 00..59 0-padded to length 2 + %s seconds, 00..59 0-padded to length 2 + %i milliseconds, 000..999 0-padded to length 3 + + Timestamp only: + %(day) day, 00..31 0-padded to length 2 + %(month) month, 00..12 0-padded to length 2 + %(year) year, 4 digits 0-padded to length 4 + + special: + %H 24-hours - unpadded + %M minutes - unpadded + %S seconds - unpadded + %I milliseconds, unpadded + + %t seconds within hour (unpadded) + %T seconds from midNight (unpadded) + + %(milli1) milliseconds, truncated to 1/10th of a second 0..9 + %(milli2) milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2 + %(milli3) milliseconds, same as %i for convenience + + Timestamp only: + %(Day) - day - unpadded + %(Month) - month - unpadded + %(yearOrTime) - year or time 5 digits as in unix-ls: + year if it is not the current year; + time otherwise + %(weekDay) - day in week (1->monday, 2->tuesday, ... ,7->sunday) + + %(dayName) - full day name + %(DayName) - full day name, first character uppercase + %(DAYNAME) - full day name, all uppercase + + %(monthName) - full month name + %(MonthName) - full month name, first character uppercase + %(MONTHNAME) - full month name, all uppercase + + %(shortDayName) - short (abbreviated) day name + %(ShortDayName) - short (abbreviated) day name, first character uppercase + %(SHORTDAYNAME) - short (abbreviated) day name, all uppercase + + %(shortMonthName) - short (abbreviated) month name + %(ShortMonthName) - short (abbreviated) month name, first character uppercase + %(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase + + %(nth) - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') + %(weekDayNth) - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') + %(weekNth) - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th') + + + The ISO8601 printString are generated with: + + Year: + YYYY (eg 1997) + Date today printStringFormat:'%(year)' + Timestamp now printStringFormat:'%(year)' + + Year and month: + YYYY-MM (eg 1997-07) + Date today printStringFormat:'%(year)-%(month)' + Timestamp now printStringFormat:'%(year)-%(month)' + + Complete date: + YYYY-MM-DD (eg 1997-07-16) + Date today printStringFormat:'%(year)-%(month)-%(day)' + Timestamp now printStringFormat:'%(year)-%(month)-%(day)' + + Complete date plus hours and minutes: + YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00) + Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m%(TZD)' + + Complete date plus hours, minutes and seconds: + YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00) + Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s%(TZD)' + + Complete date plus hours, minutes, seconds and a decimal fraction of a second + YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00) + Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)' + + " + + |hours minutes seconds millis s t| + + hours := self hours. + minutes := self minutes. + seconds := self seconds. + millis := self milliseconds. + + aDictionary at:$H put:(s := hours printString). + aDictionary at:$h put:(s leftPaddedTo:2 with:$0). + + aDictionary at:$M put:(s := minutes printString). + aDictionary at:$m put:(s leftPaddedTo:2 with:$0). + + aDictionary at:$S put:(s := seconds printString). + aDictionary at:$s put:(s leftPaddedTo:2 with:$0). + + aDictionary at:$I put:(s := millis printString). + aDictionary at:$i put:(t := s leftPaddedTo:3 with:$0). + aDictionary at:#milli3 put:t. + + aDictionary at:#milli1 put:((millis // 100) printString). + aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0). + + aDictionary at:$t put:(seconds * minutes) printString. + aDictionary at:$T put:(seconds * minutes * hours) printString. + + + " + |dict| + dict := Dictionary new. + Timestamp now addBasicPrintBindingsTo:dict language:#en. + dict inspect + " +! + addPrintBindingsTo:aDictionary - "private print support: add bindings for printing to aDictionary." + + self obsoleteMethodWarning:'use #addPrintBindingsTo:language:'. self addPrintBindingsTo:aDictionary language:nil ! @@ -1062,39 +1188,17 @@ " - |hours minutes seconds millis usHours ampm s t zone tzDelta| + |usHours ampm s zone tzDelta| - hours := self hours. - minutes := self minutes. - seconds := self seconds. - millis := self milliseconds. + self addBasicPrintBindingsTo:aDictionary language:languageOrNil. zone := self timeZoneName. tzDelta := self timeZoneDeltaInMinutes. ampm := self meridianAbbreviation. - usHours := self hour12. - - aDictionary at:$H put:(s := hours printString). - aDictionary at:$h put:(s leftPaddedTo:2 with:$0). - - aDictionary at:$U put:(s := usHours printString). - aDictionary at:$u put:(s leftPaddedTo:2 with:$0). - - aDictionary at:$M put:(s := minutes printString). - aDictionary at:$m put:(s leftPaddedTo:2 with:$0). + usHours := self hour12 printString. + aDictionary at:$U put:usHours. + aDictionary at:$u put:(usHours leftPaddedTo:2 with:$0). - aDictionary at:$S put:(s := seconds printString). - aDictionary at:$s put:(s leftPaddedTo:2 with:$0). - - aDictionary at:$I put:(s := millis printString). - aDictionary at:$i put:(t := s leftPaddedTo:3 with:$0). - aDictionary at:#milli3 put:t. - - aDictionary at:#milli1 put:((millis // 100) printString). - aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0). - - aDictionary at:$t put:(seconds * minutes) printString. - aDictionary at:$T put:(seconds * minutes * hours) printString. aDictionary at:$a put:ampm. aDictionary at:$A put:ampm asUppercase. @@ -1199,7 +1303,7 @@ |s| - s := WriteStream on:(String new:20). + s := CharacterWriteStream on:(String new:20). self printOn:s format:aFormatString language:languageString. ^ s contents. @@ -1278,10 +1382,10 @@ !AbstractTime class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.82 2014-07-01 13:58:11 az Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.83 2014-09-05 14:14:06 stefan Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.82 2014-07-01 13:58:11 az Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.83 2014-09-05 14:14:06 stefan Exp $' ! !