[squeak-dev] Re: Time now print24
David T. Lewis
lewis at mail.msen.com
Sat Jul 9 02:42:08 UTC 2016
On Thu, Jul 07, 2016 at 10:49:10PM -0700, Eliot Miranda wrote:
> Hi All,
> > On Jul 7, 2016, at 9:33 AM, Eliot Miranda <eliot.miranda at gmail.com> wrote:
> > Hi All,
> > how does one produce a nice timestamp, simply date and time as in
> > 7/7/2016 09:19:38
> > Trivial, right?
> > So
> > Date today mmddyyyy, ' ', Time now print24 '7/7/2016 09:22:40.914'
> > .914, ah, nanos. How useful. Let's get rid of them. No nanos: accessor so
> > Date today mmddyyyy, ' ', (Time now nanos: 0) print24 => MNU
> > but there's a seconds accessor, so
> > Date today mmddyyyy, ' ', (Time now seconds: Time now seconds; print24) '7/7/2016 00:00:41
> > ?? So seconds: is private, and isn't the dual of Time seconds:
> > Time seconds
> > ^ self second
> > Time second
> > ^ self asDuration seconds
> > Duration seconds
> > "Answer the number of seconds the receiver represents."
> > ^seconds rem: SecondsInMinute
> > Looks broken to me.
> Let me be more explicit, and ask for permission to fix this. One basic bug is the asymmetry between seconds, an accessor that answers seconds mod 60, and seconds: that doesn't set seconds mod 60. But seconds: is private and could be replaced by eg setTotalSeconds:, presumably without breaking clients, allowing seconds: to be redefined to do the right thing.
Yes please fix it.
It is clearly wrong to have #seconds and #seconds: refer to two different
things. And since #seconds: is private, that would be the thing to change.
Changing it to #setTotalSeconds: would be good, although I note that there
is a #asSeconds method too, so maybe #setSeconds: might match better with
#asSeconds. But either would be fine, and yes please, go ahead and fix it.
> I note that the historic bug of changing the semantics of Time now to answer something with finer resolution than one second could have been avoided by adding eg exactlyNow or preciselyNow.
I'm not sure it is a bug, more like a difference in presentation versus
internal representation. I think that #now should mean "now", not "now
rounded to the nearest second". But if I display the time now, I probably
would prefer it to be displayed to the nearest second.
> The problem with nanos (apart from the horrible abbreviation) is that it presumes a maximum precision that isn't well chosen. Microseconds work out much better. And I hope we change the internal representation accordingly. But there needs to be done accessor that rounds to the nearest second without revealing the internal precision. Time now toTheNearestSecond or Time theNearestSecondNow or...?
Absolutely right. In the UTCDateAndTime changes, the magnitude of DateAndTime
is utcMicroseconds for exactly this reason. That does not preclude nanosecond
precision, it just means that the common case of microsecond precision uses
an integer, and higher precisions are represented as Fraction. So the common
case is fast, and higher precision remains possible.
Somewhat more generally, the scale is in units of seconds. Precision should
be unlimited (any Number) and accuracy is dependent on the underlying system
clock (milliseconds or maybe microseconds if you are lucky). Most everyday
computers may be accurate to milliseconds but report precision to microseconds.
Specialized real time systems (e.g. GPS) may legitimately deal with higher
accuracies and are probably not lying if they claim nanosecond precision.
Human beings may drift a few hours one way or the other without noticing
the difference, and are thus generally satisfied with full second precision
and not much accuracy at all ;-)
> > Personally I think print24 should not print sub seconds.
> > cc'ing to Pharo because I want this timestamp to be the same in both dialects for a profiling tool we want to use in both dialects.
> > _,,,^..^,,,_
> > best, Eliot
More information about the Squeak-dev