DateAndTime question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

DateAndTime question

Chris Double-2
I have a question about the DateAndTime and Duration classes available
from Ian's web site. The questions relate to the following workspace
session:

1) a := DateAndTime now.
2) a  (=> 2001-11-10T00:45:39.29+13:00)
3) b := DateAndTime now.
4) b  (=> 2001-11-10T00:46:07.31+13:00)
5) a  (=> 2001-11-10T00:46:07.31+13:00)
6) a asSeconds (=> 6314103633929/100)
7) b asSeconds (=> 6314103636731/100)

In line 1 I set a to the current date/time. It prints out correctly in
line 2. In line 3 and 4 I do the same for b. (=> is the result of
Ctrl+D).

Note that line 5, I redo the printing of the value of a and it now
displays the same as b. But looking at lines 6 and 7 you can see they
have a different seconds value.

The same problem occurs reading values line 'a minute', 'b minute',
etc. They are always the same as each other even though the times are
actually different as noted by 'asSeconds'.

Looking at the source it seems that the results of 'hour', 'minute',
etc are cached in some class slots making them the same for all
instances. You always get the value of the last DateAndTime instance
created. Is this the correct behaviour?

As a workaround I'm just using the 'asSeconds' method.

Chris.
--
http://www.double.co.nz/smalltalk


Reply | Threaded
Open this post in threaded view
|

Re: DateAndTime question

Ian Bartholomew-5
Chris,

> Looking at the source it seems that the results of 'hour', 'minute',
> etc are cached in some class slots making them the same for all
> instances. You always get the value of the last DateAndTime instance
> created. Is this the correct behaviour?

Hear that thumping sound? - it's my head hitting the table. Talk about
elementary mistakes!!

In the method DateAndTime>>decodeRataDie

replace the second line -

fieldValues := #(0 0 0 0 0 0 0).

with -

fieldValues := Array new: 7.

and all should be well. Thanks for the report and sorry for the incorrect
code.

Suggestions of a suitable penance, probably involving whips and/or hair
shirts, are welcomed <g>

Regards
    Ian


Reply | Threaded
Open this post in threaded view
|

Re: DateAndTime question

Chris Double-2
"Ian Bartholomew" <[hidden email]> writes:

> Thanks for the report and sorry for the incorrect code.

No problem, thanks for the fix it worked fine. And thanks for making
the code available in the first place!

Cheers,
Chris.


Reply | Threaded
Open this post in threaded view
|

Re: DateAndTime question

Bill Schwab-2
In reply to this post by Ian Bartholomew-5
Ian,

> Suggestions of a suitable penance, probably involving whips and/or hair
> shirts, are welcomed <g>

You are hereby sentenced to rewrite the code in Java - how's that for
punishment :)   However, the sentence is suspended in honor of your service
to the Smalltalk community.

Thanks!

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]