Yes, I just can't understand all this code ;-) The nanoseconds seemed overly ambitious to me. That was one of the reasons I am using my own ZTimestamp (loadable from the Configuration browser), together with the confusion coming from timezones (they are not needed internally, only for representations). If you keep the julianDayNumber, you can fit millisecond precision in a small integer as milliSecondsSinceMidnight. 60 * 60 * 24 * 1000 < SmallInteger maxVal Ideally, there should be one Timestamp interface with multiple implementations of different precisions, mixed transparently. One should only pay the price (space or time) for extra features when they are really needed. On 04 Feb 2013, at 16:18, Igor Stasenko <siguctua@gmail.com> wrote:
Hi, i am maybe completely ignorant, but can someone tell me where such precision is used?
In order to achieve this (or well, get close to), a current implementation goes into very long circles to squeeze accuracy from underlying OS & primitives.. just take a look at this code and tell me what you think:
secondsWhenClockTicks
"waits for the moment when a new second begins"
| lastSecond delay |
delay := Delay forMilliseconds: 1. lastSecond := self primSecondsClock. [ lastSecond = self primSecondsClock ] whileTrue: [ delay wait ].
^ lastSecond + 1
initializeOffsets | durationSinceEpoch secondsSinceMidnight nowSecs | LastTick := 0. nowSecs := self clock secondsWhenClockTicks. LastMilliSeconds := self millisecondClockValue. durationSinceEpoch := Duration days: SqueakEpoch hours: 0 minutes: 0 seconds: nowSecs. DaysSinceEpoch := durationSinceEpoch days. secondsSinceMidnight := (durationSinceEpoch - (Duration days: DaysSinceEpoch hours: 0 minutes: 0 seconds: 0)) asSeconds. MilliSecondOffset := secondsSinceMidnight * 1000 - LastMilliSeconds
what amuses me is then the way how TimeStamp class dealing with it to actually throw away extra precision:
TimeStamp >> current "called by #now"
| ts ticks | ts := super now.
ticks := ts ticks. ticks at: 3 put: 0. ts ticks: ticks offset: ts offset.
^ ts
DateAndTime>>ticks "Private - answer an array with our instance variables. Assumed to be UTC "
^ Array with: julianDayNumber with: seconds with: nanos.
if it is not obvious for someone, the right way to reset the nanoseconds field in timestamp is not sending a message to existing timestamp, say #resetNanoseconds, NO! you should call a private method, which answers you an Array and then you do "at:3 put: 0", and then pass it again to same object as two arguments.
-- Best regards, Igor Stasenko.