aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2007-03-19 03:16:20 +0000
committerJay Belanger2007-03-19 03:16:20 +0000
commit96cd475f4b496cc069296484a4b19f726be15526 (patch)
treee28b2044b7585db73f359b630a8b3a6c78545721
parent54e6585facc95a061edb72fd41284af236e345e7 (diff)
downloademacs-96cd475f4b496cc069296484a4b19f726be15526.tar.gz
emacs-96cd475f4b496cc069296484a4b19f726be15526.zip
(math-parse-date): Fix a regular expression.
(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.
-rw-r--r--lisp/calc/calc-forms.el39
1 files changed, 36 insertions, 3 deletions
diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el
index 1b4b6fea94a..0adbbe0f558 100644
--- a/lisp/calc/calc-forms.el
+++ b/lisp/calc/calc-forms.el
@@ -727,8 +727,8 @@
727 (a nil) (b nil) (c nil) (bigyear nil) temp) 727 (a nil) (b nil) (c nil) (bigyear nil) temp)
728 728
729 ;; Extract the time, if any. 729 ;; Extract the time, if any.
730 (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) 730 (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)
731 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]m?\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str)) 731 (string-match "\\([0-9][0-9]?\\)\\(\\)\\(\\(\\(\\)\\)\\) *\\([ap]\\>\\|[ap]m\\|[ap]\\. *m\\.\\|noon\\|n\\>\\|midnight\\|mid\\>\\|m\\>\\)" math-pd-str))
732 (let ((ampm (math-match-substring math-pd-str 6))) 732 (let ((ampm (math-match-substring math-pd-str 6)))
733 (setq hour (string-to-number (math-match-substring math-pd-str 1)) 733 (setq hour (string-to-number (math-match-substring math-pd-str 1))
734 minute (math-match-substring math-pd-str 2) 734 minute (math-match-substring math-pd-str 2)
@@ -1313,7 +1313,19 @@
1313 1313
1314(defun math-std-daylight-savings (date dt zone bump) 1314(defun math-std-daylight-savings (date dt zone bump)
1315 "Standard North American daylight saving algorithm. 1315 "Standard North American daylight saving algorithm.
1316This implements the rules for the U.S. and Canada as of 2007. 1316Before 2007, this uses `math-std-daylight-savings-old', where
1317daylight savings began on the first Sunday of April at 2 a.m.,
1318and ended on the last Sunday of October at 2 a.m.
1319As of 2007, this uses `math-std-daylight-savings-new', where
1320daylight saving begins on the second Sunday of March at 2 a.m.,
1321and ends on the first Sunday of November at 2 a.m."
1322 (if (< (car dt) 2007)
1323 (math-std-daylight-savings-old date dt zone bump)
1324 (math-std-daylight-savings-new date dt zone bump)))
1325
1326(defun math-std-daylight-savings-new (date dt zone bump)
1327 "Standard North American daylight saving algorithm as of 2007.
1328This implements the rules for the U.S. and Canada.
1317Daylight saving begins on the second Sunday of March at 2 a.m., 1329Daylight saving begins on the second Sunday of March at 2 a.m.,
1318and ends on the first Sunday of November at 2 a.m." 1330and ends on the first Sunday of November at 2 a.m."
1319 (cond ((< (nth 1 dt) 3) 0) 1331 (cond ((< (nth 1 dt) 3) 0)
@@ -1332,6 +1344,27 @@ and ends on the first Sunday of November at 2 a.m."
1332 (t 0)))) 1344 (t 0))))
1333 (t 0))) 1345 (t 0)))
1334 1346
1347(defun math-std-daylight-savings-old (date dt zone bump)
1348 "Standard North American daylight savings algorithm before 2007.
1349This implements the rules for the U.S. and Canada.
1350Daylight savings begins on the first Sunday of April at 2 a.m.,
1351and ends on the last Sunday of October at 2 a.m."
1352 (cond ((< (nth 1 dt) 4) 0)
1353 ((= (nth 1 dt) 4)
1354 (let ((sunday (math-prev-weekday-in-month date dt 7 0)))
1355 (cond ((< (nth 2 dt) sunday) 0)
1356 ((= (nth 2 dt) sunday)
1357 (if (>= (nth 3 dt) (+ 3 bump)) -1 0))
1358 (t -1))))
1359 ((< (nth 1 dt) 10) -1)
1360 ((= (nth 1 dt) 10)
1361 (let ((sunday (math-prev-weekday-in-month date dt 31 0)))
1362 (cond ((< (nth 2 dt) sunday) -1)
1363 ((= (nth 2 dt) sunday)
1364 (if (>= (nth 3 dt) (+ 2 bump)) 0 -1))
1365 (t 0))))
1366 (t 0)))
1367
1335;;; Compute the day (1-31) of the WDAY (0-6) on or preceding the given 1368;;; Compute the day (1-31) of the WDAY (0-6) on or preceding the given
1336;;; day of the given month. 1369;;; day of the given month.
1337(defun math-prev-weekday-in-month (date dt day wday) 1370(defun math-prev-weekday-in-month (date dt day wday)