Permalink
Browse files

Fixed offset bug in minimize and maximize part functions

  • Loading branch information...
1 parent 3b2d503 commit 058c04f5e5870fcb9ff7365ad1156a623aedfbd8 @dlowe-net committed Mar 24, 2010
Showing with 16 additions and 7 deletions.
  1. +4 −7 src/local-time.lisp
  2. +12 −0 test/simple.lisp
View
@@ -585,7 +585,6 @@ In other words:
(timestamp-subtimezone source timezone))))
(defun timestamp-minimize-part (timestamp part &key
- offset
(timezone *default-timezone*)
into)
(let* ((timestamp-parts '(:nsec :sec :min :hour :day :month))
@@ -594,7 +593,7 @@ In other words:
"timestamp-minimize-part called with invalid part ~a (expected one of ~a)"
part
timestamp-parts)
- (multiple-value-bind (nsec sec min hour day month year day-of-week daylight-saving-time-p)
+ (multiple-value-bind (nsec sec min hour day month year day-of-week daylight-saving-time-p offset)
(decode-timestamp timestamp :timezone timezone)
(declare (ignore nsec day-of-week daylight-saving-time-p))
(encode-timestamp 0
@@ -608,9 +607,7 @@ In other words:
:timezone timezone
:into into))))
-
(defun timestamp-maximize-part (timestamp part &key
- offset
(timezone *default-timezone*)
into)
(let* ((timestamp-parts '(:nsec :sec :min :hour :day :month))
@@ -619,7 +616,7 @@ In other words:
"timestamp-maximize-part called with invalid part ~a (expected one of ~a)"
part
timestamp-parts)
- (multiple-value-bind (nsec sec min hour day month year day-of-week daylight-saving-time-p)
+ (multiple-value-bind (nsec sec min hour day month year day-of-week daylight-saving-time-p offset)
(decode-timestamp timestamp :timezone timezone)
(declare (ignore nsec day-of-week daylight-saving-time-p))
(let ((month (if (> part-count 4) 12 month)))
@@ -842,7 +839,7 @@ the previous day given by OFFSET."
(floor (+ offset nsec) 1000000000)
;; the time might need to be adjusted a bit more if q != 0
(setf part :sec
- offset sec-offset
+ offset sec-offset
nsec new-nsec)
(go top)))
((:sec :minute :hour)
@@ -853,7 +850,7 @@ the previous day given by OFFSET."
(:hour +seconds-per-hour+))))
+seconds-per-day+)
(setf part :day
- offset days-offset
+ offset days-offset
sec new-sec)
(go top)))
(:day
View
@@ -216,3 +216,15 @@
(is (= year year*))
(is (= month month*))
(is (= day day*)))))))))
+
+(deftest test/timestamp-maximize-part ()
+ (timestamp= (timestamp-maximize-part
+ (encode-timestamp 0 49 26 13 9 12 2010 :offset -18000)
+ :min)
+ (encode-timestamp 999999999 59 59 13 9 12 2010 :offset -18000)))
+
+(deftest test/timestamp-minimize-part ()
+ (timestamp= (timestamp-minimize-part
+ (encode-timestamp 0 49 26 13 9 12 2010 :offset -18000)
+ :min)
+ (encode-timestamp 0 0 0 13 9 12 2010 :offset -18000)))

0 comments on commit 058c04f

Please sign in to comment.