time zones, daylight saving time, and universal time 
Author Message
 time zones, daylight saving time, and universal time

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))



Wed, 15 Sep 2004 02:52:57 GMT  
 time zones, daylight saving time, and universal time

Quote:

> 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.



Fri, 17 Sep 2004 21:12:34 GMT  
 time zones, daylight saving time, and universal time
* 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.



Fri, 17 Sep 2004 21:44:44 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. time.daylight (Daylight Saving Time)

2. VisualWork, Time, and Daylight Savings TIme

3. Portable version of time:parse-universal-time ?

4. Daylight saving Time issue...

5. Daylight Savings Time

6. Daylight saving time

7. gmt vs. labview daylight saving time XL

8. DayLight Saving Time in LabView

9. Daylight Saving Time flag in BIOS

10. gnat304 Daylight Saving Time problem (was: compiler errors in GNAT 304a (win95))

11. time, strptime, daylight saving

12. Disregard daylight saving time

 

 
Powered by phpBB® Forum Software