From 3f66dcf1dfbf43b8d150780d5adc544349e26b19 Mon Sep 17 00:00:00 2001 From: samuel-jimenez <53528911+samuel-jimenez@users.noreply.github.com> Date: Wed, 5 Aug 2020 13:18:38 -0500 Subject: [PATCH 1/2] encode-timestamp handles DST --- src/local-time.lisp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/local-time.lisp b/src/local-time.lisp index edcbd0b2..cd385180 100644 --- a/src/local-time.lisp +++ b/src/local-time.lisp @@ -188,7 +188,7 @@ ;; time of day. (defparameter +modified-julian-date-offset+ -51604) -(defun %guess-offset (seconds days &optional timezone) +(defun %guess-unix-offset (unix-time &optional timezone) ;; try converting the local time to a timestamp using each available ;; subtimezone, until we find one where the offset matches the offset that ;; applies at that time (according to the transition table). @@ -197,7 +197,6 @@ ;; Whichever subtimezone is listed first in the tzinfo database will be ;; the one that we pick to resolve ambiguous local time representations. (let* ((zone (%realize-timezone (or timezone *default-timezone*))) - (unix-time (timestamp-values-to-unix seconds days)) (subzone-idx (if (zerop (length (timezone-indexes zone))) 0 (elt (timezone-indexes zone) @@ -206,6 +205,13 @@ (subzone (elt (timezone-subzones zone) subzone-idx))) (subzone-offset subzone))) +(defun %guess-offset (seconds days &optional timezone) + ;; check that guessed offset still applies + (let* ((unix-time (timestamp-values-to-unix seconds days)) + (offset (%guess-unix-offset unix-time timezone))) + (%guess-unix-offset (- unix-time offset) timezone))) + + (defun %read-binary-integer (stream byte-count &optional (signed nil)) "Read BYTE-COUNT bytes from the binary stream STREAM, and return an integer which is its representation in network byte order (MSB). If SIGNED is true, interprets the most significant bit as a sign indicator." (loop From 413919d7f8876f21e46579eaf224282f681b49b0 Mon Sep 17 00:00:00 2001 From: samuel-jimenez <53528911+samuel-jimenez@users.noreply.github.com> Date: Mon, 23 Nov 2020 11:02:02 -0600 Subject: [PATCH 2/2] Update local-time.lisp --- src/local-time.lisp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/local-time.lisp b/src/local-time.lisp index 2384f3fd..62d9597b 100644 --- a/src/local-time.lisp +++ b/src/local-time.lisp @@ -204,7 +204,7 @@ (values (elt (timezone-subzones timezone) subzone-idx) transition-idx))) -(defun %guess-offset (seconds days &optional timezone) +(defun %guess-unix-offset (unix-time &optional timezone) ;; try converting the local time to a timestamp using each available ;; subtimezone, until we find one where the offset matches the offset that ;; applies at that time (according to the transition table). @@ -213,10 +213,20 @@ ;; Whichever subtimezone is listed first in the tzinfo database will be ;; the one that we pick to resolve ambiguous local time representations. (let* ((zone (%realize-timezone (or timezone *default-timezone*))) - (unix-time (timestamp-values-to-unix seconds days)) - (subzone (%subzone-as-of zone unix-time))) + (subzone-idx (if (zerop (length (timezone-indexes zone))) + 0 + (elt (timezone-indexes zone) + (transition-position unix-time + (timezone-transitions zone))))) + (subzone (elt (timezone-subzones zone) subzone-idx))) (subzone-offset subzone))) +(defun %guess-offset (seconds days &optional timezone) + ;; check that guessed offset still applies + (let* ((unix-time (timestamp-values-to-unix seconds days)) + (offset (%guess-unix-offset unix-time timezone))) + (%guess-unix-offset (- unix-time offset) timezone))) + (defun %read-binary-integer (stream byte-count &optional (signed nil)) "Read BYTE-COUNT bytes from the binary stream STREAM, and return an integer which is its representation in network byte order (MSB). If SIGNED is true, interprets the most significant bit as a sign indicator." (loop