diff --git a/kernel/AnsiDates.st b/kernel/AnsiDates.st index f04b9c8..a170291 100644 --- a/kernel/AnsiDates.st +++ b/kernel/AnsiDates.st @@ -111,7 +111,18 @@ Date subclass: DateTime [ "Parse an instance of the receiver from aStream" - ^(super readFrom: aStream) + (Duration readFrom: aStream) + | date time ofs ch | + date := super readFrom: aStream. + (aStream peekFor: $T) ifFalse: [aStream skipSeparators]. + time := aStream peek isDigit + ifTrue: [Duration readFrom: aStream] + ifFalse: [Duration zero]. + aStream skipSeparators. + ch := aStream peek. + (ch = $+ or: [ch = $-]) ifFalse: [^date + time]. + aStream next. + ofs := Duration readFrom: aStream. + ^(date + time) setOffset: ofs ] DateTime class >> today [ @@ -584,25 +595,26 @@ Time subclass: Duration [ aStream" - | t1 t2 t3 t4 i ch ws | - t1 := t2 := t3 := t4 := 0. - ch := $:. + | sign sec hms i ch ws | + hms := {0. 0. 0}. + sign := (aStream peekFor: $-) ifTrue: [-1] ifFalse: [1]. i := 1. - [i <= 4 and: [(aStream atEnd not and: [ch isSeparator not]) or: [i < 4]]] whileTrue: [ + ch := $:. + [i <= 4 and: [aStream atEnd not and: [ch isSeparator not]]] whileTrue: [ ws := WriteStream on: (String new: 10). - - ch := $:. - [aStream atEnd not and: [(ch := aStream next) isDigit not]] whileTrue. - ch isDigit ifTrue: [ - [ws nextPut: ch. - aStream atEnd not and: [(ch := aStream next) isDigit]] - whileTrue]. - t1 := t2. - t2 := t3. - t3 := t4. - t4 := ws contents asNumber. + [aStream atEnd not and: [(ch := aStream next) isDigit]] + whileTrue: [ws nextPut: ch]. + i = 4 + ifTrue: [ + hms := { + (hms at: 1) * 24 + (hms at: 2). + hms at: 3. + ws contents asNumber}] + ifFalse: [ + hms at: i put: ws contents asNumber]. i := i + 1]. - ^self fromSeconds: (t1 * 24 + t2) * 3600 + (t3 * 60) + t4 + sec := ((hms at: 1) * 3600 + ((hms at: 2) * 60) + (hms at: 3)) * sign. + ^self fromSeconds: sec ] Duration class >> initialize [ diff --git a/kernel/Date.st b/kernel/Date.st index fb961b7..3751d79 100644 --- a/kernel/Date.st +++ b/kernel/Date.st @@ -255,12 +255,16 @@ method.'> ws := WriteStream on: (String new: 10). [aStream atEnd not and: [(ch := aStream next) isAlphaNumeric not]] whileTrue. - ch isAlphaNumeric + ch isLetter ifTrue: - [ - [ws nextPut: ch. - aStream atEnd not and: [(ch := aStream next) isAlphaNumeric]] - whileTrue]. + [[ws nextPut: ch. + aStream atEnd not and: [(ch := aStream next) isLetter]] + whileTrue] + ifFalse: [ + ch isDigit ifTrue: + [[ws nextPut: ch. + aStream atEnd not and: [(ch := aStream next) isDigit]] + whileTrue]]. t1 := t2. t2 := t3. t3 := ws contents. diff --git a/kernel/Time.st b/kernel/Time.st index d3810e7..99289d3 100644 --- a/kernel/Time.st +++ b/kernel/Time.st @@ -245,26 +245,17 @@ time value, and a block execution timing facility.'> aStream" - | t1 t2 t3 ch ws | - t1 := t2 := t3 := 0. - ch := $:. - 3 timesRepeat: - [t1 := t2. - t2 := t3. - t3 := 0. - ch isSeparator - ifFalse: - [ws := WriteStream on: (String new: 10). - ch := $:. - [aStream atEnd not and: [(ch := aStream next) isDigit not]] whileTrue. - ch isDigit - ifTrue: - [ - [ws nextPut: ch. - aStream atEnd not and: [(ch := aStream next) isDigit]] - whileTrue]. - t3 := ws contents asNumber]]. - ^self fromSeconds: t1 * 3600 + (t2 * 60) + t3 + | hms i ch ws | + hms := {0. 0. 0}. + i := 1. + ch := $:. + [i <= 3 and: [aStream atEnd not and: [ch isSeparator not]]] whileTrue: [ + ws := WriteStream on: (String new: 10). + [aStream atEnd not and: [(ch := aStream next) isDigit]] + whileTrue: [ws nextPut: ch]. + hms at: i put: ws contents asNumber. + i := i + 1]. + ^self fromSeconds: (hms at: 1) * 3600 + ((hms at: 2) * 60) + (hms at: 3) ] Time class >> millisecondClockValue [