TimeStamp class>>date:time:

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

TimeStamp class>>date:time:

Dmitry Zamotkin-3
Hello,

I suppose default behaiviour of TimeStamp class>>date:time: method is
incorrect for time parameter greater or equal 24 hours.

Try to evaluate:
time := Time fromSeconds: ##(24*3600 + 1). "00:00:01"
date := Date today.

badTs := TimeStamp date: date time: time.
toCompareTs := TimeStamp fromSeconds: badTs asSeconds.
badTs = toCompareTs "false"


To fix it I suggest to change dependencies between two TimeStamp
constructors.

TimeStamp class>>date: aDate time: aTime
  ^self fromSeconds: aDate asSeconds + aTime asSeconds

TimeStamp class>>fromSeconds: anInteger
 | date |
 date := Date fromSeconds: anInteger.
 ^self new
  date: date;
  time: (Time fromSeconds: anInteger - date asSeconds);
  yourself

Your thoughts?
--
Dmitry Zamotkin


Reply | Threaded
Open this post in threaded view
|

Re: TimeStamp class>>date:time:

Dmitry Zamotkin-3
Hello again,

"Dmitry Zamotkin" <[hidden email]> wrote in message
news:9stpt9$ppd$[hidden email]...
> Hello,
>
> I suppose default behaiviour of TimeStamp class>>date:time: method is
> incorrect for time parameter greater or equal 24 hours.

I wonder what the silence means:
1. I'm truly right or
2. It's a silly idea that Time instance can be greater then 24 hours.

Thanks,
Dmitry


Reply | Threaded
Open this post in threaded view
|

Re: TimeStamp class>>date:time:

Ian Bartholomew-5
In reply to this post by Dmitry Zamotkin-3
Dmitry

> I suppose default behaiviour of TimeStamp class>>date:time: method is
> incorrect for time parameter greater or equal 24 hours.

> Your thoughts?

I'd tend to go the other way. The Time class can represent an arbitrary Time
interval or a "Time of Day" so there are no limits that can be put on it.
TimeStamp, on the other hand, represents a particular moment in time,
measured using a Date and Time. Time values of 24 hours and over are not
valid in this - they don't exist, so I would probably prefer

TimeStamp date: aDate time: aTime
    self assert: [aTime asSeconds between: 0 and: ##(24 * 60 * 60 - 1)].
    &etc

If I did want to use it for "non standard" purposes then I would probably
use the #asSeconds constructor anyway.

Having said that, the ANSI DateAndTime and Duration classes are probably the
way to go now and DateAndTime won't let you set a Time over 23:59:59.

Regards
    Ian