]> git.eshelyaron.com Git - emacs.git/commitdiff
(math-parse-date): Fix a regular expression.
authorJay Belanger <jay.p.belanger@gmail.com>
Mon, 19 Mar 2007 03:16:20 +0000 (03:16 +0000)
committerJay Belanger <jay.p.belanger@gmail.com>
Mon, 19 Mar 2007 03:16:20 +0000 (03:16 +0000)
(math-std-daylight-savings-old, math-std-daylight-savings-new): New functions.
(math-std-daylight-savings): Use `math-std-daylight-savings-new' or
`math-std-daylight-savings-old' depending on year.

lisp/calc/calc-forms.el

index 1b4b6fea94ab7968bb80c9f2bbcb1c930518306d..0adbbe0f558e30635d8653bfe4276d8e84b20fbf 100644 (file)
              (a nil) (b nil) (c nil) (bigyear nil) temp)
 
          ;; Extract the time, if any.
-         (if (or (string-match "\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)\\(:\\([0-9][0-9]?\\(\\.[0-9]+\\)?\\)\\)? *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)?" math-pd-str)
-                 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str))
+         (if (or (string-match "\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)\\(:\\([0-9][0-9]?\\(\\.[0-9]+\\)?\\)\\)? *\\([ap]\\>\\|[ap]m\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)?" math-pd-str)
+                 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]\\>\\|[ap]m\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str))
              (let ((ampm (math-match-substring math-pd-str 6)))
                (setq hour (string-to-number (math-match-substring math-pd-str 1))
                      minute (math-match-substring math-pd-str 2)
 
 (defun math-std-daylight-savings (date dt zone bump)
   "Standard North American daylight saving algorithm.
-This implements the rules for the U.S. and Canada as of 2007.
+Before 2007, this uses `math-std-daylight-savings-old', where
+daylight savings began on the first Sunday of April at 2 a.m.,
+and ended on the last Sunday of October at 2 a.m.
+As of 2007, this uses `math-std-daylight-savings-new', where
+daylight saving begins on the second Sunday of March at 2 a.m.,
+and ends on the first Sunday of November at 2 a.m."
+  (if (< (car dt) 2007)
+      (math-std-daylight-savings-old date dt zone bump)
+    (math-std-daylight-savings-new date dt zone bump)))
+
+(defun math-std-daylight-savings-new (date dt zone bump)
+  "Standard North American daylight saving algorithm as of 2007.
+This implements the rules for the U.S. and Canada.
 Daylight saving begins on the second Sunday of March at 2 a.m.,
 and ends on the first Sunday of November at 2 a.m."
   (cond ((< (nth 1 dt) 3) 0)
@@ -1332,6 +1344,27 @@ and ends on the first Sunday of November at 2 a.m."
                 (t 0))))
        (t 0)))
 
+(defun math-std-daylight-savings-old (date dt zone bump)
+  "Standard North American daylight savings algorithm before 2007.
+This implements the rules for the U.S. and Canada.
+Daylight savings begins on the first Sunday of April at 2 a.m.,
+and ends on the last Sunday of October at 2 a.m."
+  (cond ((< (nth 1 dt) 4) 0)
+       ((= (nth 1 dt) 4)
+        (let ((sunday (math-prev-weekday-in-month date dt 7 0)))
+          (cond ((< (nth 2 dt) sunday) 0)
+                ((= (nth 2 dt) sunday)
+                 (if (>= (nth 3 dt) (+ 3 bump)) -1 0))
+                (t -1))))
+       ((< (nth 1 dt) 10) -1)
+       ((= (nth 1 dt) 10)
+        (let ((sunday (math-prev-weekday-in-month date dt 31 0)))
+          (cond ((< (nth 2 dt) sunday) -1)
+                ((= (nth 2 dt) sunday)
+                 (if (>= (nth 3 dt) (+ 2 bump)) 0 -1))
+                (t 0))))
+       (t 0)))
+
 ;;; Compute the day (1-31) of the WDAY (0-6) on or preceding the given
 ;;; day of the given month.
 (defun math-prev-weekday-in-month (date dt day wday)