--- a/Timestamp.st Tue Aug 17 17:31:59 2004 +0200
+++ b/Timestamp.st Thu Aug 19 17:08:19 2004 +0200
@@ -479,7 +479,8 @@
yearOrNil notNil ifTrue:[
year := yearOrNil
] ifFalse:[
- year := Integer readFrom:str.
+ year := Integer readFrom:str onError:nil.
+ year isNil ifTrue:[ ConversionError raiseErrorString:'bad year' ]
].
str skipSeparators.
@@ -525,8 +526,8 @@
str peek == $. ifTrue:[
str next.
"/ millis follow.
- fraction := Number readMantissaFrom:str radix:10.
- millis := 1000 * fraction rounded. "/ mhmh - should it be truncated ?
+ fraction := Number readMantissaFrom:str radix:10.
+ millis := (1000 * fraction) rounded. "/ mhmh - should it be truncated ?
]
].
].
@@ -542,6 +543,7 @@
hour:hour minute:min second:sec millisecond:millis.
"
+ Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06.123'
Timestamp readIso8601FormatFrom:'1995-02-20T13:11:06'
Timestamp readIso8601FormatFrom:'1995-02T13:11:06'
Timestamp readIso8601FormatFrom:'1995T13:11:06'
@@ -1061,6 +1063,34 @@
"Modified: / 17.1.2000 / 15:53:02 / stefan"
!
+printIso8601FormatOn:aStream
+ "append the iso8601 UTC representation of the receiver to aStream.
+ This format looks like:
+ 1999-01-01T24:00:00
+ or, for zero hr:min:sec,
+ 1999-01-01
+ Of course, a 24 hour clock is used."
+
+ |format|
+
+ format := '%(year)-%(month)-%(day)T%h:%m:%s.%i'.
+ self milliseconds = 0 ifTrue:[
+ format := '%(year)-%(month)-%(day)T%h:%m:%s'.
+ self seconds = 0 ifTrue:[
+ format := '%(year)-%(month)-%(day)T%h:%m'.
+ ((self hours = 0) and:[self minutes = 0]) ifTrue:[
+ format := '%(year)-%(month)-%(day)'.
+ ]
+ ]
+ ].
+ self printOn:aStream format:format
+
+ "
+ Timestamp now printIso8601FormatOn:Transcript
+ Timestamp readIso8601FormatFrom:(Timestamp now printStringIso8601Format).
+ "
+!
+
printOn:aStream
"append a user readable representation of the receiver to aStream.
The format is compatible with readFromString:, but not with readFrom:."
@@ -1150,6 +1180,21 @@
"
!
+printStringIso8601Format
+ "return the Iso8601 representation of the receiver.
+ This format looks like:
+ 1999-01-01T24:00:00
+ or, for zero hr:min:sec,
+ 1999-01-01
+ Of course, a 24 hour clock is used."
+
+ ^ String streamContents:[:s | self printIso8601FormatOn:s]
+
+ "
+ Timestamp now printStringIso8601Format
+ "
+!
+
printStringRFC1123Format
"return the RFC1123 representation of the receiver.
This format is used in HTTP requests and looks like:
@@ -1245,7 +1290,7 @@
!Timestamp class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.96 2004-07-06 11:43:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Timestamp.st,v 1.97 2004-08-19 15:08:19 cg Exp $'
! !
Timestamp initialize!