Permalink
Browse files

fix encode/decode incongruence caused by changing decode-timestamp

  • Loading branch information...
1 parent 7a736c6 commit b912578f3174a07b8a09b30a8d2b272718582402 @felideon felideon committed Nov 1, 2012
Showing with 76 additions and 78 deletions.
  1. +76 −78 src/local-time.lisp
View
@@ -1148,17 +1148,14 @@ elements."
(%timestamp-decode-time adjusted-secs)
(multiple-value-bind (year month day)
(%timestamp-decode-date adjusted-days)
- (multiple-value-bind (iso-year iso-week iso-weekday)
- (%timestamp-decode-iso-week timestamp)
- (values
- (nsec-of timestamp)
- seconds minutes hours
- day month year
- (timestamp-day-of-week timestamp :timezone timezone :offset offset)
- iso-year iso-week iso-weekday
- daylight-p
- (or offset offset*)
- abbreviation)))))))
+ (values
+ (nsec-of timestamp)
+ seconds minutes hours
+ day month year
+ (timestamp-day-of-week timestamp :timezone timezone :offset offset)
+ daylight-p
+ (or offset offset*)
+ abbreviation))))))
(defun timestamp-year (timestamp &key (timezone *default-timezone*))
"Returns the cardinal year upon which the timestamp falls."
@@ -1467,75 +1464,76 @@ elements."
"Constructs a string representing TIMESTAMP given the FORMAT of the string and the TIMEZONE. See the documentation of FORMAT-TIMESTRING for the structure of FORMAT."
(declare (type timestamp timestamp)
(optimize (speed 3)))
- (multiple-value-bind (nsec sec minute hour day month year weekday
- iso-year iso-week iso-weekday daylight-p offset abbrev)
+ (multiple-value-bind (nsec sec minute hour day month year weekday daylight-p offset abbrev)
(decode-timestamp timestamp :timezone timezone)
(declare (ignore daylight-p))
- (let ((*print-pretty* nil)
- (*print-circle* nil))
- (with-output-to-string (result nil :element-type 'base-char)
- (dolist (fmt format)
- (cond
- ((or (eql fmt :gmt-offset)
- (eql fmt :gmt-offset-or-z))
- (multiple-value-bind (offset-hours offset-secs)
- (floor offset +seconds-per-hour+)
- (declare (fixnum offset-hours offset-secs))
- (if (and (eql fmt :gmt-offset-or-z) (zerop offset))
- (princ #\Z result)
- (format result "~c~2,'0d:~2,'0d"
- (if (minusp offset-hours) #\- #\+)
- (abs offset-hours)
- (truncate (abs offset-secs)
- +seconds-per-minute+)))))
- ((eql fmt :short-year)
- (princ (mod year 100) result))
- ((eql fmt :long-month)
- (princ (aref +month-names+ month) result))
- ((eql fmt :short-month)
- (princ (aref +short-month-names+ month) result))
- ((eql fmt :long-weekday)
- (princ (aref +day-names+ weekday) result))
- ((eql fmt :short-weekday)
- (princ (aref +short-day-names+ weekday) result))
- ((eql fmt :timezone)
- (princ abbrev result))
- ((eql fmt :hour12)
- (princ (1+ (mod (1- hour) 12)) result))
- ((eql fmt :ampm)
- (princ (if (< hour 12) "am" "pm") result))
- ((eql fmt :ordinal-day)
- (princ (ordinalize day) result))
- ((or (stringp fmt) (characterp fmt))
- (princ fmt result))
- (t
- (let ((val (ecase (if (consp fmt) (car fmt) fmt)
- (:nsec nsec)
- (:usec (floor nsec 1000))
- (:msec (floor nsec 1000000))
- (:sec sec)
- (:min minute)
- (:hour hour)
- (:day day)
- (:weekday weekday)
- (:month month)
- (:year year)
- (:iso-week-year iso-year)
- (:iso-week-number iso-week)
- (:iso-week-day iso-weekday))))
- (cond
- ((atom fmt)
- (princ val result))
- ((minusp val)
- (format result "-~v,vd"
- (second fmt)
- (or (third fmt) #\0)
- (abs val)))
- (t
- (format result "~v,vd"
- (second fmt)
- (or (third fmt) #\0)
- val)))))))))))
+ (multiple-value-bind (iso-year iso-week iso-weekday)
+ (%timestamp-decode-iso-week timestamp)
+ (let ((*print-pretty* nil)
+ (*print-circle* nil))
+ (with-output-to-string (result nil :element-type 'base-char)
+ (dolist (fmt format)
+ (cond
+ ((or (eql fmt :gmt-offset)
+ (eql fmt :gmt-offset-or-z))
+ (multiple-value-bind (offset-hours offset-secs)
+ (floor offset +seconds-per-hour+)
+ (declare (fixnum offset-hours offset-secs))
+ (if (and (eql fmt :gmt-offset-or-z) (zerop offset))
+ (princ #\Z result)
+ (format result "~c~2,'0d:~2,'0d"
+ (if (minusp offset-hours) #\- #\+)
+ (abs offset-hours)
+ (truncate (abs offset-secs)
+ +seconds-per-minute+)))))
+ ((eql fmt :short-year)
+ (princ (mod year 100) result))
+ ((eql fmt :long-month)
+ (princ (aref +month-names+ month) result))
+ ((eql fmt :short-month)
+ (princ (aref +short-month-names+ month) result))
+ ((eql fmt :long-weekday)
+ (princ (aref +day-names+ weekday) result))
+ ((eql fmt :short-weekday)
+ (princ (aref +short-day-names+ weekday) result))
+ ((eql fmt :timezone)
+ (princ abbrev result))
+ ((eql fmt :hour12)
+ (princ (1+ (mod (1- hour) 12)) result))
+ ((eql fmt :ampm)
+ (princ (if (< hour 12) "am" "pm") result))
+ ((eql fmt :ordinal-day)
+ (princ (ordinalize day) result))
+ ((or (stringp fmt) (characterp fmt))
+ (princ fmt result))
+ (t
+ (let ((val (ecase (if (consp fmt) (car fmt) fmt)
+ (:nsec nsec)
+ (:usec (floor nsec 1000))
+ (:msec (floor nsec 1000000))
+ (:sec sec)
+ (:min minute)
+ (:hour hour)
+ (:day day)
+ (:weekday weekday)
+ (:month month)
+ (:year year)
+ (:iso-week-year iso-year)
+ (:iso-week-number iso-week)
+ (:iso-week-day iso-weekday))))
+ (cond
+ ((atom fmt)
+ (princ val result))
+ ((minusp val)
+ (format result "-~v,vd"
+ (second fmt)
+ (or (third fmt) #\0)
+ (abs val)))
+ (t
+ (format result "~v,vd"
+ (second fmt)
+ (or (third fmt) #\0)
+ val))))))))))))
(defun format-timestring (destination timestamp &key
(format +iso-8601-format+)

0 comments on commit b912578

Please sign in to comment.