[local-time-devel] Confused about encode-timestamp, offsets and timezones

Arjan Wekking arjan at streamtech.nl
Wed Jul 23 09:42:20 UTC 2008


While making some functions to get the ISO 8601 week number of a  
timestamp I encountered the following issue with encode-timestamp that  
rather confuses me:

CL-USER> (timestamp-day (universal-to-timestamp (encode-universal-time  
0 0 0 4 1 2010)))
4
CL-USER> (timestamp-day (encode-timestamp 0 0 0 0 4 1 2010))
3

CL-USER> (universal-to-timestamp (encode-universal-time 0 0 0 4 1 2010))
@2010-01-04T00:00:00.000000+01:00
CL-USER> (encode-timestamp 0 0 0 0 4 1 2010)
@2010-01-03T23:00:00.000000+01:00

CL-USER> (universal-to-timestamp (encode-universal-time 0 0 0 22 07  
2008))
@2008-07-22T00:00:00.000000+02:00
CL-USER> (encode-timestamp 0 0 0 0 22 07 2008)
@2008-07-22T00:00:00.000000+02:00

It looks like encode-timestamp should be using (timezone *default- 
timezone*) instead of (offset (%get-default-offset)) to build a  
timestamp from the date/time fields since the offset computed by %get- 
default-offset is incorrect for dates outside the current daylight  
savings time state but correct for those within (see the second  
example above where the encoded date is in the same DST state).

In general I think it would be better to not have the timezone  
'offset' as a concept in the public API at all (also prevents  
confusion with offset in adjust-timestamp) and deal exclusively with  
timezones and the *default-timezone*.

Perhaps I'm misunderstanding what encode-timestamp should be used for  
- I just wanted to create a timestamp for midnight Jan 4th of a given  
year (with the given or *default-timezone*) but currently I have to  
use universal-to-timestamp with encode-universal-time which is not  
very elegant.

I'll pop by on IRC as well - it might make communication easier on  
stuff like this.

-Arjan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3405 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/local-time-devel/attachments/20080723/dc3bf026/attachment.bin>


More information about the local-time-devel mailing list