From: Will Fitzgerald
Subject: time zones, daylight saving time, and universal time
Date: 
Message-ID: <661755b5.0203291052.78c9d702@posting.google.com>
This is more a note to myself than anything else.

Universal time represents the number of seconds since the Common Lisp
epoch (defined at 1970-01-01 00:00:00Z (midnight, UTC).

DECODE-UNIVERSAL-TIME and ENCODE-UNIVERSAL-TIME take an optional time
zone argument. A time zone is defined to be the number of hours (more
precisely, a "rational multiple of 1/3600 between 24 (inclusive) and
-24 (inclusive)"). Unlike most (every other?) programming language,
this is positive going west from UTC and negative going east. Thus,
for example, the time zone of Massachusetts is always 5.

If a time zone is not supplied to DECODE-UNIVERSAL-TIME or
ENCODE-UNIVERSAL-TIME, Common Lisp makes some assumptions, and some of
them are implementation specific. For example, the Hyperspec says, for
DECODE-UNIVERSAL-TIME: "If time-zone is not supplied, it defaults to
the current time zone adjusted for daylight saving time." I *think*
this means that the time zone is the (constant) time zone reported by
the machine (see function below) and whether or not daylight saving is
being observed in the machine's location then. No discussion of what
ENCODE-UNIVERSAL-TIME assumes is provided.

In any case, *supplying* a time zone is always safe, and turns off any
guesses about daylight saving time (very
implementation/location/operating system dependent), and this is
probably Good Programming Hygiene.


--
I *think* this should always return the local time zone, and always
return the same value whether or not daylight saving time is being
observed:

(defun current-time-zone ()
  (multiple-value-bind (s m h d m y dd dp zone) (get-decoded-time)
    (declare (ignore s m h d m y dd dp))
    zone))


And this should return whether the implementation thinks DST is being
observed at this universal time:

(defun dst-observed-p (universal-time)
 (multiple-value-bind (s m h d m y dd daylight-p) 
  (decode-universal-time universal-time)
    (declare (ignore s m h d m y dd))
    daylight-p))

From: Will Fitzgerald
Subject: Re: time zones, daylight saving time, and universal time
Date: 
Message-ID: <661755b5.0204010512.78a9a944@posting.google.com>
··········@inetmi.com (Will Fitzgerald) wrote in message news:<····························@posting.google.com>...
> This is more a note to myself than anything else.
> 

And I should have kept it a note to myself, given its inaccuracies.
Here's an update with corrections.

Universal time represents the number of seconds since the Common Lisp
epoch (defined at 1900-01-01 00:00:00Z (midnight, UTC).

DECODE-UNIVERSAL-TIME and ENCODE-UNIVERSAL-TIME take an optional time
zone argument. A time zone is defined to be the number of hours (more
precisely, a "rational multiple of 1/3600 between 24 (inclusive) and
-24 (inclusive)"). This positive going west from UTC and negative
going east. Thus, for example, the time zone of Massachusetts is
always 5.

If a time zone is not supplied to DECODE-UNIVERSAL-TIME or
ENCODE-UNIVERSAL-TIME, Common Lisp makes some assumptions, and some of
them are implementation specific. For example, the Hyperspec says, for
DECODE-UNIVERSAL-TIME: "If time-zone is not supplied, it defaults to
the current time zone adjusted for daylight saving time." I *think*
this means that the time zone is the (constant) time zone reported by
the machine (see function below) and whether or not daylight saving is
being observed in the machine's location then. No discussion of what
ENCODE-UNIVERSAL-TIME assumes is provided.

In any case, *supplying* a time zone is always safe, and turns off any
guesses about daylight saving time (very
implementation/location/operating system dependent), and this is
probably Good Programming Hygiene.
 
--
I *think* this should always return the local time zone, and always
return the same value whether or not daylight saving time is being
observed:

(defun current-time-zone ()
  (multiple-value-bind (s m h d m y dd dp zone) (get-decoded-time)
    (declare (ignore s m h d m y dd dp))
    zone))


And this should return whether the implementation thinks DST is being
observed (locally) at this universal time:

(defun dst-observed-p (universal-time)
 (multiple-value-bind (s m h d m y dd daylight-p) 
  (decode-universal-time universal-time)
    (declare (ignore s m h d m y dd))
    daylight-p))

--

Modifications: 
 - Corrected CL epoch to 1900 from 1970 (braino).
 - Removed comment about other languages' representation for time zone
offsets.

Thanks to Paul Foley for the corrections.
From: Erik Naggum
Subject: Re: time zones, daylight saving time, and universal time
Date: 
Message-ID: <3226657500167118@naggum.net>
* Will Fitzgerald
| I *think* this should always return the local time zone, and always
| return the same value whether or not daylight saving time is being
| observed:
| 
| (defun current-time-zone ()
|   (multiple-value-bind (s m h d m y dd dp zone) (get-decoded-time)
|     (declare (ignore s m h d m y dd dp))
|     zone))
| 
| 
| And this should return whether the implementation thinks DST is being
| observed (locally) at this universal time:
| 
| (defun dst-observed-p (universal-time)
|  (multiple-value-bind (s m h d m y dd daylight-p) 
|   (decode-universal-time universal-time)
|     (declare (ignore s m h d m y dd))
|     daylight-p))

  Are you aware of the function nth-value?

///
-- 
  In a fight against something, the fight has value, victory has none.
  In a fight for something, the fight is a loss, victory merely relief.