AbstractTime.st
branchjv
changeset 17815 956b46750806
parent 17814 b75a7f0c346b
child 17834 04ff72c5039a
--- a/AbstractTime.st	Mon Dec 20 07:13:27 2010 +0000
+++ b/AbstractTime.st	Fri Feb 04 23:09:23 2011 +0000
@@ -178,6 +178,22 @@
     "
 
     "Modified: 1.7.1996 / 15:20:10 / cg"
+!
+
+utcNow
+    "return an instance of myself representing this momentin the UTC timezone."
+
+    ^ self subclassResponsibility
+
+    "
+     Timestamp utcNow   
+     Timestamp utcNow
+
+     Time now   
+     Time utcNow   
+    "
+
+    "Modified: 1.7.1996 / 15:20:10 / cg"
 ! !
 
 !AbstractTime class methodsFor:'Compatibility-Squeak'!
@@ -516,18 +532,6 @@
 
 timeZoneName
     ^ #utc
-!
-
-weekInYear
-    "return the week number of the receiver - 1 for Jan, 1st."
-
-    ^ Date weekInYearOf:self
-
-    "
-     (Timestamp newDay:1 year:2000) weekInYear    
-     (Timestamp newDay:2 year:2000) weekInYear    
-     (Timestamp newDay:3 year:2000) weekInYear    
-    "
 ! !
 
 !AbstractTime methodsFor:'arithmetic'!
@@ -843,7 +847,21 @@
     ^ self asTimestamp
 !
 
+asLocalTimestamp
+    "represent myself as a timestamp in the local timezone"
+
+    ^ self subclassResponsibility
+!
+
 asTimestamp
+    "represent myself as a Timestamp"
+
+    ^ self subclassResponsibility
+!
+
+asUtcTimestamp
+    "represent myself as a timestamp in the local timezone"
+
     ^ self subclassResponsibility
 ! !
 
@@ -863,7 +881,8 @@
 
 addPrintBindingsTo:aDictionary language:languageOrNil
     "private print support: add bindings for printing to aDictionary.
-     languageOrNil can only be #en or nil for the current language.
+     languageOrNil can be #en, #fr, #de or nil for the current language.
+
      bindings:
         %h      hours, 00..23 (i.e. european)  0-padded to length 2
         %u      hours, 00..12 (i.e. us)        0-padded to length 2
@@ -890,19 +909,36 @@
 
         %(TZD)  timeZone delta from UTC in the format +/-hh:mm  
 
-        %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        
-
-        %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')      
+        %(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        
 
      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
+        %(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:
@@ -988,84 +1024,9 @@
 
 printOn:aStream format:aFormatString
     "print using a format string;
-     valid format items are:
-        %h      hours, 00..23 (i.e. european)  0-padded to length 2
-        %u      hours, 00..12 (i.e. us)        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
-        %a      am/pm
-
-     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
-        %U      12-hours - unpadded
-        %M      minutes - unpadded
-        %S      seconds - unpadded
-        %I      milliseconds, unpadded
-        %A      AM/PM   - uppercase
-
-        %t      seconds within hour  (unpadded)
-        %T      seconds from midNight  (unpadded)
-
-        %(TZD)  timeZone delta from UTC in the format +/-hh:mm  
-
-        %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        
-
-        %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')      
+     See #addPrintBindingsTo:language: for allowed format strings"
 
-     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
-
-
-     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)'  
-
-    "
-
-    |dict|
-
-    dict := IdentityDictionary new.
-    self addPrintBindingsTo:dict.
-
-    aFormatString expandPlaceholdersWith:dict on:aStream
+    self printOn:aStream format:aFormatString language:nil.
 
     "
      Timestamp now printOn:Transcript format:'%h:%m:%s'   . Transcript cr.      
@@ -1082,77 +1043,7 @@
 
 printOn:aStream format:aFormatString language:languageString
     "print using a format string;
-     valid format items are:
-        %h      hours, 00..23 (i.e. european)  0-padded to length 2
-        %u      hours, 00..12 (i.e. us)        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
-        %a      am/pm
-
-     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
-        %U      12-hours - unpadded
-        %M      minutes - unpadded
-        %S      seconds - unpadded
-        %I      milliseconds, unpadded
-        %A      AM/PM   - uppercase
-
-        %t      seconds within hour  (unpadded)
-        %T      seconds from midNight  (unpadded)
-
-        %(TZD)  timeZone delta from UTC in the format +/-hh:mm  
-
-        %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        
-
-        %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')      
-
-     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
-
-
-     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)'  
-
-    "
+     See #addPrintBindingsTo:language: for allowed format strings"
 
     |dict|
 
@@ -1175,13 +1066,10 @@
 !
 
 printStringFormat:aFormatString
-    "print using a format string  - see #printOn:format:"
-
-    |s|
+    "print using a format string.
+     See #addPrintBindingsTo:language: for allowed format strings"
 
-    s := WriteStream on:(String new:20).
-    self printOn:s format:aFormatString.
-    ^ s contents.
+    ^ self printStringFormat:aFormatString language:nil.
 
     "
      Timestamp now printStringFormat:'%U:%m:%s %a'   
@@ -1208,7 +1096,8 @@
 !
 
 printStringFormat:aFormatString language:languageString
-    "print using a format string  - see #printOn:format:"
+    "print using a format string.
+     See #addPrintBindingsTo:language: for allowed format strings"
 
     |s|
 
@@ -1227,7 +1116,9 @@
      Timestamp now printStringFormat:'%H:%m:%s.%(milli1)'   
      Timestamp now printStringFormat:'%H:%m:%s.%(milli2)'     
      Timestamp now printStringFormat:'%(day)-%(month)-%(year) :%m:%s'       
-     Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s'       
+     Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#en      
+     Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#de      
+     Timestamp now printStringFormat:'%(day)-%(monthName)-%(year) :%m:%s' language:#fr      
      Time now printStringFormat:'%u:%m:%s %a'   
      Time now printStringFormat:'%h:%m'         
      Time now printStringFormat:'%h:%m'         
@@ -1289,15 +1180,15 @@
 !AbstractTime class methodsFor:'documentation'!
 
 version
-    ^ '$Id: AbstractTime.st 10602 2010-12-20 07:13:27Z vranyj1 $'
+    ^ '$Id: AbstractTime.st 10604 2011-02-04 23:09:23Z vranyj1 $'
 !
 
 version_CVS
-    ^ 'Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.71 2010/09/29 09:15:08 stefan Exp '
+    ^ 'Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.73 2011/01/24 19:55:34 stefan Exp '
 !
 
 version_SVN
-    ^ '$Id: AbstractTime.st 10602 2010-12-20 07:13:27Z vranyj1 $'
+    ^ '$Id: AbstractTime.st 10604 2011-02-04 23:09:23Z vranyj1 $'
 ! !
 
 
@@ -1305,3 +1196,4 @@
 
 
 
+