AbstractTime.st
changeset 6172 a3c88ea5efe9
parent 6048 af4b1127f362
child 6419 5cf00f5e656d
--- a/AbstractTime.st	Fri Nov 09 15:45:23 2001 +0100
+++ b/AbstractTime.st	Fri Nov 09 16:18:46 2001 +0100
@@ -49,6 +49,98 @@
         Time Date AbsoluteTime
         Delay ProcessorScheduler
 "
+!
+
+iso8601Format
+"
+  Abstract
+
+    This document defines a profile of ISO 8601, the International Standard for the representation of dates and times. ISO
+    8601 describes a large number of date/time formats. To reduce the scope for error and the complexity of software, it is
+    useful to restrict the supported formats to a small number. This profile defines a few date/time formats, likely to satisfy
+    most requirements. 
+
+
+  Formats
+
+    Different standards may need different levels of granularity in the date and time, so this profile defines six levels.
+    Standards that reference this profile should specify one or more of these granularities. If a given standard allows more
+    than one granularity, it should specify the meaning of the dates and times with reduced precision, for example, the result
+    of comparing two dates with different precisions.
+
+    The formats are as follows. Exactly the components shown here must be present, with exactly this punctuation. Note
+    that the 'T' appears literally in the string, to indicate the beginning of the time element, as specified in ISO 8601. 
+
+       Year:
+          YYYY (eg 1997)
+       Year and month:
+          YYYY-MM (eg 1997-07)
+       Complete date:
+          YYYY-MM-DD (eg 1997-07-16)
+       Complete date plus hours and minutes:
+          YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
+       Complete date plus hours, minutes and seconds:
+          YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
+       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)
+
+    where:
+
+         YYYY = four-digit year
+         MM   = two-digit month (01=January, etc.)
+         DD   = two-digit day of month (01 through 31)
+         hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
+         mm   = two digits of minute (00 through 59)
+         ss   = two digits of second (00 through 59)
+         s    = one or more digits representing a decimal fraction of a second
+         TZD  = time zone designator (Z or +hh:mm or -hh:mm)
+
+    This profile does not specify how many digits may be used to represent the decimal fraction of a second. An adopting
+    standard that permits fractions of a second must specify both the minimum number of digits (a number greater than or
+    equal to one) and the maximum number of digits (the maximum may be stated to be 'unlimited').
+
+    This profile defines two ways of handling time zone offsets:
+
+       1.Times are expressed in UTC (Coordinated Universal Time), with a special UTC designator ('Z'). 
+       2.Times are expressed in local time, together with a time zone offset in hours and minutes. A time zone offset of
+         '+hh:mm' indicates that the date/time uses a local time zone which is 'hh' hours and 'mm' minutes ahead of
+         UTC. A time zone offset of '-hh:mm' indicates that the date/time uses a local time zone which is 'hh' hours and
+         'mm' minutes behind UTC. 
+
+    A standard referencing this profile should permit one or both of these ways of handling time zone offsets.
+
+  The ISO8601 printString are generated with:
+
+       Year:
+          YYYY (eg 1997)
+                Date today printStringFormat:'%(year)'
+                AbsoluteTime now printStringFormat:'%(year)'  
+
+       Year and month:
+          YYYY-MM (eg 1997-07)
+                Date today printStringFormat:'%(year)-%(month)'  
+                AbsoluteTime now printStringFormat:'%(year)-%(month)'  
+
+       Complete date:
+          YYYY-MM-DD (eg 1997-07-16)
+                Date today printStringFormat:'%(year)-%(month)-%(day)'    
+                AbsoluteTime now printStringFormat:'%(year)-%(month)-%(day)'  
+
+       Complete date plus hours and minutes:
+          YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
+                AbsoluteTime 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)
+                AbsoluteTime 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)
+                AbsoluteTime now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)'  
+
+
+"
 ! !
 
 !AbstractTime class methodsFor:'instance creation'!
@@ -182,6 +274,52 @@
     "
 ! !
 
+!AbstractTime methodsFor:'abstract'!
+
+hours
+    "return the hours (0..23)"
+
+    ^ self subclassResponsibility
+
+    "
+     AbsoluteTime now hours 
+     Time now hours 
+    "
+!
+
+milliseconds
+    "return the milliseconds (0..999)"
+
+    ^ self subclassResponsibility
+
+    "
+     AbsoluteTime now milliseconds 
+     Time now milliseconds 
+    "
+!
+
+minutes
+    "return the minutes (0..59)"
+
+    ^ self minutes.
+
+    "
+     AbsoluteTime now minutes 
+     Time now minutes 
+    "
+!
+
+seconds
+    "return the seconds (0..59)"
+
+    ^ self subclassResponsibility
+
+    "
+     AbsoluteTime now seconds 
+     Time now seconds 
+    "
+! !
+
 !AbstractTime methodsFor:'accessing'!
 
 hourInDay
@@ -219,6 +357,10 @@
     "Created: 22.10.1996 / 09:27:47 / stefan"
 !
 
+timeZoneDeltaInMinutes
+    ^ 0
+!
+
 timeZoneName
     ^ 'utc'
 !
@@ -506,22 +648,23 @@
 addPrintBindingsTo:aDictionary
     "add bindings for printing to aDictionary."
 
-    |hours minutes seconds millis usHours ampm s zone|
+    |hours minutes seconds millis usHours ampm s zone tzDelta|
 
     hours := self hours.
     minutes := self minutes.
     seconds := self seconds.
     millis := self milliseconds.
     zone := self timeZoneName.
+    tzDelta := self timeZoneDeltaInMinutes.
 
     hours // 12 == 0 ifTrue:[
-	ampm := 'am'.
+        ampm := 'am'.
     ] ifFalse:[
-	ampm := 'pm'.
+        ampm := 'pm'.
     ].
     usHours := hours.
     usHours ~~ 0 ifTrue:[
-	usHours := usHours - 1 \\ 12 + 1.
+        usHours := usHours - 1 \\ 12 + 1.
     ].
 
     aDictionary at:$H put:(s := hours printString).
@@ -542,6 +685,13 @@
     aDictionary at:$A put:ampm asUppercase.
     aDictionary at:$z put:zone.
     aDictionary at:$Z put:zone asUppercase.
+
+    s := tzDelta >= 0 ifTrue:[ '+' ] ifFalse:[ '-' ].
+    tzDelta := tzDelta abs.
+    s := s , ((tzDelta // 60) printStringLeftPaddedTo:2 with:$0).
+    s := s , ':'.
+    s := s , ((tzDelta \\ 60) printStringLeftPaddedTo:2 with:$0).
+    aDictionary at:#TZD put:s
 !
 
 printOn:aStream format:aFormatString
@@ -601,9 +751,9 @@
         %a      am/pm
 
      AbsoluteTime 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
+        %(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
@@ -616,12 +766,45 @@
         %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        
 
      AbsoluteTime only:
         %Day    day - unpadded                    
         %Month  month - unpadded                    
+
+
+     The ISO8601 printString are generated with:
+
+       Year:
+          YYYY (eg 1997)
+                Date today printStringFormat:'%(year)'
+                AbsoluteTime now printStringFormat:'%(year)'  
+
+       Year and month:
+          YYYY-MM (eg 1997-07)
+                Date today printStringFormat:'%(year)-%(month)'  
+                AbsoluteTime now printStringFormat:'%(year)-%(month)'  
+
+       Complete date:
+          YYYY-MM-DD (eg 1997-07-16)
+                Date today printStringFormat:'%(year)-%(month)-%(day)'    
+                AbsoluteTime now printStringFormat:'%(year)-%(month)-%(day)'  
+
+       Complete date plus hours and minutes:
+          YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
+                AbsoluteTime 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)
+                AbsoluteTime 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)
+                AbsoluteTime now printStringFormat:'%(year)-%(month)-%(day)T%h:%m:%s.%(milli2)%(TZD)'  
+
     "
 
     |dict|
@@ -704,5 +887,5 @@
 !AbstractTime class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.33 2001-09-26 13:11:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractTime.st,v 1.34 2001-11-09 15:18:46 cg Exp $'
 ! !