[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] srfi-19 & DST
From: |
David N Murray |
Subject: |
[Chicken-users] srfi-19 & DST |
Date: |
Sun, 13 Sep 2009 01:24:35 -0400 (EDT) |
Hi Kon!
Under OpenBSD, I'm required to set the TZ environment variable:
address@hidden:~/tr/scheme$ csi
CHICKEN
(c)2008-2009 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.1.7
openbsd-unix-gnu-x86-64 [ 64bit manyargs dload ptables applyhook ]
compiled 2009-09-02 on kili.jsbsystems.com (OpenBSD)
#;1> (use locale)
[snip a bunch of ; loading msgs]
; loading /usr/local/lib/chicken/4/locale-current.so ...
Error: (set-timezone-component!) bad argument type - not a std-offset:
19316752
Call history:
<syntax> (##core#undefined)
<syntax> (##core#undefined)
<syntax> (import chicken scheme posix type-checks
type-errors locale-builtin locale-posix locale-components l......
<syntax> (##core#undefined)
<syntax> (##core#undefined)
<syntax> (##core#undefined)
<syntax> (##core#undefined)
<eval> (##sys#require (quote locale)) <--
So, I set it to the way I've set it in the past:
address@hidden:~/tr/scheme$ export TZ=EST5EDT
address@hidden:~/tr/scheme$ cat t.scm
(use srfi-19)
(print (current-date))
(print (date->string (current-date)))
(exit)
address@hidden:~/tr/scheme$ csi -q t.scm
#,(date 446000000 55 5 22 12 9 2009 -21600 EDT #t #f #f #f)
Sat Sep 12 22:05:55-0600 2009
address@hidden:~/tr/scheme$ date
Sun Sep 13 00:05:59 EDT 2009
According to http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
"The offset specifies the time value you must add to the local time to
get a Coordinated Universal Time value. It has syntax like
[+|-]hh[:mm[:ss]]. This is positive if the local time zone is west of
the Prime Meridian and negative if it is east. The hour must be between
0 and 23, and the minute and seconds between 0 and 59.
For example, here is
how we would specify
Eastern Standard Time, but without any Daylight Saving Time alternative:
EST+5
The second format is used when there is Daylight Saving Time:
std offset dst [offset],start[/time],end[/time]
The initial std and offset specify the standard time zone, as described
above. The dst string and offset specify the name and offset for the
corresponding Daylight Saving Time zone; if the offset is omitted, it
defaults to one hour ahead of standard time."
Looking at locale-posix.scm, I find:
(let* ((o-m (next-match offset-re))
(off (if o-m (hms->offset (cadr o-m) (cddr
o-m))
;XXX What does "ahead" mean?
(+ (timezone-component-ref tz
'std-offset) SEC/HR) ) ) )
(set-timezone-component! tz 'dst-name (cadr n-m))
(set-timezone-component! tz 'dst-offset off)
I think the problem arises because timezone-component-ref returns a
positive number at this point, and at some point along the way, the sign
gets changed (I snipped all the ;loading messages):
#;1> (use locale)
#;2> (current-timezone-components)
((tag . timezone) (name . "EST5EDT") (source "POSIX" "TZ") (std-name .
"EST") (std-offset . 18000) (dst-name . "EDT") (dst-offset . 21600) (dst?
. #t))
#;3> (use srfi-19)
#;4> (current-date)
#,(date 329000000 52 19 23 12 9 2009 -21600 EDT #t #f #f #f)
#;5>
If the timezone component were negative prior to the add, then everything
would be fine. I also notice that you can't just flip the above + to a -,
because then that breaks everything east of Greenwich (unless
timezone-component returns a negative number for them, that is later
converted to positive when stored in a date object).
My workaround is:
$ set TZ=EST5EDT4
But, I'm also curious why the TZ environment variable is required. My
OpenBSD system knows what timezone I'm in:
address@hidden:~/tr/scheme$ ls -l /etc/localtime
lrwxr-xr-x 1 root wheel 30 May 17 2007 /etc/localtime -> \
/usr/share/zoneinfo/US/Eastern
TIA,
Dave
- [Chicken-users] srfi-19 & DST,
David N Murray <=