summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-11-19 20:38:16 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-19 20:52:32 (GMT)
commit1a0f8b5c8b49ba59d21fabebf962c47852a5a14b (patch)
treea09ff79f96bbf247635445275ded92b9d1de80ae
parentdadde768f740b79d258e4b1f472aeb5454f38972 (diff)
downloadorg-mode-1a0f8b5c8b49ba59d21fabebf962c47852a5a14b.zip
org-mode-1a0f8b5c8b49ba59d21fabebf962c47852a5a14b.tar.gz
org-export: Add tools for timestamps
* contrib/lisp/org-export.el (org-export-timestamp-has-time-p, org-export-format-timestamp): New functions. * testing/lisp/test-org-export.el: Add tests.
-rw-r--r--contrib/lisp/org-export.el35
-rw-r--r--testing/lisp/test-org-export.el30
2 files changed, 65 insertions, 0 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 59f3f60..1ae5472 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -4278,6 +4278,41 @@ Return a list of src-block elements with a caption."
(org-export-collect-elements 'src-block info))
+;;;; For Timestamps
+;;
+;; `org-export-timestamp-has-time-p' is a predicate to know if hours
+;; and minutes are defined in a given timestamp.
+;;
+;; `org-export-format-timestamp' allows to format a timestamp object
+;; with an arbitrary format string.
+
+(defun org-export-timestamp-has-time-p (timestamp)
+ "Non-nil when TIMESTAMP has a time specified."
+ (org-element-property :hour-start timestamp))
+
+(defun org-export-format-timestamp (timestamp format &optional end utc)
+ "Format a TIMESTAMP element into a string.
+
+FORMAT is a format specifier to be passed to
+`format-time-string'.
+
+When optional argument END is non-nil, use end of date-range or
+time-range, if possible.
+
+When optional argument UTC is non-nil, time will be expressed as
+Universal Time."
+ (format-time-string
+ format
+ (apply 'encode-time
+ (cons 0
+ (mapcar
+ (lambda (prop) (or (org-element-property prop timestamp) 0))
+ (if end '(:minute-end :hour-end :day-end :month-end :year-end)
+ '(:minute-start :hour-start :day-start :month-start
+ :year-start)))))
+ utc))
+
+
;;;; Smart Quotes
;;
;; The main function for the smart quotes sub-system is
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index e049406..18b0103 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -2021,6 +2021,36 @@ Another text. (ref:text)
+;;; Timestamps
+
+(ert-deftest test-org-export/timestamp-has-time-p ()
+ "Test `org-export-timestamp-has-time-p' specifications."
+ ;; With time.
+ (should
+ (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
+ (org-export-timestamp-has-time-p (org-element-context))))
+ ;; Without time.
+ (should-not
+ (org-test-with-temp-text "<2012-03-29 Thu>"
+ (org-export-timestamp-has-time-p (org-element-context)))))
+
+(ert-deftest test-org-export/format-timestamp ()
+ "Test `org-export-format-timestamp' specifications."
+ ;; Regular test.
+ (should
+ (equal
+ "2012-03-29 16:40"
+ (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
+ (org-export-format-timestamp (org-element-context) "%Y-%m-%d %R"))))
+ ;; Range end.
+ (should
+ (equal
+ "2012-03-29"
+ (org-test-with-temp-text "[2011-07-14 Thu]--[2012-03-29 Thu]"
+ (org-export-format-timestamp (org-element-context) "%Y-%m-%d" t)))))
+
+
+
;;; Topology
(ert-deftest test-org-export/get-next-element ()