aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Belanger2012-12-10 20:29:21 -0600
committerJay Belanger2012-12-10 20:29:21 -0600
commitff3f6c266a5a4fb730e7a59a8eb22005a6c0abb1 (patch)
treeb185c930f0da147e12eebef069ec9b5af09c3d80
parent0eeb69fe150751f33150f448fcc4fcd1d3fe4ff9 (diff)
downloademacs-ff3f6c266a5a4fb730e7a59a8eb22005a6c0abb1.tar.gz
emacs-ff3f6c266a5a4fb730e7a59a8eb22005a6c0abb1.zip
* lisp/calc/calc.el (calc-standard-date-formats): Add more date
formats. * lisp/calc/calc-forms.el (math-parse-iso-date): New function. (math-parse-date): Use `math-parse-iso-date' when appropriate. (math-parse-iso-date-validate): Add extra error checking. (calc-date-notation): Add ability to access new date formats.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/calc/calc-forms.el33
-rw-r--r--lisp/calc/calc.el4
3 files changed, 43 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index aa870591e23..ebce9305f31 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12012-12-11 Jay Belanger <jay.p.belanger@gmail.com>
2
3 * calc/calc.el (calc-standard-date-formats): Add more date
4 formats.
5 * calc/calc-forms.el (math-parse-iso-date): New function.
6 (math-parse-date): Use `math-parse-iso-date' when appropriate.
7 (math-parse-iso-date-validate): Add extra error checking.
8 (calc-date-notation): Add ability to access new date formats.
9
12012-12-10 Stefan Monnier <monnier@iro.umontreal.ca> 102012-12-10 Stefan Monnier <monnier@iro.umontreal.ca>
2 11
3 * hi-lock.el (hi-lock--regexps-at-point): Fix boundary case for 12 * hi-lock.el (hi-lock--regexps-at-point): Fix boundary case for
diff --git a/lisp/calc/calc-forms.el b/lisp/calc/calc-forms.el
index 5ce76b14d72..f72d20a57a0 100644
--- a/lisp/calc/calc-forms.el
+++ b/lisp/calc/calc-forms.el
@@ -82,13 +82,13 @@
82 (calc-wrapper 82 (calc-wrapper
83 (if (string-match-p "\\`\\s-*\\'" fmt) 83 (if (string-match-p "\\`\\s-*\\'" fmt)
84 (setq fmt "1")) 84 (setq fmt "1"))
85 (if (string-match "\\` *[0-9] *\\'" fmt) 85 (if (string-match "\\` \\(*[0-9]\\|10\\|11\\) *\\'" fmt)
86 (setq fmt (nth (string-to-number fmt) calc-standard-date-formats))) 86 (setq fmt (nth (string-to-number fmt) calc-standard-date-formats)))
87 (or (string-match "[a-zA-Z]" fmt) 87 (or (string-match "[a-zA-Z]" fmt)
88 (error "Bad date format specifier")) 88 (error "Bad date format specifier"))
89 (and arg 89 (and arg
90 (>= (setq arg (prefix-numeric-value arg)) 0) 90 (>= (setq arg (prefix-numeric-value arg)) 0)
91 (<= arg 9) 91 (<= arg 11)
92 (setq calc-standard-date-formats 92 (setq calc-standard-date-formats
93 (copy-sequence calc-standard-date-formats)) 93 (copy-sequence calc-standard-date-formats))
94 (setcar (nthcdr arg calc-standard-date-formats) fmt)) 94 (setcar (nthcdr arg calc-standard-date-formats) fmt))
@@ -918,6 +918,8 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
918 (catch 'syntax 918 (catch 'syntax
919 (or (math-parse-standard-date math-pd-str t) 919 (or (math-parse-standard-date math-pd-str t)
920 (math-parse-standard-date math-pd-str nil) 920 (math-parse-standard-date math-pd-str nil)
921 (and (or (memq 'IYYY calc-date-format) (memq 'Iww calc-date-format))
922 (math-parse-iso-date math-pd-str))
921 (and (string-match "\\`[^-+/0-9a-zA-Z]*\\([-+]?[0-9]+\\.?[0-9]*\\([eE][-+]?[0-9]+\\)?\\)[^-+/0-9a-zA-Z]*\\'" math-pd-str) 923 (and (string-match "\\`[^-+/0-9a-zA-Z]*\\([-+]?[0-9]+\\.?[0-9]*\\([eE][-+]?[0-9]+\\)?\\)[^-+/0-9a-zA-Z]*\\'" math-pd-str)
922 (list 'date (math-read-number (math-match-substring math-pd-str 1)))) 924 (list 'date (math-read-number (math-match-substring math-pd-str 1))))
923 (let ((case-fold-search t) 925 (let ((case-fold-search t)
@@ -1085,6 +1087,8 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
1085(defun math-parse-iso-date-validate (isoyear isoweek isoweekday hour minute second) 1087(defun math-parse-iso-date-validate (isoyear isoweek isoweekday hour minute second)
1086 (if (or (< isoweek 1) (> isoweek 53)) 1088 (if (or (< isoweek 1) (> isoweek 53))
1087 (throw 'syntax "Week value is out of range")) 1089 (throw 'syntax "Week value is out of range"))
1090 (if (or (< isoweekday 1) (> isoweekday 7))
1091 (throw 'syntax "Weekday value is out of range"))
1088 (and hour 1092 (and hour
1089 (progn 1093 (progn
1090 (if (or (< hour 0) (> hour 23)) 1094 (if (or (< hour 0) (> hour 23))
@@ -1290,6 +1294,31 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
1290 (setq day (math-add day (1- yearday)))) 1294 (setq day (math-add day (1- yearday))))
1291 day)))))) 1295 day))))))
1292 1296
1297(defun math-parse-iso-date (math-pd-str)
1298 "Parse MATH-PD-STR as an ISO week date, or return nil."
1299 (let ((case-fold-search t)
1300 (isoyear nil) (isoweek nil) (isoweekday nil)
1301 (hour nil) (minute nil) (second nil))
1302 ;; Extract the time, if any.
1303 (if (string-match "T[^0-9]*\\([0-9][0-9]\\)[^0-9]*\\([0-9][0-9]\\)?[^0-9]*\\([0-9][0-9]\\(\\.[0-9]+\\)?\\)?" math-pd-str)
1304 (progn
1305 (setq hour (string-to-number (math-match-substring math-pd-str 1))
1306 minute (math-match-substring math-pd-str 2)
1307 second (math-match-substring math-pd-str 3)
1308 math-pd-str (substring math-pd-str 0 (match-beginning 0)))
1309 (if (equal minute "")
1310 (setq minute 0)
1311 (setq minute (string-to-number minute)))
1312 (if (equal second "")
1313 (setq second 0)
1314 (setq second (math-read-number second)))))
1315 ;; Next, the year, week and weekday
1316 (if (string-match "\\(-?[0-9]*\\)[^0-9]*W\\([0-9][0-9]\\)[^0-9]*\\([0-9]\\)[^0-9]*\\'" math-pd-str)
1317 (progn
1318 (setq isoyear (string-to-number (math-match-substring math-pd-str 1))
1319 isoweek (string-to-number (math-match-substring math-pd-str 2))
1320 isoweekday (string-to-number (math-match-substring math-pd-str 3)))
1321 (math-parse-iso-date-validate isoyear isoweek isoweekday hour minute second)))))
1293 1322
1294(defun calcFunc-now (&optional zone) 1323(defun calcFunc-now (&optional zone)
1295 (let ((date (let ((calc-date-format nil)) 1324 (let ((date (let ((calc-date-format nil))
diff --git a/lisp/calc/calc.el b/lisp/calc/calc.el
index 58eabf9bcec..b89cfbbda36 100644
--- a/lisp/calc/calc.el
+++ b/lisp/calc/calc.el
@@ -787,7 +787,9 @@ If nil, selections displayed but ignored.")
787 "M-D-Y< H:mm:SSpp>" 787 "M-D-Y< H:mm:SSpp>"
788 "D-M-Y< h:mm:SS>" 788 "D-M-Y< h:mm:SS>"
789 "j<, h:mm:SS>" 789 "j<, h:mm:SS>"
790 "YYddd< hh:mm:ss>")) 790 "YYddd< hh:mm:ss>"
791 "ZYYY-MM-DD Www< hh:mm>"
792 "IYYY-Iww-w< Thh:mm:ss>"))
791 793
792(defcalcmodevar calc-autorange-units nil 794(defcalcmodevar calc-autorange-units nil
793 "If non-nil, automatically set unit prefixes to keep units in a reasonable range.") 795 "If non-nil, automatically set unit prefixes to keep units in a reasonable range.")