Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Timezone string had wrong sign and did not take DST into account.

* src/pattern-layout.lisp (format-time): %z time zone had wrong sign, and did not take DST into account
* tests/test-layouts.lisp (test-pattern-date-1): Change test of %c format to use correct time zone sign
(test-pattern-date-timezone): Add test for timezone formatted when DST is in effect
  • Loading branch information...
commit 98e42f13a9afa28387b12a1fa2e28a233862b17d 1 parent c05ffa8
Max Mikhanosha authored
Showing with 29 additions and 4 deletions.
  1. +5 −3 src/pattern-layout.lisp
  2. +24 −1 tests/test-layouts.lisp
View
8 src/pattern-layout.lisp
@@ -568,7 +568,6 @@ strftime like PATTERN."))
(multiple-value-bind (sec min hour day mon year wday dst-p tz)
(if utc-p (decode-universal-time ut 0)
(decode-universal-time ut))
- (declare (ignore dst-p))
(let ((state :normal)
(idx 0)
(c #\Space)
@@ -696,10 +695,13 @@ strftime like PATTERN."))
((char= c #\P) (output-string (if (< hour 12) "am" "pm")))
((char= c #\z)
(multiple-value-bind (tz-hours tz-mins)
- (floor tz)
+ (floor (if dst-p
+ (+ tz (/ (- ut (encode-universal-time sec min hour day mon year tz))
+ (* 60 60)))
+ tz))
(pad 5)
(format stream "~:[+~;-~]~2,'0d~2,'0d"
- (minusp tz-hours) (abs tz-hours)
+ (plusp tz-hours) (abs tz-hours)
(round (* 60 (coerce tz-mins 'float)))))))
(setq flag-uppercase nil
flag-numeric-no-pad nil
View
25 tests/test-layouts.lisp
@@ -455,7 +455,7 @@ two asserts "
(multiple-value-bind (tz-hours tz-mins)
(floor tz)
(format nil "Tue 21 Feb 2012 03:02:01 ~:[+~;-~]~2,'0d~2,'0d"
- (minusp tz-hours) (abs tz-hours)
+ (plusp tz-hours) (abs tz-hours)
(round (* 60 (coerce tz-mins 'float)))))))
(test-pattern-layout
(format nil "%D{%c}{~d}" ut-loc)
@@ -498,3 +498,26 @@ two asserts "
(test-pattern-layout "%I%p - %m" " INFO - message")
(with-log-indent ()
(test-pattern-layout "%I{>}%p - %m" ">>INFO - message")))))
+
+(deftest test-pattern-date-timezone ()
+ "Test that date pattern %z timezone changes when DST is effect"
+ (let* ((ut-winter (encode-universal-time 1 2 3 15 01 2012))
+ (ut-summer (encode-universal-time 1 2 3 15 6 2012))
+ (had-dst-in-summer-p (nth-value 7 (decode-universal-time ut-summer)))
+ (winter-tz (nth-value 8 (decode-universal-time ut-winter)))
+ (summer-tz (nth-value 8 (decode-universal-time ut-summer))))
+ ;; CL decode-universal-time returns timezone without taking TZ
+ ;; into consideration so just sanity check
+ (is (equal winter-tz summer-tz))
+ (if had-dst-in-summer-p
+ ;; If dst is in effect in the summer, test that %z is
+ ;; different from winter one
+ (is (not (equal (with-output-to-string (s)
+ (log4cl-impl::format-time s "%z" ut-winter nil))
+ (with-output-to-string (s)
+ (log4cl-impl::format-time s "%z" ut-summer nil)))))
+ ;; Otherwise should be same
+ (is (equal (with-output-to-string (s)
+ (log4cl-impl::format-time s "%z" ut-winter nil))
+ (with-output-to-string (s)
+ (log4cl-impl::format-time s "%z" ut-summer nil)))))))
Please sign in to comment.
Something went wrong with that request. Please try again.