emacs-wiki-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[emacs-wiki-discuss] planner iso8601 patch


From: Trent Buck
Subject: [emacs-wiki-discuss] planner iso8601 patch
Date: Mon, 11 Jul 2005 08:18:25 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

I think I submitted this before... I've cleaned it up a little, and added a
defcustom variable to switch between ISO 8601 (hyphens) and traditional (dots)
formatted dates.  Of course, changing it after loading planner has no effect :-p

diff -wpurNd planner/planner-deadline.el planner/planner-deadline.el
--- planner/planner-deadline.el 2005-07-02 21:18:44.000000000 +1000
+++ planner/planner-deadline.el 2005-07-11 07:06:23.403580968 +1000
@@ -48,10 +48,17 @@ Point will be on the same line as the ta
   :type 'hook
   :group 'planner-deadline)
 
-(defcustom planner-deadline-regexp 
"\\({{Deadline:\\s-+\\([0-9]+\\.[0-9]+\\.[0-9]+\\)[^}]*}}\\)"
+(defcustom planner-deadline-regexp
+  (if planner-iso8601-dates
+      "\\({{Deadline:\\s-+\\([0-9]+-[0-9]+-[0-9]+\\)[^}]*}}\\)"
+    "\\({{Deadline:\\s-+\\([0-9]+\\.[0-9]+\\.[0-9]+\\)[^}]*}}\\)")
+  (if planner-iso8601-dates
   "Regular expression for deadline data.
 The special deadline string should be regexp group 1. The
-date (YYYY.MM.DD) should be regexp group 2."
+date (YYYY-MM-DD) should be regexp group 2."
+    "Regular expression for deadline data.
+The special deadline string should be regexp group 1. The
+date (YYYY.MM.DD) should be regexp group 2.")
   :type 'regexp
   :group 'planner-deadline)
 
diff -wpurNd planner/planner-rdf.el planner/planner-rdf.el
--- planner/planner-rdf.el      2005-07-02 21:18:44.000000000 +1000
+++ planner/planner-rdf.el      2005-07-11 06:47:31.528652112 +1000
@@ -580,7 +580,7 @@ of the standard output to provide custom
 (defun planner-rdf-insert-page-info (name tasks notes)
   "Create a page object."
   (insert "<planner:Page rdf:about=\"" planner-rdf-page-prefix name "\">\n")
-  (let ((type (if (string-match "^[0-9]\\{4\\}\\.[0-9]\\{2\\}\\.[0-9]\\{2\\}" 
name)
+  (let ((type (if (string-match planner-date-regexp name)
                                  planner-rdf-pagetype-day
                                planner-rdf-pagetype-project)))
         (insert "\t<page-type rdf:resource=\"" type "\"/>\n")
@@ -614,7 +614,7 @@ of the standard output to provide custom
         (insert "\t<dc:Title>" (file-name-nondirectory file) "</dc:Title>\n")
         (insert "\t<dc:Identifier>" planner-rdf-base "page-" name 
"</dc:Identifier>\n")
         (insert "\t<dc:Format>text</dc:Format>\n")
-        (if (string-match "^[0-9]\\{4\\}\\.[0-9]\\{2\\}\\.[0-9]\\{2\\}" name)
+        (if (string-match planner-date-regexp name)
                  (progn
                         (insert "\t<dc:Type>" planner-rdf-pagetype-day 
"</dc:Type>\n")
                         (insert 
diff -wpurNd planner/planner-timeclock-summary.el 
planner/planner-timeclock-summary.el
--- planner/planner-timeclock-summary.el        2005-07-10 03:14:47.000000000 
+1000
+++ planner/planner-timeclock-summary.el        2005-07-11 07:13:00.019286216 
+1000
@@ -469,8 +469,9 @@ The section is updated only if it exists
           (insert "* " planner-timeclock-summary-section "\n\n"
                   (if (and thepage (string-match planner-date-regexp thepage))
                       (planner-timeclock-summary-make-text-table-day
-                       (planner-replace-regexp-in-string "\\." "/"
-                                                         thepage t t))
+                       (planner-replace-regexp-in-string
+                       (if planner-iso8601-dates "-""\\.")
+                       "/" thepage t t))
                     (planner-timeclock-summary-make-text-table-day
                      nil nil
                      (concat "^" thepage
@@ -539,8 +540,12 @@ Dates are strings in the form YYYY.MM.DD
               (concat start-date " - " end-date))
             "\n\n"
             (planner-timeclock-summary-make-text-table-day
-             (planner-replace-regexp-in-string "\\." "/" start-date t t)
-             (planner-replace-regexp-in-string "\\." "/" end-date t t)
+             (planner-replace-regexp-in-string 
+             (if planner-iso8601-dates "-" "\\.")
+             "/" start-date t t)
+             (planner-replace-regexp-in-string
+             (if planner-iso8601-dates "-" "\\.")
+             "/" end-date t t)
              filter))
     (planner-mode))
   (goto-char (point-min)))
@@ -678,7 +683,9 @@ given."
     (insert "Timeclock summary report for " date "\n\n")
     (planner-mode)
     (planner-timeclock-summary-make-table-day
-     (planner-replace-regexp-in-string "\\." "/" date t t) (point)))
+     (planner-replace-regexp-in-string 
+      (if planner-iso8601-dates "-" "\\.")
+      "/" date t t) (point)))
   (goto-char (point-min)))
 
 ;; (defun planner-timeclock-summary-table-insert-list (list)
diff -wpurNd planner/planner-trunk.el planner/planner-trunk.el
--- planner/planner-trunk.el    2005-07-02 21:18:45.000000000 +1000
+++ planner/planner-trunk.el    2005-07-11 07:19:52.333604912 +1000
@@ -61,7 +61,9 @@
   :prefix "planner-trunk"
   :group 'planner)
 
-(defcustom planner-trunk-rule-list  
`(("`[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]'" nil
+(defcustom planner-trunk-rule-list  `((,(if planner-iso8601-dates
+                                           
"`[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'"
+                                         
"`[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]'") nil
                                       ("HomeWork" "WorkStuff"
                                        "EmacsHack\\|PlannerHack")))
   "List of rules for trunking tasks.
@@ -105,6 +107,8 @@ use, it will become obvious why this is 
                   (choice :tag "Page regexp"
                           (const 
"`[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]'"
                                  :tag "Day pages")
+                          (const "`[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'"
+                                 :tag "Day pages (ISO8601 format)")
                           (const "." :tag "All pages")
                           (regexp :tag "Regexp"))
                   (choice
diff -wpurNd planner/planner.el planner/planner.el
--- planner/planner.el  2005-07-10 03:14:48.000000000 +1000
+++ planner/planner.el  2005-07-11 08:00:02.081267584 +1000
@@ -601,6 +601,11 @@ If you change this, also change `planner
   :group 'planner-tasks
   :type 'boolean)
 
+(defcustom planner-iso8601-dates t
+  "Non-nil means planner expects dates in YYYY-MM-DD format rather than 
YYYY.MM.DD."
+  :group 'planner
+  :type 'boolean)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Emacs-wiki options
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -612,8 +617,11 @@ If you change this, also change `planner
 
 (defcustom planner-name-regexp
   (when planner-use-day-pages
+    (if planner-iso8601-dates
+       (concat "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]#[A-Za-z0-9_%]+"
+               "\\|[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]")
     (concat "[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]#[A-Za-z0-9_%]+"
-            "\\|[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]"))
+             "\\|[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]")))
   "A regexp used to match planner references in a planning buffer."
   :type 'regexp
   :set 'planner-option-customized
@@ -1136,7 +1144,9 @@ instead of a string."
     (kill-buffer (current-buffer))))
 
 (defvar planner-date-regexp
-  "\\`\\([1-9][0-9][0-9][0-9]\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\'")
+  (if planner-iso8601-dates
+      "\\`\\([1-9][0-9][0-9][0-9]\\)-\\([0-9]+\\)-\\([0-9]+\\)\\'"
+    "\\`\\([1-9][0-9][0-9][0-9]\\)\\.\\([0-9]+\\)\\.\\([0-9]+\\)\\'"))
 
 (defun planner-prepare-file ()
   "Insert some standard sections into an empty planner file."
@@ -1277,7 +1287,9 @@ If PROMPT is non-nil, display it as the 
                              (format "%s %s"
                                      (or prompt "When")
                                      (format-time-string
-                                      "(%Y.%m.%d, %m.%d, %d): ")))))
+                                     (if planner-iso8601-dates
+                                         "(%Y-%m-%d, %m-%d, %d): "
+                                       "(%Y.%m.%d, %m.%d, %d): "))))))
                   (or planner-calendar-selected-date
                       (with-current-buffer old-buffer (planner-expand-name 
text)))))
             (setq calendar-mode-map old-map)))))))
@@ -1304,10 +1316,11 @@ Should be a string of the form YYYY.MM.D
   "Return the planner filename corresponding to DATE.
 DATE is a list (month day year) or an internal date representation."
   (if (= (length date) 3)
-      (format "%04d.%02d.%02d" (elt date 2) (elt date 0) (elt date 1))
+      (format (if planner-iso8601-dates "%04d-%02d-%02d" "%04d.%02d.%02d")
+             (elt date 2) (elt date 0) (elt date 1))
     (if (= (length date) 2)
         (setq date (decode-time date)))
-    (format "%04d.%02d.%02d"
+    (format (if planner-iso8601-dates "%04d-%02d-%02d" "%04d.%02d.%02d")
             (elt date 5) ; year
             (elt date 4) ; month
             (elt date 3)))) ; day
@@ -1413,9 +1426,14 @@ defaults."
     (cond
      ((string= "nil" name) nil)
      ((string= "." name) (planner-today))
-     ((string-match (concat "^\\([1-9][0-9][0-9][0-9]\\.\\)?"
+     ((string-match 
+       (if planner-iso8601-dates
+          (concat "^\\([1-9][0-9][0-9][0-9]-\\)?"
+                  "\\(\\([0-9]+\\)-\\)?"
+                  "\\([0-9]+\\)\\(#.*\\)?$")
+        (concat "^\\([1-9][0-9][0-9][0-9]\\.\\)?"
                             "\\(\\([0-9]+\\)\\.\\)?"
-                            "\\([0-9]+\\)\\(#.*\\)?$") name)
+                "\\([0-9]+\\)\\(#.*\\)?$")) name)
       (setq name-year
             (if (match-string 1 name)
                 (string-to-number (match-string 1 name)) (nth 2 now)))
@@ -1452,7 +1470,9 @@ defaults."
         (string-match (concat
                        "^\\([-+]\\)\\s-*\\([0-9]*\\)\\s-*\\("
                        (mapconcat 'car planner-expand-name-days-alist "\\|")
-                       
"\\)\\s-*\\(\\.\\|\\(\\(\\([0-9]+\\.\\)?[0-9]+\\.\\)?[0-9]+\\)\\)?$")
+                      (if planner-iso8601-dates 
+                          
"\\)\\s-*\\(-\\|\\(\\(\\([0-9]+-\\)?[0-9]+-\\)?[0-9]+\\)\\)?$"
+                        
"\\)\\s-*\\(\\.\\|\\(\\(\\([0-9]+\\.\\)?[0-9]+\\.\\)?[0-9]+\\)\\)?$"))
                       name))
       (let* ((day (cdr (assoc (match-string 3 name)
                               planner-expand-name-days-alist)))
@@ -1766,7 +1786,8 @@ If nil, no actions will be taken."
   :group 'planner-tasks
   :type 'boolean)
 
-(defcustom planner-sort-undated-tasks-equivalent "9999.99.99"
+(defcustom planner-sort-undated-tasks-equivalent
+  (if planner-iso8601-dates "9999-99-99" "9999.99.99")
   "Date considered for undated tasks.
 This option controls task sorting on plan pages.  By default,
 undated tasks are sorted after dated tasks."
@@ -1774,6 +1795,7 @@ undated tasks are sorted after dated tas
   :type
   '(choice
     (const :tag "Sort undated tasks after dated tasks" "9999.99.99")
+    (const :tag "Sort undated tasks after dated tasks (ISO 8601 format)" 
"9999-99-99")
     (const :tag "Sort undated tasks before dated tasks" "")
     string))
 
-- 
Trent Buck, Student Errant

reply via email to

[Prev in Thread] Current Thread [Next in Thread]