Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/local-time.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand Down