We have DateAndTime and TimeStamp, which are generally useful objects with lots
of features.
But for a lot of applications, they are too heavy. In server side code,
timestamps are almost always in UTC (timezone zero). In most cases, nanosecond
or millisecond precision are not (really) needed. Unix/Posix time has only
second precision.
I wrote ZTimestamp as an alternative for DateAndTime and TimeStamp.
It has second precision and lives in the UTC/GMT/Zulu timezone.
It uses ISO/International conventions and protocols only.
ZTimestamp is more efficient: it uses half the memory of DateAndTime and is
faster.
You can find it in
http://mc.stfx.eu/Neo
ConfigurationOfZTimestamp is also available from
http://www.squeaksource.com/MetacelloRepository
http://squeaksource.com/MetaRepoForPharo14
http://ss3.gemstone.com/ss/MetaRepoForPharo20
Here are some benchmarks:
[ 1000 timesRepeat: [ ZTimestamp now ] ] bench '1,910 per second.'
[ 1000 timesRepeat: [ DateAndTime now ] ] bench '253 per second.'
[ 1000 timesRepeat: [ ZTimestamp fromString: '2012-06-18T07:51:40Z' ] ] bench
'161 per second.'
[ 1000 timesRepeat: [ DateAndTime fromString: '2012-06-18T07:51:40Z' ] ] bench
'44.9 per second.'
[ 1000 timesRepeat: [ ZTimestamp now printString ] ] bench '212 per second.'
[ 1000 timesRepeat: [ DateAndTime now printString ] ] bench '82.3 per second.'
[ 1000 timesRepeat: [ TimeStamp now printString ] ] bench '54.2 per second.'
[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) = (ZTimestamp
fromUnixTime: 2540006939) ] ] bench '377 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) = (DateAndTime
fromUnixTime: 2540006939) ] ] bench '142 per second.'
[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) < (ZTimestamp
fromUnixTime: 2540006939) ] ] bench '376 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) < (DateAndTime
fromUnixTime: 2540006939) ] ] bench '134 per second.'
[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) + 10 days ] ] bench
'604 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) + 10 days ] ]
bench '142 per second.'
[ 1000 timesRepeat: [ (ZTimestamp fromUnixTime: 1340006939) - (ZTimestamp
fromUnixTime: 2540006939) ] ] bench '239 per second.'
[ 1000 timesRepeat: [ (DateAndTime fromUnixTime: 1340006939) - (DateAndTime
fromUnixTime: 2540006939) ] ] bench '98.8 per second.'
[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) = (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '2,040 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) = (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '1,800 per second.'
[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) < (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '2,220 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) < (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '1,050 per second.'
[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) + 10 days ] ] bench '1,970 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) + 10 days ] ] bench '245 per second.'
[ 1000 timesRepeat: [ (ZTimestamp year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) - (ZTimestamp year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '1,440 per second.'
[ 1000 timesRepeat: [ (DateAndTime year: 2012 month: 7 day: 1 hour: 8 minute: 8
second: 8) - (DateAndTime year: 2011 month: 5 day: 2 hour: 4 minute: 4 second:
4) ] ] bench '767 per second.'
ZTimestamp is *not* meant as a general replacement for DateAndTime or
TimeStamp. But in a lot of cases, it can be more efficient.
Feedback and users are welcome.
Sven
--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill