Changeset 14840


Ignore:
Timestamp:
11/09/15 10:59:10 (6 years ago)
Author:
Mark Evenson
Message:

{decode,encode}-universal-time "time of the time" timezone semantics

Scott L. Burson

The implementation of EXT:GET-TIME-ZONE provides the underlying
mechanism.

Both GET-TIME-ZONE and DEFAULT-TIME-ZONE have been elevated to
supported status by virtue of promotion of their respective symbols to
the EXTENSIONS and SYSTEM packages, respectively.

ME: A mechanism for adding symbols to both SYS and EXT packages with
DEFINE-SYMBOL-MACRO didn't work, but left as comment at the end of
'time.lisp' for further work.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Autoload.java

    r14493 r14840  
    520520        autoload(PACKAGE_EXT, "gc", "gc", true);
    521521        autoload(PACKAGE_EXT, "get-floating-point-modes", "FloatFunctions", true);
     522        autoload(PACKAGE_EXT, "get-time-zone", "Time", true);
    522523        autoload(PACKAGE_EXT, "make-slime-input-stream", "SlimeInputStream", true);
    523524        autoload(PACKAGE_EXT, "make-slime-output-stream", "SlimeOutputStream", true);
  • trunk/abcl/src/org/armedbear/lisp/Time.java

    r12431 r14840  
    112112
    113113  // ### default-time-zone => offset daylight-p
    114   private static final Primitive DEFAULT_TIME_ZONE =
    115     new Primitive("default-time-zone", PACKAGE_SYS, false)
     114  public static final Primitive DEFAULT_TIME_ZONE = new pf_default_time_zone();
     115  @DocString(name="default-time-zone",
     116             args="",
     117             returns="offset daylight-p",
     118             doc="Returns the OFFSET of the default time zone for this instance of the implementation, and as a second value the state of the DAYLIGHT-P predicate.")
     119  public static final class pf_default_time_zone extends Primitive {
     120    pf_default_time_zone() {
     121      super("default-time-zone", PACKAGE_SYS, true);
     122    }
     123    public LispObject execute()
    116124    {
    117       @Override
    118       public LispObject execute()
    119       {
    120         TimeZone tz = TimeZone.getDefault();
    121         //int offset = tz.getOffset(System.currentTimeMillis());
    122         // Classpath hasn't implemented TimeZone.getOffset(long).
    123         int rawOffset = tz.getRawOffset();
    124         final boolean inDaylightTime =
    125           tz.inDaylightTime(new Date(System.currentTimeMillis()));
    126         if (inDaylightTime)
    127           rawOffset += tz.getDSTSavings();
    128         // "Time zone values increase with motion to the west..."
    129         // Convert milliseconds to hours.
    130         return LispThread.currentThread().setValues(
    131           Fixnum.getInstance(- rawOffset).divideBy(Fixnum.getInstance(3600000)),
    132           inDaylightTime ? T : NIL);
    133       }
    134     };
     125      return GET_TIME_ZONE.execute(LispInteger.getInstance(System.currentTimeMillis()));
     126    }
     127  };
     128
     129  public static final Primitive GET_TIME_ZONE = new pf_get_time_zone();
     130  @DocString(name="get-time-zone",
     131             args="time-in-millis",
     132             returns="timezone",
     133             doc="Return the timezone for TIME-IN-MILLIS via the Daylight assumptions that were in place at its occurance. i.e. implement 'time of the time semantics'." )
     134  public static final class pf_get_time_zone extends Primitive {
     135    pf_get_time_zone() {
     136      super("get-time-zone", PACKAGE_EXT, true, "");
     137    }
     138
     139    public LispObject execute(LispObject unixTimeMillis) {
     140      // should be a reference to a singleton for the lifetime of an ABCL process
     141      TimeZone tz = TimeZone.getDefault();
     142      // int offset = tz.getOffset(System.currentTimeMillis());
     143      // Classpath hasn't implemented TimeZone.getOffset(long).
     144      int rawOffset = tz.getRawOffset();
     145      final boolean inDaylightTime = tz.inDaylightTime(new Date(unixTimeMillis.longValue()));
     146      if (inDaylightTime)
     147        rawOffset += tz.getDSTSavings();
     148      // "Time zone values increase with motion to the west..."
     149      // Convert milliseconds to hours.
     150      return LispThread.currentThread()
     151        .setValues(Fixnum
     152                   .getInstance(- rawOffset).divideBy(Fixnum.getInstance(3600000)),
     153                   inDaylightTime ? T : NIL);
     154    }
     155  };
    135156}
  • trunk/abcl/src/org/armedbear/lisp/time.lisp

    r11391 r14840  
    4343(defconstant weekday-november-17-1858 2)
    4444
     45
     46
    4547;;; decode-universal-time universal-time &optional time-zone
    4648;;; => second minute hour date month year day daylight-p zone
     
    5456        (setf seconds-west (* time-zone 3600)
    5557              daylight nil)
    56         (multiple-value-bind (time-zone daylight-p) (default-time-zone)
     58        (multiple-value-bind (time-zone daylight-p) (ext:get-time-zone universal-time)
    5759          (setf seconds-west (* time-zone 3600)
    5860                daylight daylight-p)))
     
    128130   (hours (+ hour (* days 24))))
    129131    (cond (time-zone
    130            (+ second (* (+ minute (* (+ hours time-zone) 60)) 60)))
     132           (let* ((tz-guess (get-time-zone (* hours 3600)))
     133      (guess (+ second (* 60 (+ minute (* 60 (+ hours tz-guess))))))
     134      (tz (get-time-zone guess)))
     135             (+ guess (* 3600 (- tz tz-guess)))))
    131136          ((> year 2037)
    132137           (labels ((leap-year-p (year)
     
    144149          (t
    145150           (+ second (* (+ minute (* (+ hours (default-time-zone)) 60)) 60))))))
     151
     152#|
     153(intern "GET-TIME-ZONE" (find-package :ext))
     154(define-symbol-macro EXT:GET-TIME-ZONE
     155    `(get-time-zone))
     156(export (intern "GET-TIME-ZONE" (find-package :ext)))
     157#|
Note: See TracChangeset for help on using the changeset viewer.