]> code.delx.au - gnu-emacs-elpa/commitdiff
tiny.el (tiny-date): improve
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 5 Dec 2014 10:48:48 +0000 (11:48 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 5 Dec 2014 10:48:48 +0000 (11:48 +0100)
* tiny.el (tiny-date): Will recognize e.g. "Mon" and "Mon 10:00" and
  format appropriately.

tiny.el

diff --git a/tiny.el b/tiny.el
index 339389c1d53fd2c6f6ce708d586b4d54cba90239..4d95438d36cd77abcf9aae94892bda992bdedb27 100644 (file)
--- a/tiny.el
+++ b/tiny.el
@@ -391,13 +391,19 @@ Return nil if nothing was matched, otherwise
   "Return date representation of S.
 `org-mode' format is used.
 Optional SHIFT argument is the integer amount of days to shift."
-  (let ((time (apply 'encode-time
-                     (org-read-date-analyze
-                      s nil
-                      (decode-time (current-time))))))
+  (let* ((ct (decode-time (current-time)))
+         (time (apply 'encode-time
+                      (org-read-date-analyze
+                       s nil
+                       ct)))
+         (formatter
+          (if (equal (cl-subseq ct 1 3)
+                     (cl-subseq (decode-time time) 1 3))
+              "%Y-%m-%d %a"
+            "%Y-%m-%d %a %H:%M")))
     (when shift
       (setq time (time-add time (days-to-time shift))))
-    (format-time-string "%Y-%m-%d %a" time)))
+    (format-time-string formatter time)))
 
 (provide 'tiny)
 ;;; tiny.el ends here