Timestamp.st
changeset 16915 2174b3784836
parent 16914 c550a2e2359d
child 16919 80445b2bec64
--- a/Timestamp.st	Wed Nov 05 21:27:34 2014 +0100
+++ b/Timestamp.st	Wed Nov 05 21:46:42 2014 +0100
@@ -2623,17 +2623,19 @@
 
 documentation
 "
-    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. Also, class
-    methods can be used to print but the main reading job is done in instance protocol. It has been
-    written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method.
-
-    It produces timestamps, ie. when the string (or stream) contains only a time, an error will result
+    TimestampISO8601Builder is designed to read any (almost) format of ISO 8601 encoded timestamp. 
+    Also, class methods can be used to print but the main reading job is done in instance protocol. 
+    It has been written because of insufficient abilities of Timestamp #readIso8601FormatFrom: method
+    (which was now changed to call this as well).
+
+    It produces timestamps, i.e. when the string (or stream) contains only a time, an error will result
     (it may also pass in some cases but with the time undestood as date). It survives incomplete dates,
     broken years, incomplete times and timezones. All times read with timezone difference are recomputed
     to UTC before the timestamp is created (even passing across new year boundary is handled correctly).
     Unknown offsets (usually local) are considered UTC - this may be wrong and more work is probably needed.
     All data is checked for validity (including leap years, leap seconds,...) during reading and as soon as
-    possible. For an example of what the builder can read, see the examples method and ISO 8601 itself.
+    possible. 
+    For an example of what the builder can read, see the examples method and ISO 8601 itself.
 
     [author:]
         Martin Dvorak (masca@volny.cz)
@@ -2656,7 +2658,7 @@
 
 examples
 "
-    See the testing protocol on instance protocol (should be turned into a TestCase).
+    See the unit tests in exept:regression >> RegressionTests::timeAndDateTest
     It covers the main features this builder has.
 
     Just to introduce some coding examples, try:
@@ -2757,146 +2759,6 @@
     "Created: / 15-06-2005 / 17:52:03 / masca"
 ! !
 
-!Timestamp::TimestampISO8601Builder class methodsFor:'testing'!
-
-test
-
-    self test_date.
-    self test_time.
-    self test_timezone.
-    self test_edge.
-
-    "
-        TimestampISO8601Builder test
-    "
-
-    "Created: / 15-06-2005 / 17:51:16 / masca"
-    "Modified: / 16-06-2005 / 10:15:55 / masca"
-!
-
-test_date
-
-    | ts |
-    ts := UtcTimestamp
-         year: 2005 month: 6 day: 15
-         hour: 0 minute: 0 second: 0 millisecond: 0.
-
-    "Test common dates"
-    self assert: ts = (self read: '20050615' withClass:Timestamp).
-    self assert: ts = (self read: '2005-06-15'  withClass:Timestamp).
-    self assert: ts = (self read: '05-06-15'  withClass:Timestamp).
-    self assert: ts = (self read: '05-0615'  withClass:Timestamp). "/ Is this correct?
-    self assert: ts = (self read: ':50615'  withClass:Timestamp). "/ Should not happen and should not appear after 2009
-    self assert: ts = (self read: '200506-15'  withClass:Timestamp). "/ Is this corect?
-    self assert: ts = (self read: '105-06-15'  withClass:Timestamp). "/ Should not happen
-
-    "Test week numbers"
-    "/self assert: ts = (self read: '05W243'  withClass:Timestamp).
-    "/self assert: ts = (self read: '2005W24-3'  withClass:Timestamp).
-
-    "Test day numbers"
-    "self assert: ts = (self read: '2005-166'  withClass:Timestamp).
-
-    ts := Timestamp year: 2004 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '2004-366'  withClass:Timestamp).
-
-    ts := Timestamp year: 2005 month: 12 day: 31 hour: 0 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '2004-365'  withClass:Timestamp)."
-
-    "Test february"
-    ts := UtcTimestamp year: 2000 month: 2 day: 28 hour: 0 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '20000228'  withClass:Timestamp).
-
-    ts := UtcTimestamp year: 2000 month: 2 day: 29 hour: 0 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '20000229'  withClass:Timestamp).
-
-    "
-        TimestampISO8601Builder new test_date
-    "
-
-
-    "Created: / 15-06-2005 / 17:21:56 / masca"
-    "Modified: / 16-06-2005 / 11:50:04 / masca"
-!
-
-test_edge
-
-    | ts |
-
-    self test_mustFail: [self read: '20050229' withClass:Timestamp].
-    self test_mustFail: [self read: '20050029' withClass:Timestamp].
-    self test_mustFail: [self read: '20050332' withClass:Timestamp].
-    self test_mustFail: [self read: '2005-366' withClass:Timestamp].
-
-    ts := UtcTimestamp year: 2005 month: 1 day: 1 hour: 0 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '20041231T22-0200' withClass:Timestamp).
-
-    ts := UtcTimestamp year: 2004 month: 12 day: 31 hour: 22 minute: 0 second: 0 millisecond: 0.
-    self assert: ts = (self read: '20050101T0000+0200' withClass:Timestamp).
-
-    "
-        TimestampISO8601Builder new test_edge
-    "
-
-
-    "Created: / 16-06-2005 / 09:44:34 / masca"
-    "Modified: / 16-06-2005 / 11:48:59 / masca"
-!
-
-test_mustFail: aBlock
-
-    TimeConversionError
-        handle: [:ex | ex return]
-        do: [
-            aBlock value.
-            self error: 'Assertion failed'
-        ]
-
-    "Created: / 16-06-2005 / 09:43:37 / masca"
-!
-
-test_time
-
-    | ts |
-
-    ts := UtcTimestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 0.
-    self assert: ts = (self read: '2005-06-15 17:37' withClass:Timestamp).
-    self assert: ts = (self read: '20050615T1737' withClass:Timestamp).
-    self assert: ts = (self read: '05-0615T17:3700' withClass:Timestamp).
-
-    ts := UtcTimestamp  year: 2005 month: 6 day: 15 hour: 17 minute: 37 second: 0 millisecond: 30.
-    self assert: ts = (self read: '05-0615T17:3700.03' withClass:Timestamp).
-    self assert: ts = (self read: '2005-06-15T17:37:00.0305486-00:00' withClass:Timestamp).
-
-    "
-        TimestampISO8601Builder new test_time
-    "
-
-    "Created: / 15-06-2005 / 17:39:26 / masca"
-    "Modified: / 16-06-2005 / 11:54:30 / masca"
-!
-
-test_timezone
-
-    | ts |
-    ts := UtcTimestamp
-         year: 2005 month: 6 day: 15
-         hour: 17 minute: 37 second: 0 millisecond: 0.
-
-    self assert: ts = (self read: '2005-06-15T17:37Z' withClass:UtcTimestamp).
-    self assert: ts = (self read: '2005-06-15T17:37+0000' withClass:Timestamp).
-    self assert: ts = (self read: '2005-06-15T17:37-00:00' withClass:Timestamp).
-    self assert: ts = (self read: '2005-06-15T15:37:00-0200' withClass:Timestamp).
-    self assert: ts = (self read: '2005-06-15T19:37:00+0200'withClass:Timestamp).
-
-    "
-        TimestampISO8601Builder new test_timezone
-    "
-
-    "Created: / 15-06-2005 / 17:40:23 / masca"
-    "Modified: / 16-06-2005 / 10:17:57 / masca"
-! !
-
 !Timestamp::TimestampISO8601Builder methodsFor:'private-reading'!
 
 nextDigit
@@ -3308,7 +3170,7 @@
     peek := stream peekOrNil.
     peek ifNil: [^self].
 
-    year := peek = $-
+    year := ((peek == $-) or:[peek == $W])
         ifTrue: [
             "OK, got two digits. These are expected to be the year after 1970."
             read < 70
@@ -3335,11 +3197,11 @@
 !Timestamp class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.158 2014-11-05 20:27:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.159 2014-11-05 20:46:42 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.158 2014-11-05 20:27:34 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.159 2014-11-05 20:46:42 cg Exp $'
 ! !