Hi all, I probably should make an issue out of this, and follow the workflow, but I found a bug in the DateAndTime class in the method readFrom: This method comes in an infinite loop, if there is only a date specified: it tried to do aStream next while aStream peek is not a digit. And since aStream peek returns nil when the stream is at the end, this will result in an infinite loop. Here is the fixed method. Cheers, Diego readFrom: aStream "Parse and return a new DateAndTime instance from stream, as a Date, a Time and a TimeZone offset." "self readFrom: ' 2013-03-04T23:47:52.876+01:00' readStream" | offset date time | date := Date readFrom: aStream. [ aStream peek isDigit or: [ aStream atEnd ] ] whileFalse: [ aStream next ]. aStream atEnd ifTrue: [ time := Time midnight ] ifFalse: [ time := Time readFrom: aStream ]. aStream skipSeparators. offset := self readTimezoneOffsetFrom: aStream. ^ self year: date year month: date monthIndex day: date dayOfMonth hour: time hour minute: time minute second: time second nanoSecond: time nanoSecond offset: offset " '-1199-01-05T20:33:14.321-05:00' asDateAndTime ' 2002-05-16T17:20:45.1+01:01' asDateAndTime ' 2002-05-16T17:20:45.02+01:01' asDateAndTime ' 2002-05-16T17:20:45.003+01:01' asDateAndTime ' 2002-05-16T17:20:45.0004+01:01' asDateAndTime ' 2002-05-16T17:20:45.00005' asDateAndTime ' 2002-05-16T17:20:45.000006+01:01' asDateAndTime ' 2002-05-16T17:20:45.0000007+01:01' asDateAndTime ' 2002-05-16T17:20:45.00000008-01:01' asDateAndTime ' 2002-05-16T17:20:45.000000009+01:01' asDateAndTime ' 2002-05-16T17:20:45.0000000001+01:01' asDateAndTime ' 2002-05-16T17:20' asDateAndTime ' 2002-05-16T17:20:45' asDateAndTime ' 2002-05-16T17:20:45+01:57' asDateAndTime ' 2002-05-16T17:20:45-02:34' asDateAndTime ' 2002-05-16T17:20:45+00:00' asDateAndTime ' 1997-04-26T01:02:03+01:02:3' asDateAndTime "
Thanks for the report. Yes, an issue, a unit test and a slice to fix it would be cool ;-) BTW, what do you propose: throw an error or use a zero time ? On 19 Feb 2014, at 10:27, Diego Lont <diego.lont@delware.nl> wrote:
Hi all,
I probably should make an issue out of this, and follow the workflow, but I found a bug in the DateAndTime class in the method readFrom:
This method comes in an infinite loop, if there is only a date specified: it tried to do aStream next while aStream peek is not a digit. And since aStream peek returns nil when the stream is at the end, this will result in an infinite loop. Here is the fixed method.
Cheers, Diego
readFrom: aStream "Parse and return a new DateAndTime instance from stream, as a Date, a Time and a TimeZone offset." "self readFrom: ' 2013-03-04T23:47:52.876+01:00' readStream"
| offset date time | date := Date readFrom: aStream. [ aStream peek isDigit or: [ aStream atEnd ] ] whileFalse: [ aStream next ]. aStream atEnd ifTrue: [ time := Time midnight ] ifFalse: [ time := Time readFrom: aStream ]. aStream skipSeparators. offset := self readTimezoneOffsetFrom: aStream. ^ self year: date year month: date monthIndex day: date dayOfMonth hour: time hour minute: time minute second: time second nanoSecond: time nanoSecond offset: offset
" '-1199-01-05T20:33:14.321-05:00' asDateAndTime ' 2002-05-16T17:20:45.1+01:01' asDateAndTime
' 2002-05-16T17:20:45.02+01:01' asDateAndTime
' 2002-05-16T17:20:45.003+01:01' asDateAndTime
' 2002-05-16T17:20:45.0004+01:01' asDateAndTime ' 2002-05-16T17:20:45.00005' asDateAndTime ' 2002-05-16T17:20:45.000006+01:01' asDateAndTime
' 2002-05-16T17:20:45.0000007+01:01' asDateAndTime ' 2002-05-16T17:20:45.00000008-01:01' asDateAndTime ' 2002-05-16T17:20:45.000000009+01:01' asDateAndTime ' 2002-05-16T17:20:45.0000000001+01:01' asDateAndTime
' 2002-05-16T17:20' asDateAndTime ' 2002-05-16T17:20:45' asDateAndTime ' 2002-05-16T17:20:45+01:57' asDateAndTime ' 2002-05-16T17:20:45-02:34' asDateAndTime ' 2002-05-16T17:20:45+00:00' asDateAndTime ' 1997-04-26T01:02:03+01:02:3' asDateAndTime "
I think a zero time would be best, as I did so in my proposed fix.
Thanks for the report.
Yes, an issue, a unit test and a slice to fix it would be cool ;-)
BTW, what do you propose: throw an error or use a zero time ?
On 19 Feb 2014, at 10:27, Diego Lont <diego.lont@delware.nl> wrote:
Hi all,
I probably should make an issue out of this, and follow the workflow, but I found a bug in the DateAndTime class in the method readFrom:
This method comes in an infinite loop, if there is only a date specified: it tried to do aStream next while aStream peek is not a digit. And since aStream peek returns nil when the stream is at the end, this will result in an infinite loop. Here is the fixed method.
Cheers, Diego
readFrom: aStream "Parse and return a new DateAndTime instance from stream, as a Date, a Time and a TimeZone offset." "self readFrom: ' 2013-03-04T23:47:52.876+01:00' readStream"
| offset date time | date := Date readFrom: aStream. [ aStream peek isDigit or: [ aStream atEnd ] ] whileFalse: [ aStream next ]. aStream atEnd ifTrue: [ time := Time midnight ] ifFalse: [ time := Time readFrom: aStream ]. aStream skipSeparators. offset := self readTimezoneOffsetFrom: aStream. ^ self year: date year month: date monthIndex day: date dayOfMonth hour: time hour minute: time minute second: time second nanoSecond: time nanoSecond offset: offset
" '-1199-01-05T20:33:14.321-05:00' asDateAndTime ' 2002-05-16T17:20:45.1+01:01' asDateAndTime
' 2002-05-16T17:20:45.02+01:01' asDateAndTime
' 2002-05-16T17:20:45.003+01:01' asDateAndTime
' 2002-05-16T17:20:45.0004+01:01' asDateAndTime ' 2002-05-16T17:20:45.00005' asDateAndTime ' 2002-05-16T17:20:45.000006+01:01' asDateAndTime
' 2002-05-16T17:20:45.0000007+01:01' asDateAndTime ' 2002-05-16T17:20:45.00000008-01:01' asDateAndTime ' 2002-05-16T17:20:45.000000009+01:01' asDateAndTime ' 2002-05-16T17:20:45.0000000001+01:01' asDateAndTime
' 2002-05-16T17:20' asDateAndTime ' 2002-05-16T17:20:45' asDateAndTime ' 2002-05-16T17:20:45+01:57' asDateAndTime ' 2002-05-16T17:20:45-02:34' asDateAndTime ' 2002-05-16T17:20:45+00:00' asDateAndTime ' 1997-04-26T01:02:03+01:02:3' asDateAndTime "
https://pharo.fogbugz.com/f/cases/12923/DateAndTime-gets-into-infinite-loop-... fix/slice submitted. On 19 Feb 2014, at 15:21, Diego Lont <diego.lont@delware.nl> wrote:
I think a zero time would be best, as I did so in my proposed fix.
Thanks for the report.
Yes, an issue, a unit test and a slice to fix it would be cool ;-)
BTW, what do you propose: throw an error or use a zero time ?
On 19 Feb 2014, at 10:27, Diego Lont <diego.lont@delware.nl> wrote:
Hi all,
I probably should make an issue out of this, and follow the workflow, but I found a bug in the DateAndTime class in the method readFrom:
This method comes in an infinite loop, if there is only a date specified: it tried to do aStream next while aStream peek is not a digit. And since aStream peek returns nil when the stream is at the end, this will result in an infinite loop. Here is the fixed method.
Cheers, Diego
readFrom: aStream "Parse and return a new DateAndTime instance from stream, as a Date, a Time and a TimeZone offset." "self readFrom: ' 2013-03-04T23:47:52.876+01:00' readStream"
| offset date time | date := Date readFrom: aStream. [ aStream peek isDigit or: [ aStream atEnd ] ] whileFalse: [ aStream next ]. aStream atEnd ifTrue: [ time := Time midnight ] ifFalse: [ time := Time readFrom: aStream ]. aStream skipSeparators. offset := self readTimezoneOffsetFrom: aStream. ^ self year: date year month: date monthIndex day: date dayOfMonth hour: time hour minute: time minute second: time second nanoSecond: time nanoSecond offset: offset
" '-1199-01-05T20:33:14.321-05:00' asDateAndTime ' 2002-05-16T17:20:45.1+01:01' asDateAndTime
' 2002-05-16T17:20:45.02+01:01' asDateAndTime
' 2002-05-16T17:20:45.003+01:01' asDateAndTime
' 2002-05-16T17:20:45.0004+01:01' asDateAndTime ' 2002-05-16T17:20:45.00005' asDateAndTime ' 2002-05-16T17:20:45.000006+01:01' asDateAndTime
' 2002-05-16T17:20:45.0000007+01:01' asDateAndTime ' 2002-05-16T17:20:45.00000008-01:01' asDateAndTime ' 2002-05-16T17:20:45.000000009+01:01' asDateAndTime ' 2002-05-16T17:20:45.0000000001+01:01' asDateAndTime
' 2002-05-16T17:20' asDateAndTime ' 2002-05-16T17:20:45' asDateAndTime ' 2002-05-16T17:20:45+01:57' asDateAndTime ' 2002-05-16T17:20:45-02:34' asDateAndTime ' 2002-05-16T17:20:45+00:00' asDateAndTime ' 1997-04-26T01:02:03+01:02:3' asDateAndTime "
participants (2)
-
Diego Lont -
Sven Van Caekenberghe