encode/decode-universal-time - reolved - not a bug

Bug #1980611 reported by Navid
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Invalid
Undecided
Unassigned

Bug Description

I expected the following function to return the correct day of the week, but it is off by one day (reports the previous weekday). The date decreases by one day during the process.

SBCL version 2.2.6, Windows x64

(defun weekday-of (day month year)
  "Return day of the week for a date."
  (nth-value 6
      (decode-universal-time (encode-universal-time 0 0 0 day month year 0))))

E.g.
(weekday-of 3 7 2022) => 5 (but should return 6 as July 3, 2022 is a Sunday).

Thank you for your attention.

Navid

Tags: dateandtime
Revision history for this message
Navid (jnmadani) wrote :

Looks like this is localization-related. With time-zone adjustment, the result is correct. If I use:

(encode-universal-time 0 0 0 day month year 5)

to account for my GMT-5 time-zone, I get the correct date.

Sorry for the trouble, but it does not appear that I can close/resolve the report.

summary: - encode/decode-universal-time bug
+ encode/decode-universal-time - reolved - not a bug
Changed in sbcl:
status: New → Invalid
Revision history for this message
Stas Boukarev (stassats) wrote :

I might be better to supply the same timezone to decode-universal-time instead, i.e:

(defun weekday-of (day month year)
  "Return day of the week for a date."
  (nth-value 6
             (decode-universal-time (encode-universal-time 0 0 0 day month year 0) 0)))

Revision history for this message
Navid (jnmadani) wrote :

Indeed, thank you!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.