]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/calc/calc.el (calc-standard-date-formats): Add more date
authorJay Belanger <jay.p.belanger@gmail.com>
Tue, 11 Dec 2012 02:29:21 +0000 (20:29 -0600)
committerJay Belanger <jay.p.belanger@gmail.com>
Tue, 11 Dec 2012 02:29:21 +0000 (20:29 -0600)
  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.

lisp/ChangeLog
lisp/calc/calc-forms.el
lisp/calc/calc.el

index aa870591e23c2dd72c077dace5f553a18e458019..ebce9305f317fd41c68e3a87b810ca1684e9b398 100644 (file)
@@ -1,3 +1,12 @@
+2012-12-11  Jay Belanger  <jay.p.belanger@gmail.com>
+
+       * calc/calc.el (calc-standard-date-formats):  Add more date
+       formats.
+       * 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.
+
 2012-12-10  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * hi-lock.el (hi-lock--regexps-at-point): Fix boundary case for
index 5ce76b14d72c5817ab8bdf974bf871fbb70de009..f72d20a57a011cae2386aad4edb0406879fb3fd3 100644 (file)
   (calc-wrapper
    (if (string-match-p "\\`\\s-*\\'" fmt)
        (setq fmt "1"))
-   (if (string-match "\\` *[0-9] *\\'" fmt)
+   (if (string-match "\\` \\(*[0-9]\\|10\\|11\\) *\\'" fmt)
        (setq fmt (nth (string-to-number fmt) calc-standard-date-formats)))
    (or (string-match "[a-zA-Z]" fmt)
        (error "Bad date format specifier"))
    (and arg
        (>= (setq arg (prefix-numeric-value arg)) 0)
-       (<= arg 9)
+       (<= arg 11)
        (setq calc-standard-date-formats
              (copy-sequence calc-standard-date-formats))
        (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)."
   (catch 'syntax
     (or (math-parse-standard-date math-pd-str t)
        (math-parse-standard-date math-pd-str nil)
+        (and (or (memq 'IYYY calc-date-format) (memq 'Iww calc-date-format))
+             (math-parse-iso-date math-pd-str))
        (and (string-match "\\`[^-+/0-9a-zA-Z]*\\([-+]?[0-9]+\\.?[0-9]*\\([eE][-+]?[0-9]+\\)?\\)[^-+/0-9a-zA-Z]*\\'" math-pd-str)
             (list 'date (math-read-number (math-match-substring math-pd-str 1))))
        (let ((case-fold-search t)
@@ -1085,6 +1087,8 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
 (defun math-parse-iso-date-validate (isoyear isoweek isoweekday hour minute second)
   (if (or (< isoweek 1) (> isoweek 53))
       (throw 'syntax "Week value is out of range"))
+  (if (or (< isoweekday 1) (> isoweekday 7))
+      (throw 'syntax "Weekday value is out of range"))
   (and hour
        (progn
         (if (or (< hour 0) (> hour 23))
@@ -1290,6 +1294,31 @@ as measured in the integer number of days before December 31, 1 BC (Gregorian)."
                      (setq day (math-add day (1- yearday))))
                  day))))))
 
+(defun math-parse-iso-date (math-pd-str)
+  "Parse MATH-PD-STR as an ISO week date, or return nil."
+  (let ((case-fold-search t)
+        (isoyear nil) (isoweek nil) (isoweekday nil)
+        (hour nil) (minute nil) (second nil))
+    ;; Extract the time, if any.
+    (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)
+        (progn
+          (setq hour (string-to-number (math-match-substring math-pd-str 1))
+                minute (math-match-substring math-pd-str 2)
+                second (math-match-substring math-pd-str 3)
+                math-pd-str (substring math-pd-str 0 (match-beginning 0)))
+          (if (equal minute "")
+              (setq minute 0)
+            (setq minute (string-to-number minute)))
+          (if (equal second "")
+              (setq second 0)
+            (setq second (math-read-number second)))))
+    ;; Next, the year, week and weekday
+    (if (string-match "\\(-?[0-9]*\\)[^0-9]*W\\([0-9][0-9]\\)[^0-9]*\\([0-9]\\)[^0-9]*\\'" math-pd-str)
+        (progn
+          (setq isoyear (string-to-number (math-match-substring math-pd-str 1))
+                isoweek (string-to-number (math-match-substring math-pd-str 2))
+                isoweekday (string-to-number (math-match-substring math-pd-str 3)))
+          (math-parse-iso-date-validate isoyear isoweek isoweekday hour minute second)))))
 
 (defun calcFunc-now (&optional zone)
   (let ((date (let ((calc-date-format nil))
index 58eabf9bcec03a8288544759a9530370ad74892f..b89cfbbda367d041120875023164dd143b4928d9 100644 (file)
@@ -787,7 +787,9 @@ If nil, selections displayed but ignored.")
     "M-D-Y< H:mm:SSpp>"
     "D-M-Y< h:mm:SS>"
     "j<, h:mm:SS>"
-    "YYddd< hh:mm:ss>"))
+    "YYddd< hh:mm:ss>"
+    "ZYYY-MM-DD Www< hh:mm>"
+    "IYYY-Iww-w< Thh:mm:ss>"))
 
 (defcalcmodevar calc-autorange-units nil
   "If non-nil, automatically set unit prefixes to keep units in a reasonable range.")