On Sun, 18 Apr 2010, Edwin Woollett wrote:
< On April 17, Robert Dodier wrote:
< -----------------
< I guess you have Maxima built with GCL on Windows.
< GCL has a global variable SI::*DEFAULT-TIME-ZONE* which by
< default is -1. You can set this to some other value, e.g.
<
< :lisp (setq si::*default-time-zone* 7)
<
< now I get timedate() => 2010-04-17 08:51:46-07:00
<
< Digging around in the GCL source code, I see that the time
< zone is retrieved by, I guess, a Mingw function named
< GetTimeZoneInformation. I don;t know if the -1 value is a bug
< in that function or in GCL or what.
<
< Hope this helps,
< -----------------------------
< On April 17 Leo Butler wrote:
< --------------
< Ted, timedate can be patched to give you the functionality
< you want. The patched code replicates timedate() while
< timedate(+8) will give you the offset time.
<
<
< Leo
<
<
< (defmvar $time_zone_offset nil
< "The offset of the local time zone from GMT. This offset does
< not account for daylight savings.")
<
< (defun $timedate (&optional (tz-offset $time_zone_offset))
< (multiple-value-bind
< (second minute hour date month year day-of-week dst-p tz)
< (decode-universal-time (get-universal-time) tz-offset)
< (declare (ignore day-of-week))
< (let
< ((tz-offset (if dst-p (- 1 tz) (- tz))))
< (multiple-value-bind
< (tz-hours tz-hour-fraction)
< (floor tz-offset)
< (let
< ((tz-sign (if (< 0 tz-hours) #\+ #\-)))
< (format nil "~4,'0d-~2,'0d-~2,'0d
< ~2,'0d:~2,'0d:~2,'0d~a~2,'0d:~2,'0d"
< year month date hour minute second tz-sign (abs tz-hours)
< (floor (* 60 tz-hour-fraction))))))))
<
< -------------------------------------------
< Thanks to you both for solutions to my query.
< Both solutions do the job, although the lisp
< patch did not behave as expected with no
< argument:
< -------------------------
< (%i1) timedate();
< (%o1) 2010-04-18 19:51:22+01:00
< (%i2) :lisp (setq si::*default-time-zone* 7)
< 7
< (%i2) timedate();
< (%o2) 2010-04-18 11:52:20-07:00
< (%i3) load("new-timedate.lisp");
< (%o3) new-timedate.lisp
< (%i4) timedate();
< Maxima encountered a Lisp error:
<
< Error in DECODE-UNIVERSAL-TIME [or a callee]: NIL is not of type NUMBER.
<
< Automatically continuing.
< To reenable the Lisp debugger set *debugger-hook* to nil.
(defmvar $time_zone_offset nil
"The offset of the local time zone from GMT. This offset does
not account for daylight savings.")
(defun $timedate (&optional (tz-offset $time_zone_offset))
(multiple-value-bind
(second minute hour date month year day-of-week dst-p tz)
(if tz-offset (decode-universal-time (get-universal-time) tz-offset)
(decode-universal-time (get-universal-time)))
(declare (ignore day-of-week))
(let
((tz-offset (if dst-p (- 1 tz) (- tz))))
(multiple-value-bind
(tz-hours tz-hour-fraction)
(floor tz-offset)
(let
((tz-sign (if (< 0 tz-hours) #\+ #\-)))
(format nil "~4,'0d-~2,'0d-~2,'0d
~2,'0d:~2,'0d:~2,'0d~a~2,'0d:~2,'0d"
year month date hour minute second tz-sign (abs tz-hours)
(floor (* 60 tz-hour-fraction))))))))
Hi Ted,
I guess this is due to different Lisps behaving differently with a nil
tz-offset. The above code makes it explicit, and will fix your errors.
Leo
< (%i5) timedate(+8);
< (%o5) 2010-04-18
< 10:56:08-08:00
<
< (%i6) timedate(+7);
< (%o6) 2010-04-18
< 11:56:27-07:00
< -------------------------------
< My actual interest is using timedate() to put a
< time stamp on runs of batch files. Looking back
< at my tex file record of these runs, having that
< time stamp helps me sort out what came first in
< my thinking. And I actually only need the mo-day-year
< part of the time stamp.
<
< So I use the code :
< mydate : apply ('sconcat, rest (charlist (timedate()),-15))$
< with the effects (with the lisp patch in place):
< ---------------------------
< (%i7) mydate : apply ('sconcat, rest (charlist (timedate()),-15))$
< Maxima encountered a Lisp error:
<
< Error in DECODE-UNIVERSAL-TIME [or a callee]: NIL is not of type NUMBER.
<
< Automatically continuing.
< To reenable the Lisp debugger set *debugger-hook* to nil.
< (%i8) mydate : apply ('sconcat, rest (charlist (timedate(+7)),-15))$
< (%i9) mydate;
< (%o9) 2010-04-18
< -------------------------------------------
<
< I would like to include the construction of mydate
< as a simple example of string manipulation in the next
< revision of ch. 1 of maxima by example, as well as
< mention the cures you have provided for windows
< users.
<
< Thanks again,
< Ted
<
<
<
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.