AbstractTime.st
branchjv
changeset 17807 06cc6c49e291
parent 17797 71451ae83564
child 17814 b75a7f0c346b
--- a/AbstractTime.st	Tue Nov 09 13:54:57 2010 +0000
+++ b/AbstractTime.st	Tue Nov 09 16:24:28 2010 +0000
@@ -976,6 +976,14 @@
             ':' , ((tzDelta \\ 60) printStringLeftPaddedTo:2 with:$0).
     ].
     aDictionary at:#TZD put:s
+
+
+    "
+      |dict|
+      dict := Dictionary new.
+      Timestamp now addPrintBindingsTo:dict language:#en.
+      dict inspect
+    "
 !
 
 printOn:aStream format:aFormatString
@@ -1072,6 +1080,100 @@
     "Modified: 22.2.1996 / 16:58:30 / cg"
 !
 
+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)'  
+
+    "
+
+    |dict|
+
+    dict := IdentityDictionary new.
+    self addPrintBindingsTo:dict language:languageString.
+
+    aFormatString expandPlaceholdersWith:dict on:aStream
+
+    "
+     Timestamp now printOn:Transcript format:'%h:%m:%s'   . Transcript cr.      
+     Time now printOn:Transcript format:'%h:%m:%s'   . Transcript cr.      
+     Time now printOn:Transcript format:'%H:%m:%s'   . Transcript cr.      
+     Time now printOn:Transcript format:'%u:%m:%s %a'. Transcript cr.   
+     Time now printOn:Transcript format:'%h:%m'      . Transcript cr. 
+     Time now printOn:Transcript format:'%H:%m %A'   . Transcript cr.
+     Time now printOn:Transcript format:'minutes:%M seconds:%S'. Transcript cr.
+    "
+
+    "Modified: 22.2.1996 / 16:58:30 / cg"
+!
+
 printStringFormat:aFormatString
     "print using a format string  - see #printOn:format:"
 
@@ -1103,6 +1205,39 @@
     "
 
     "Modified: 22.2.1996 / 16:58:30 / cg"
+!
+
+printStringFormat:aFormatString language:languageString
+    "print using a format string  - see #printOn:format:"
+
+    |s|
+
+    s := WriteStream on:(String new:20).
+    self printOn:s format:aFormatString language:languageString.
+    ^ s contents.
+
+    "
+     Timestamp now printStringFormat:'%U:%m:%s %a  
+     Time now printStringFormat:'%U:%m:%s %a'   
+
+     Time now printStringFormat:'%h:%m:%s'      
+     Time now printStringFormat:'%H:%m:%s'      
+     Time now printStringFormat:'%H:%m:%s.%i'           
+     Timestamp now printStringFormat:'%H:%m:%s.%i'   
+     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'       
+     Time now printStringFormat:'%u:%m:%s %a'   
+     Time now printStringFormat:'%h:%m'         
+     Time now printStringFormat:'%h:%m'         
+     Time now printStringFormat:'%H:%m %A'     
+     Time now printStringFormat:'%m minutes after %U %a'     
+     Time now printStringFormat:'%t seconds after %U %a'     
+     Time now printStringFormat:'%T seconds from midNight'     
+    "
+
+    "Modified: 22.2.1996 / 16:58:30 / cg"
 ! !
 
 !AbstractTime methodsFor:'private'!
@@ -1154,17 +1289,18 @@
 !AbstractTime class methodsFor:'documentation'!
 
 version
-    ^ '$Id: AbstractTime.st 10570 2010-08-26 10:12:57Z vranyj1 $'
+    ^ '$Id: AbstractTime.st 10590 2010-11-09 16:24:28Z vranyj1 $'
 !
 
 version_CVS
-    ^ 'Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.70 2010/08/19 11:20:32 cg Exp '
+    ^ 'Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.71 2010-09-29 09:15:08 stefan Exp '
 !
 
 version_SVN
-    ^ '$Id: AbstractTime.st 10570 2010-08-26 10:12:57Z vranyj1 $'
+    ^ '$Id: AbstractTime.st 10590 2010-11-09 16:24:28Z vranyj1 $'
 ! !
 
 
 
 
+