Mantis - Squeak
Viewing Issue Advanced Details
7197 Kernel minor always 09-21-08 19:20 09-25-08 14:42
new 3.10.2  
0007197: DateAndTime readFrom: Results are About 2 Seconds Early.
'2008-08-28' asDateAndTime 2008-08-27T23:59:57.999999995+00:00
'2006-08-28T00:00' asDateAndTime 2006-08-27T23:59:57.999999995+00:00

It should produce 2008-08-28T00:00:00.0000000+00:00. I sampled several dates, all with similar results. I see that the testReadFrom test in the Kernel Tests fail.

I'll have a look at see if I can fix it.
 DateAndTime_readFrom_patch_M7197-nice.1.cs [^] (2,848 bytes) 09-22-08 21:16
 DateAndTime_readFrom_test_M7197-nice.1.cs [^] (1,329 bytes) 09-22-08 22:06
 DateAndTime_readFrom_patch_M7197-nice.2.cs [^] (2,870 bytes) 09-22-08 22:25
 DateAndTime_readFrom_test_M7197-nice.2.cs [^] (1,492 bytes) 09-22-08 22:25

nicolas cellier   
09-22-08 20:39   
I do not confirm this.
In a 3.10.2 basic image, i have a MNU bug because hour isNil.
fixing DataAndTime class>>#readFrom:code with
hour _ (aStream upTo: $:) asInteger ifNil: [0].

I get '2008-08-28' asDateAndTime 2008-08-28T00:00:00+00:00

What image are you using?
nicolas cellier   
09-22-08 20:47   
By the way, this one works:

'2006-08-28T00:00:00.123456789' asDateAndTime.

But extra picoseconds are just too much:

'2006-08-28T00:00:00.123456789000' asDateAndTime.

This is somewhat similar to 0006764
nicolas cellier   
09-22-08 21:09   
The picosecond behaviour is tricky:
  nanos _ WriteStream on: buffer.
  nanos _ buffer asInteger.

This will fill the 10 characters of buffer, then at 11th, the writeStream will write on a grown buffer copy...

initializing buffer to 9 digits fixes it:
buffer _ '000000000' copy.
nicolas cellier   
09-22-08 22:18   
I added two ifNil: [1] for month and day to be more in line with [^]

However, implementation lacks year day, week day, time only and some abbreviations...

And sure we can still fool it with malformed inputs.
09-25-08 14:42   
I found the problem. I had loaded Didier Besset's Numerical Analysis package from universes. It replaces asInteger with:

        "(c) Copyrights Didier BESSET, all rights reserved
         Initial code: 1/6/98 "
    ^self inject: 0
            into: [ :ans :each | (ans * 10) + each digitValue]

It naively assumes that all characters are valid digits. The asDateAndTime also places a plus sign into the conversion buffer. digitValue happily converts $+ to -5.

The original asInteger is coded as ^self asSignedInteger. It works fine when revert it. All Chronology Tests now pass. Hurray for unit tests and Test Runner. A lesson learned for me, I'll run unit test after every package load from now on!