AbstractTime.st
changeset 16829 2b434f626099
parent 16673 38e6f4c80e3a
child 16926 755f4c452bf4
equal deleted inserted replaced
16828:cf00d8f4970c 16829:2b434f626099
   960 ! !
   960 ! !
   961 
   961 
   962 
   962 
   963 !AbstractTime methodsFor:'printing & storing'!
   963 !AbstractTime methodsFor:'printing & storing'!
   964 
   964 
       
   965 addBasicPrintBindingsTo:aDictionary language:languageOrNil
       
   966     "private print support: add bindings for printing to aDictionary.
       
   967      languageOrNil can be #en, #fr, #de or nil for the current language.
       
   968      Here only basic bindings are added - no timezone am am/pm stuff,
       
   969      which doesn't make sense for TimeDuration.
       
   970 
       
   971      bindings:
       
   972         %h      hours, 00..23 (i.e. european)  0-padded to length 2
       
   973         %m      minutes, 00..59                0-padded to length 2
       
   974         %s      seconds, 00..59                0-padded to length 2
       
   975         %i      milliseconds, 000..999         0-padded to length 3
       
   976 
       
   977      Timestamp only:
       
   978         %(day)   day, 00..31                    0-padded to length 2
       
   979         %(month) month, 00..12                  0-padded to length 2
       
   980         %(year)  year, 4 digits                 0-padded to length 4
       
   981 
       
   982      special:
       
   983         %H      24-hours - unpadded
       
   984         %M      minutes - unpadded
       
   985         %S      seconds - unpadded
       
   986         %I      milliseconds, unpadded
       
   987 
       
   988         %t      seconds within hour  (unpadded)
       
   989         %T      seconds from midNight  (unpadded)
       
   990 
       
   991         %(milli1) milliseconds, truncated to 1/10th of a second 0..9         
       
   992         %(milli2) milliseconds, truncated to 1/100th of a second 00..99 0-padded to length 2        
       
   993         %(milli3) milliseconds, same as %i for convenience
       
   994 
       
   995      Timestamp only:
       
   996         %(Day)         - day - unpadded                    
       
   997         %(Month)       - month - unpadded                    
       
   998         %(yearOrTime)  - year or time 5 digits    as in unix-ls:
       
   999                                                   year if it is not the current year;
       
  1000                                                   time otherwise
       
  1001         %(weekDay)      - day in week (1->monday, 2->tuesday, ... ,7->sunday)
       
  1002 
       
  1003         %(dayName)      - full day name     
       
  1004         %(DayName)      - full day name, first character uppercase      
       
  1005         %(DAYNAME)      - full day name, all uppercase       
       
  1006 
       
  1007         %(monthName)    - full month name     
       
  1008         %(MonthName)    - full month name, first character uppercase      
       
  1009         %(MONTHNAME)    - full month name, all uppercase       
       
  1010 
       
  1011         %(shortDayName) - short (abbreviated) day name     
       
  1012         %(ShortDayName) - short (abbreviated) day name, first character uppercase      
       
  1013         %(SHORTDAYNAME) - short (abbreviated) day name, all uppercase       
       
  1014 
       
  1015         %(shortMonthName) - short (abbreviated) month name     
       
  1016         %(ShortMonthName) - short (abbreviated) month name, first character uppercase      
       
  1017         %(SHORTMONTHNAME) - short (abbreviated) month name, all uppercase       
       
  1018 
       
  1019         %(nth)          - counting day-in-month (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
       
  1020         %(weekDayNth)   - counting day-in-week (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')      
       
  1021         %(weekNth)      - counting week-in-year (1->'st'; 2->'nd'; 3->'rd'; 4...->'th')
       
  1022 
       
  1023 
       
  1024      The ISO8601 printString are generated with:
       
  1025 
       
  1026        Year:
       
  1027           YYYY (eg 1997)
       
  1028                 Date today printStringFormat:'%(year)'
       
  1029                 Timestamp now printStringFormat:'%(year)'  
       
  1030 
       
  1031        Year and month:
       
  1032           YYYY-MM (eg 1997-07)
       
  1033                 Date today printStringFormat:'%(year)-%(month)'  
       
  1034                 Timestamp now printStringFormat:'%(year)-%(month)'  
       
  1035 
       
  1036        Complete date:
       
  1037           YYYY-MM-DD (eg 1997-07-16)
       
  1038                 Date today printStringFormat:'%(year)-%(month)-%(day)'    
       
  1039                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)'  
       
  1040 
       
  1041        Complete date plus hours and minutes:
       
  1042           YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
       
  1043                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m%(TZD)'  
       
  1044 
       
  1045        Complete date plus hours, minutes and seconds:
       
  1046           YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
       
  1047                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s%(TZD)'  
       
  1048 
       
  1049        Complete date plus hours, minutes, seconds and a decimal fraction of a second
       
  1050           YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
       
  1051                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)'  
       
  1052 
       
  1053     "
       
  1054 
       
  1055     |hours minutes seconds millis s t|
       
  1056 
       
  1057     hours := self hours.
       
  1058     minutes := self minutes.
       
  1059     seconds := self seconds.
       
  1060     millis := self milliseconds.
       
  1061 
       
  1062     aDictionary at:$H put:(s := hours printString).
       
  1063     aDictionary at:$h put:(s leftPaddedTo:2 with:$0).
       
  1064 
       
  1065     aDictionary at:$M put:(s := minutes printString).
       
  1066     aDictionary at:$m put:(s leftPaddedTo:2 with:$0).
       
  1067 
       
  1068     aDictionary at:$S put:(s := seconds printString).
       
  1069     aDictionary at:$s put:(s leftPaddedTo:2 with:$0).
       
  1070 
       
  1071     aDictionary at:$I put:(s := millis printString).
       
  1072     aDictionary at:$i put:(t := s leftPaddedTo:3 with:$0).
       
  1073     aDictionary at:#milli3 put:t.
       
  1074 
       
  1075     aDictionary at:#milli1 put:((millis // 100) printString).
       
  1076     aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0).
       
  1077 
       
  1078     aDictionary at:$t put:(seconds * minutes) printString.
       
  1079     aDictionary at:$T put:(seconds * minutes * hours) printString.
       
  1080 
       
  1081 
       
  1082     "
       
  1083       |dict|
       
  1084       dict := Dictionary new.
       
  1085       Timestamp now addBasicPrintBindingsTo:dict language:#en.
       
  1086       dict inspect
       
  1087     "
       
  1088 !
       
  1089 
   965 addPrintBindingsTo:aDictionary
  1090 addPrintBindingsTo:aDictionary
   966     "private print support: add bindings for printing to aDictionary."
  1091     <resource: #obsolete>
   967 
  1092 
       
  1093     self obsoleteMethodWarning:'use #addPrintBindingsTo:language:'.
   968     self addPrintBindingsTo:aDictionary language:nil
  1094     self addPrintBindingsTo:aDictionary language:nil
   969 !
  1095 !
   970 
  1096 
   971 addPrintBindingsTo:aDictionary language:languageOrNil
  1097 addPrintBindingsTo:aDictionary language:languageOrNil
   972     "private print support: add bindings for printing to aDictionary.
  1098     "private print support: add bindings for printing to aDictionary.
  1060           YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
  1186           YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
  1061                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)'  
  1187                 Timestamp now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)'  
  1062 
  1188 
  1063     "
  1189     "
  1064 
  1190 
  1065     |hours minutes seconds millis usHours ampm s t zone tzDelta|
  1191     |usHours ampm s zone tzDelta|
  1066 
  1192 
  1067     hours := self hours.
  1193     self addBasicPrintBindingsTo:aDictionary language:languageOrNil.
  1068     minutes := self minutes.
       
  1069     seconds := self seconds.
       
  1070     millis := self milliseconds.
       
  1071     zone := self timeZoneName.
  1194     zone := self timeZoneName.
  1072     tzDelta := self timeZoneDeltaInMinutes.
  1195     tzDelta := self timeZoneDeltaInMinutes.
  1073 
  1196 
  1074     ampm := self meridianAbbreviation.
  1197     ampm := self meridianAbbreviation.
  1075     usHours := self hour12.
  1198     usHours := self hour12 printString.
  1076 
  1199     aDictionary at:$U put:usHours.
  1077     aDictionary at:$H put:(s := hours printString).
  1200     aDictionary at:$u put:(usHours leftPaddedTo:2 with:$0).
  1078     aDictionary at:$h put:(s leftPaddedTo:2 with:$0).
  1201 
  1079 
       
  1080     aDictionary at:$U put:(s := usHours printString).
       
  1081     aDictionary at:$u put:(s leftPaddedTo:2 with:$0).
       
  1082 
       
  1083     aDictionary at:$M put:(s := minutes printString).
       
  1084     aDictionary at:$m put:(s leftPaddedTo:2 with:$0).
       
  1085 
       
  1086     aDictionary at:$S put:(s := seconds printString).
       
  1087     aDictionary at:$s put:(s leftPaddedTo:2 with:$0).
       
  1088 
       
  1089     aDictionary at:$I put:(s := millis printString).
       
  1090     aDictionary at:$i put:(t := s leftPaddedTo:3 with:$0).
       
  1091     aDictionary at:#milli3 put:t.
       
  1092 
       
  1093     aDictionary at:#milli1 put:((millis // 100) printString).
       
  1094     aDictionary at:#milli2 put:((millis // 10) printStringLeftPaddedTo:2 with:$0).
       
  1095 
       
  1096     aDictionary at:$t put:(seconds * minutes) printString.
       
  1097     aDictionary at:$T put:(seconds * minutes * hours) printString.
       
  1098 
  1202 
  1099     aDictionary at:$a put:ampm.
  1203     aDictionary at:$a put:ampm.
  1100     aDictionary at:$A put:ampm asUppercase.
  1204     aDictionary at:$A put:ampm asUppercase.
  1101     aDictionary at:$z put:zone.
  1205     aDictionary at:$z put:zone.
  1102     aDictionary at:$Z put:zone asUppercase.
  1206     aDictionary at:$Z put:zone asUppercase.
  1197     "print using a format string.
  1301     "print using a format string.
  1198      See #addPrintBindingsTo:language: for allowed format strings"
  1302      See #addPrintBindingsTo:language: for allowed format strings"
  1199 
  1303 
  1200     |s|
  1304     |s|
  1201 
  1305 
  1202     s := WriteStream on:(String new:20).
  1306     s := CharacterWriteStream on:(String new:20).
  1203     self printOn:s format:aFormatString language:languageString.
  1307     self printOn:s format:aFormatString language:languageString.
  1204     ^ s contents.
  1308     ^ s contents.
  1205 
  1309 
  1206     "
  1310     "
  1207      Timestamp now printStringFormat:'%U:%m:%s %a  
  1311      Timestamp now printStringFormat:'%U:%m:%s %a  
  1276 ! !
  1380 ! !
  1277 
  1381 
  1278 !AbstractTime class methodsFor:'documentation'!
  1382 !AbstractTime class methodsFor:'documentation'!
  1279 
  1383 
  1280 version
  1384 version
  1281     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.82 2014-07-01 13:58:11 az Exp $'
  1385     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.83 2014-09-05 14:14:06 stefan Exp $'
  1282 !
  1386 !
  1283 
  1387 
  1284 version_CVS
  1388 version_CVS
  1285     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.82 2014-07-01 13:58:11 az Exp $'
  1389     ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.83 2014-09-05 14:14:06 stefan Exp $'
  1286 ! !
  1390 ! !
  1287 
  1391