emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [new exporter] adhere org-export-date-timestamp-format?
@ 2012-11-18 14:43 Rasmus
  2012-12-24  1:50 ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Rasmus @ 2012-11-18 14:43 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Would it be desirable if the new exporter took the variable
org-export-date-timestamp-format into consideration when formatting
dates?  Or is there another way of dealing with the formatting of
dates?

┏━━━┫  org-export-date-timestamp-format ~"%Y-%m-%d"~ ┃
┃     Type: string
┃     Since: Emacs version 24.1
┃     In file: org-exp.el 
┃     Time string format for Org timestamps in the #+DATE option.
┗━━━

Here's the relevant snip for org-exp. 

 ((string-equal key "DATE")
  ;; If date is an Org timestamp, convert it to a time
  ;; string using `org-export-date-timestamp-format'
  (when (string-match org-ts-regexp3 val)
    (setq val (format-time-string
               org-export-date-timestamp-format
               (apply 'encode-time (org-parse-time-string
                                    (match-string 0 val))))))
  (setq p (plist-put p :date val)))

Example:

#+BEGIN_SRC org
#+DATE: <2012-11-18 Sun>
* test
#+END_SRC

Date is exported as \date{<2012-11-18 Sun>} with the new exporter and
\date{2012-11-18} with the old exporter (using emacs -q).

Thanks,
Rasmus

-- 
El Rey ha muerto. ¡Larga vida al Rey!

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2012-11-18 14:43 [new exporter] adhere org-export-date-timestamp-format? Rasmus
@ 2012-12-24  1:50 ` Bastien
  2013-01-06 10:00   ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2012-12-24  1:50 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hi Rasmus,

Rasmus <rasmus@gmx.us> writes:

> Would it be desirable if the new exporter took the variable
> org-export-date-timestamp-format into consideration when formatting
> dates?  

I think so.  What do you think, Nicolas?

-- 
 Bastien

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2012-12-24  1:50 ` Bastien
@ 2013-01-06 10:00   ` Nicolas Goaziou
  2013-01-06 11:45     ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-01-06 10:00 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

Hello,

Bastien <bzg@altern.org> writes:

> Rasmus <rasmus@gmx.us> writes:
>
>> Would it be desirable if the new exporter took the variable
>> org-export-date-timestamp-format into consideration when formatting
>> dates?  
>
> I think so.  What do you think, Nicolas?

I'm not convinced by this variable. Back-ends are usually so much
different that a global variable aiming at formatting a date timestamp
in any of them doesn't sound very useful.

Though it may be the job of back-ends to provide such a variable
variable, whenever it makes sense.

Another option would be to allow to specify an arbitrary timestamp as
a second, optional, argument to {{{time(...)}}} macro. One could then
use:

  #+DATE: {{{time(%Y-%m-%d,<2013-01-06 Sun>)}}}


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-06 10:00   ` Nicolas Goaziou
@ 2013-01-06 11:45     ` Bastien
  2013-01-09 15:29       ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2013-01-06 11:45 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi Nicolas,

thanks for looking into this.

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> I'm not convinced by this variable. Back-ends are usually so much
> different that a global variable aiming at formatting a date timestamp
> in any of them doesn't sound very useful.
>
> Though it may be the job of back-ends to provide such a variable
> variable, whenever it makes sense.

Yes, I think it's the job of backends.

> Another option would be to allow to specify an arbitrary timestamp as
> a second, optional, argument to {{{time(...)}}} macro. One could then
> use:
>
>   #+DATE: {{{time(%Y-%m-%d,<2013-01-06 Sun>)}}}

I'm all for allowing macros in "document info" keywords
(i.e. "#+title:" "#+author:" "#+email:" "#+date) though 
I'm not sure if it makes sense for other keywords than
for "#+date", and maybe allowing macro here just for
this use-case is to liberal.

Best,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-06 11:45     ` Bastien
@ 2013-01-09 15:29       ` Nicolas Goaziou
  2013-01-09 17:15         ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-01-09 15:29 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

Hello,

Bastien <bzg@altern.org> writes:

>> Though it may be the job of back-ends to provide such a variable
>> variable, whenever it makes sense.
>
> Yes, I think it's the job of backends.

For example, in the `e-latex' back-end, there is
`org-e-latex-date-format'.

Should the value of the variable be used as an argument for
`org-export-format-timestamp' if the #+DATE: keyword only contains
a timestamp object, and for `format-time-string' otherwise?

>> Another option would be to allow to specify an arbitrary timestamp as
>> a second, optional, argument to {{{time(...)}}} macro. One could then
>> use:
>>
>>   #+DATE: {{{time(%Y-%m-%d,<2013-01-06 Sun>)}}}
>
> I'm all for allowing macros in "document info" keywords
> (i.e. "#+title:" "#+author:" "#+email:" "#+date) though 
> I'm not sure if it makes sense for other keywords than
> for "#+date", and maybe allowing macro here just for
> this use-case is to liberal.

Note that macros are already supported there (as in anything that will
be parsed).


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-09 15:29       ` Nicolas Goaziou
@ 2013-01-09 17:15         ` Bastien
  2013-01-09 18:03           ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2013-01-09 17:15 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> For example, in the `e-latex' back-end, there is
> `org-e-latex-date-format'.
>
> Should the value of the variable be used as an argument for
> `org-export-format-timestamp' if the #+DATE: keyword only contains
> a timestamp object, and for `format-time-string' otherwise?

Yes, good idea!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-09 17:15         ` Bastien
@ 2013-01-09 18:03           ` Nicolas Goaziou
  2013-01-09 18:30             ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-01-09 18:03 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

Bastien <bzg@altern.org> writes:

>> Should the value of the variable be used as an argument for
>> `org-export-format-timestamp' if the #+DATE: keyword only contains
>> a timestamp object, and for `format-time-string' otherwise?
>
> Yes, good idea!

Ok.

Before I start coding it, I wonder if functions related to timestamp
objects, that is `org-export-timestamp-has-time-p',
`org-export-format-timestamp', `org-export-split-timestamp-range' and
`org-export-translate-timestamp' shouldn't be moved from org-export.el
to org.el. After all, there are not only useful in an export context.

What do you think about it?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-09 18:03           ` Nicolas Goaziou
@ 2013-01-09 18:30             ` Bastien
  2013-01-12 11:30               ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2013-01-09 18:30 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Before I start coding it, I wonder if functions related to timestamp
> objects, that is `org-export-timestamp-has-time-p',
> `org-export-format-timestamp', `org-export-split-timestamp-range' and
> `org-export-translate-timestamp' shouldn't be moved from org-export.el
> to org.el. After all, there are not only useful in an export context.
>
> What do you think about it?

I agree they are general and should be move out of org-export.el.

Note that one of my plan for 8.[01] is to put org.el on diet so that
it loads more quickly and for more basic stuff.  So maybe there will
be org-plan.el at some point for org-schedule, org-deadline and 
anything related to planning.  Ideally, Org would *just* be outline
reloaded (with orgtble and all editing facilities), while other
features would have their own library.  So maybe those functions
will end up outside of org.el one day... but I'd say it's okay
to have them in org.el for now.

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-09 18:30             ` Bastien
@ 2013-01-12 11:30               ` Nicolas Goaziou
  2013-01-12 14:45                 ` Bastien
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-01-12 11:30 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

[-- Attachment #1: Type: text/plain, Size: 1045 bytes --]

Bastien <bzg@altern.org> writes:

> I agree they are general and should be move out of org-export.el.
>
> Note that one of my plan for 8.[01] is to put org.el on diet so that
> it loads more quickly and for more basic stuff.  So maybe there will
> be org-plan.el at some point for org-schedule, org-deadline and 
> anything related to planning.  Ideally, Org would *just* be outline
> reloaded (with orgtble and all editing facilities), while other
> features would have their own library.  So maybe those functions
> will end up outside of org.el one day... but I'd say it's okay
> to have them in org.el for now.

The attached patch moves them into org.el, with an org-timestamp-
prefix.

Though, I think I have to withdraw my proposal about using #+DATE: value
as a time format string. Indeed, date value, along with any document
property, is parsed, which defeats the purpose of using it as a format
string.

We can still implement a convenient macro to handle timestamps in date
keyword.

What do you think?


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-functions-operating-on-timestamp-objects-into-o.patch --]
[-- Type: text/x-patch, Size: 23761 bytes --]

From 564dbaa3f7a694c2b46074e7ccc529a310ad5b7d Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Thu, 10 Jan 2013 21:42:21 +0100
Subject: [PATCH] Move functions operating on timestamp objects into org.el

* contrib/lisp/org-export.el (org-export-timestamp-has-time-p,
  org-export-format-timestamp, org-export-split-timestamp-range,
  org-export-translate-timestamp): Removed functions.
* lisp/org.el (org-timestamp-has-time-p, org-timestamp-format,
  org-timestamp-split-range, org-timestamp-translate): New functions.
* contrib/lisp/org-e-ascii.el (org-e-ascii-timestamp): Apply move.
* contrib/lisp/org-e-groff.el (org-e-groff-timestamp): Apply move.
* contrib/lisp/org-e-html.el (org-e-html-timestamp): Apply move.
* contrib/lisp/org-e-latex.el (org-e-latex-timestamp): Apply move.
* contrib/lisp/org-e-odt.el (org-e-odt--format-timestamp,
  org-e-odt-timestamp): Apply move.
* contrib/lisp/org-e-texinfo.el (org-e-texinfo-timestamp): Apply move.
* testing/lisp/test-org-export.el: Remove tests.
* testing/lisp/test-org.el: Add tests.
---
 contrib/lisp/org-e-ascii.el     |   2 +-
 contrib/lisp/org-e-groff.el     |   2 +-
 contrib/lisp/org-e-html.el      |   2 +-
 contrib/lisp/org-e-latex.el     |   2 +-
 contrib/lisp/org-e-odt.el       |  10 ++--
 contrib/lisp/org-e-texinfo.el   |   2 +-
 contrib/lisp/org-export.el      |  90 ----------------------------
 lisp/org.el                     |  88 ++++++++++++++++++++++++++++
 testing/lisp/test-org-export.el | 126 ----------------------------------------
 testing/lisp/test-org.el        | 126 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 224 insertions(+), 226 deletions(-)

diff --git a/contrib/lisp/org-e-ascii.el b/contrib/lisp/org-e-ascii.el
index 4499de5..7bfc4c2 100644
--- a/contrib/lisp/org-e-ascii.el
+++ b/contrib/lisp/org-e-ascii.el
@@ -1706,7 +1706,7 @@ a communication channel."
 (defun org-e-ascii-timestamp (timestamp contents info)
   "Transcode a TIMESTAMP object from Org to ASCII.
 CONTENTS is nil.  INFO is a plist holding contextual information."
-  (org-e-ascii-plain-text (org-export-translate-timestamp timestamp) info))
+  (org-e-ascii-plain-text (org-timestamp-translate timestamp) info))
 
 
 ;;;; Underline
diff --git a/contrib/lisp/org-e-groff.el b/contrib/lisp/org-e-groff.el
index e91de34..c7fbeac 100644
--- a/contrib/lisp/org-e-groff.el
+++ b/contrib/lisp/org-e-groff.el
@@ -1852,7 +1852,7 @@ information."
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (let ((value (org-e-groff-plain-text
-		(org-export-translate-timestamp timestamp) info)))
+		(org-timestamp-translate timestamp) info)))
     (case (org-element-property :type timestamp)
       ((active active-range)
        (format org-e-groff-active-timestamp-format value))
diff --git a/contrib/lisp/org-e-html.el b/contrib/lisp/org-e-html.el
index 7a37d29..ab46e2a 100644
--- a/contrib/lisp/org-e-html.el
+++ b/contrib/lisp/org-e-html.el
@@ -2684,7 +2684,7 @@ information."
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (let ((value (org-e-html-plain-text
-		(org-export-translate-timestamp timestamp) info)))
+		(org-timestamp-translate timestamp) info)))
     (format "<span class=\"timestamp-wrapper\"><span class=\"timestamp\">%s</span></span>"
 	    (replace-regexp-in-string "--" "&ndash;" value))))
 
diff --git a/contrib/lisp/org-e-latex.el b/contrib/lisp/org-e-latex.el
index 7d165d3..6ac8e86 100644
--- a/contrib/lisp/org-e-latex.el
+++ b/contrib/lisp/org-e-latex.el
@@ -2597,7 +2597,7 @@ information."
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (let ((value (org-e-latex-plain-text
-		(org-export-translate-timestamp timestamp) info)))
+		(org-timestamp-translate timestamp) info)))
     (case (org-element-property :type timestamp)
       ((active active-range) (format org-e-latex-active-timestamp-format value))
       ((inactive inactive-range)
diff --git a/contrib/lisp/org-e-odt.el b/contrib/lisp/org-e-odt.el
index ded4b02..7ba2d9d 100644
--- a/contrib/lisp/org-e-odt.el
+++ b/contrib/lisp/org-e-odt.el
@@ -909,10 +909,10 @@ See `org-e-odt--build-date-styles' for implementation details."
   (let* ((format-timestamp
 	  (lambda (timestamp format &optional end utc)
 	    (if timestamp
-		(org-export-format-timestamp timestamp format end utc)
+		(org-timestamp-format timestamp format end utc)
 	      (format-time-string format nil utc))))
 	 (has-time-p (or (not timestamp)
-			 (org-export-timestamp-has-time-p timestamp)))
+			 (org-timestamp-has-time-p timestamp)))
 	 (iso-date (let ((format (if has-time-p "%Y-%m-%dT%H:%M:%S"
 				   "%Y-%m-%dT%H:%M:%S")))
 		     (funcall format-timestamp timestamp format end))))
@@ -3632,7 +3632,7 @@ channel."
   	 (type (org-element-property :type timestamp)))
     (if (not org-e-odt-use-date-fields)
 	(let ((value (org-e-odt-plain-text
-		      (org-export-translate-timestamp timestamp) info)))
+		      (org-timestamp-translate timestamp) info)))
 	  (case (org-element-property :type timestamp)
 	    ((active active-range)
 	     (format "<text:span text:style-name=\"%s\">%s</text:span>"
@@ -3665,8 +3665,8 @@ channel."
 	(otherwise
 	 (format "<text:span text:style-name=\"%s\">%s</text:span>"
 		 "OrgDiaryTimestamp"
-		 (org-e-odt-plain-text (org-export-translate-timestamp
-					timestamp) info)))))))
+		 (org-e-odt-plain-text (org-timestamp-translate timestamp)
+				       info)))))))
 
 
 ;;;; Underline
diff --git a/contrib/lisp/org-e-texinfo.el b/contrib/lisp/org-e-texinfo.el
index 52d7e96..a14998c 100644
--- a/contrib/lisp/org-e-texinfo.el
+++ b/contrib/lisp/org-e-texinfo.el
@@ -1623,7 +1623,7 @@ information."
 CONTENTS is nil.  INFO is a plist holding contextual
 information."
   (let ((value (org-e-texinfo-plain-text
-		(org-export-translate-timestamp timestamp) info)))
+		(org-timestamp-translate timestamp) info)))
     (case (org-element-property :type timestamp)
       ((active active-range)
        (format org-e-texinfo-active-timestamp-format value))
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 5b71ef4..067abe1 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -4433,96 +4433,6 @@ 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))
-
-(defun org-export-split-timestamp-range (timestamp &optional end)
-  "Extract a timestamp object from a date or time range.
-
-TIMESTAMP is a timestamp object. END, when non-nil, means extract
-the end of the range.  Otherwise, extract its start.
-
-Return a new timestamp object sharing the same parent as
-TIMESTAMP."
-  (let ((type (org-element-property :type timestamp)))
-    (if (memq type '(active inactive diary)) timestamp
-      (let ((split-ts (list 'timestamp (copy-sequence (nth 1 timestamp)))))
-	;; Set new type.
-	(org-element-put-property
-	 split-ts :type (if (eq type 'active-range) 'active 'inactive))
-	;; Copy start properties over end properties if END is
-	;; non-nil.  Otherwise, copy end properties over `start' ones.
-	(let ((p-alist '((:minute-start . :minute-end)
-			 (:hour-start . :hour-end)
-			 (:day-start . :day-end)
-			 (:month-start . :month-end)
-			 (:year-start . :year-end))))
-	  (dolist (p-cell p-alist)
-	    (org-element-put-property
-	     split-ts
-	     (funcall (if end 'car 'cdr) p-cell)
-	     (org-element-property
-	      (funcall (if end 'cdr 'car) p-cell) split-ts)))
-	  ;; Eventually refresh `:raw-value'.
-	  (org-element-put-property split-ts :raw-value nil)
-	  (org-element-put-property
-	   split-ts :raw-value (org-element-interpret-data split-ts)))))))
-
-(defun org-export-translate-timestamp (timestamp &optional boundary)
-  "Apply `org-translate-time' on a TIMESTAMP object.
-When optional argument BOUNDARY is non-nil, it is either the
-symbol `start' or `end'.  In this case, only translate the
-starting or ending part of TIMESTAMP if it is a date or time
-range.  Otherwise, translate both parts."
-  (if (and (not boundary)
-	   (memq (org-element-property :type timestamp)
-		 '(active-range inactive-range)))
-      (concat
-       (org-translate-time
-	(org-element-property :raw-value
-			      (org-export-split-timestamp-range timestamp)))
-       "--"
-       (org-translate-time
-	(org-element-property :raw-value
-			      (org-export-split-timestamp-range timestamp t))))
-    (org-translate-time
-     (org-element-property
-      :raw-value
-      (if (not boundary) timestamp
-	(org-export-split-timestamp-range timestamp (eq boundary 'end)))))))
-
-
 ;;;; Smart Quotes
 ;;
 ;; The main function for the smart quotes sub-system is
diff --git a/lisp/org.el b/lisp/org.el
index 1c2ee9a..f3f7901 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -21859,6 +21859,94 @@ contains commented lines.  Otherwise, comment them."
 	      (forward-line))))))))
 
 
+;;; Planning
+
+;; This section contains tools to operate on timestamp objects, as
+;; returned by, e.g. `org-element-context'.
+
+(defun org-timestamp-has-time-p (timestamp)
+  "Non-nil when TIMESTAMP has a time specified."
+  (org-element-property :hour-start timestamp))
+
+(defun org-timestamp-format (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))
+
+(defun org-timestamp-split-range (timestamp &optional end)
+  "Extract a timestamp object from a date or time range.
+
+TIMESTAMP is a timestamp object. END, when non-nil, means extract
+the end of the range.  Otherwise, extract its start.
+
+Return a new timestamp object sharing the same parent as
+TIMESTAMP."
+  (let ((type (org-element-property :type timestamp)))
+    (if (memq type '(active inactive diary)) timestamp
+      (let ((split-ts (list 'timestamp (copy-sequence (nth 1 timestamp)))))
+	;; Set new type.
+	(org-element-put-property
+	 split-ts :type (if (eq type 'active-range) 'active 'inactive))
+	;; Copy start properties over end properties if END is
+	;; non-nil.  Otherwise, copy end properties over `start' ones.
+	(let ((p-alist '((:minute-start . :minute-end)
+			 (:hour-start . :hour-end)
+			 (:day-start . :day-end)
+			 (:month-start . :month-end)
+			 (:year-start . :year-end))))
+	  (dolist (p-cell p-alist)
+	    (org-element-put-property
+	     split-ts
+	     (funcall (if end 'car 'cdr) p-cell)
+	     (org-element-property
+	      (funcall (if end 'cdr 'car) p-cell) split-ts)))
+	  ;; Eventually refresh `:raw-value'.
+	  (org-element-put-property split-ts :raw-value nil)
+	  (org-element-put-property
+	   split-ts :raw-value (org-element-interpret-data split-ts)))))))
+
+(defun org-timestamp-translate (timestamp &optional boundary)
+  "Apply `org-translate-time' on a TIMESTAMP object.
+When optional argument BOUNDARY is non-nil, it is either the
+symbol `start' or `end'.  In this case, only translate the
+starting or ending part of TIMESTAMP if it is a date or time
+range.  Otherwise, translate both parts."
+  (if (and (not boundary)
+	   (memq (org-element-property :type timestamp)
+		 '(active-range inactive-range)))
+      (concat
+       (org-translate-time
+	(org-element-property :raw-value
+			      (org-timestamp-split-range timestamp)))
+       "--"
+       (org-translate-time
+	(org-element-property :raw-value
+			      (org-timestamp-split-range timestamp t))))
+    (org-translate-time
+     (org-element-property
+      :raw-value
+      (if (not boundary) timestamp
+	(org-timestamp-split-range timestamp (eq boundary 'end)))))))
+
+
+
 ;;; Other stuff.
 
 (defun org-toggle-fixed-width-section (arg)
diff --git a/testing/lisp/test-org-export.el b/testing/lisp/test-org-export.el
index f4ac5a3..1152940 100644
--- a/testing/lisp/test-org-export.el
+++ b/testing/lisp/test-org-export.el
@@ -2079,132 +2079,6 @@ Another text. (ref:text)
 
 
 \f
-;;; 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)))))
-
-(ert-deftest test-org-export/split-timestamp-range ()
-  "Test `org-export-split-timestamp-range' specifications."
-  ;; Extract range start (active).
-  (should
-   (equal '(2012 3 29)
-	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
-	    (let ((ts (org-export-split-timestamp-range (org-element-context))))
-	      (mapcar (lambda (p) (org-element-property p ts))
-		      '(:year-end :month-end :day-end))))))
-  ;; Extract range start (inactive)
-  (should
-   (equal '(2012 3 29)
-	  (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
-	    (let ((ts (org-export-split-timestamp-range (org-element-context))))
-	      (mapcar (lambda (p) (org-element-property p ts))
-		      '(:year-end :month-end :day-end))))))
-  ;; Extract range end (active).
-  (should
-   (equal '(2012 3 30)
-	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
-	    (let ((ts (org-export-split-timestamp-range
-		       (org-element-context) t)))
-	      (mapcar (lambda (p) (org-element-property p ts))
-		      '(:year-end :month-end :day-end))))))
-  ;; Extract range end (inactive)
-  (should
-   (equal '(2012 3 30)
-	  (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
-	    (let ((ts (org-export-split-timestamp-range
-		       (org-element-context) t)))
-	      (mapcar (lambda (p) (org-element-property p ts))
-		      '(:year-end :month-end :day-end))))))
-  ;; Return the timestamp if not a range.
-  (should
-   (org-test-with-temp-text "[2012-03-29 Thu]"
-     (let* ((ts-orig (org-element-context))
-	    (ts-copy (org-export-split-timestamp-range ts-orig)))
-       (eq ts-orig ts-copy))))
-  (should
-   (org-test-with-temp-text "<%%(org-float t 4 2)>"
-     (let* ((ts-orig (org-element-context))
-	    (ts-copy (org-export-split-timestamp-range ts-orig)))
-       (eq ts-orig ts-copy))))
-  ;; Check that parent is the same when a range was split.
-  (should
-   (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
-     (let* ((ts-orig (org-element-context))
-	    (ts-copy (org-export-split-timestamp-range ts-orig)))
-       (eq (org-element-property :parent ts-orig)
-	   (org-element-property :parent ts-copy))))))
-
-(ert-deftest test-org-export/translate-timestamp ()
-  "Test `org-export-translate-timestamp' specifications."
-  ;; Translate whole date range.
-  (should
-   (equal "<29>--<30>"
-	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
-	      (org-export-translate-timestamp (org-element-context))))))
-  ;; Translate date range start.
-  (should
-   (equal "<29>"
-	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
-	      (org-export-translate-timestamp (org-element-context) 'start)))))
-  ;; Translate date range end.
-  (should
-   (equal "<30>"
-	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
-	      (org-export-translate-timestamp (org-element-context) 'end)))))
-  ;; Translate time range.
-  (should
-   (equal "<08>--<16>"
-	  (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
-	      (org-export-translate-timestamp (org-element-context))))))
-  ;; Translate non-range timestamp.
-  (should
-   (equal "<29>"
-	  (org-test-with-temp-text "<2012-03-29 Thu>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
-	      (org-export-translate-timestamp (org-element-context))))))
-  ;; Do not change `diary' timestamps.
-  (should
-   (equal "<%%(org-float t 4 2)>"
-	  (org-test-with-temp-text "<%%(org-float t 4 2)>"
-	    (let ((org-display-custom-times t)
-		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
-	      (org-export-translate-timestamp (org-element-context)))))))
-
-
-\f
 ;;; Topology
 
 (ert-deftest test-org-export/get-next-element ()
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 10fedd7..fed6882 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -893,6 +893,132 @@ Text.
 
 
 \f
+;;; Planning
+
+(ert-deftest test-org/timestamp-has-time-p ()
+  "Test `org-timestamp-has-time-p' specifications."
+  ;; With time.
+  (should
+   (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
+     (org-timestamp-has-time-p (org-element-context))))
+  ;; Without time.
+  (should-not
+   (org-test-with-temp-text "<2012-03-29 Thu>"
+     (org-timestamp-has-time-p (org-element-context)))))
+
+(ert-deftest test-org/timestamp-format ()
+  "Test `org-timestamp-format' specifications."
+  ;; Regular test.
+  (should
+   (equal
+    "2012-03-29 16:40"
+    (org-test-with-temp-text "<2012-03-29 Thu 16:40>"
+      (org-timestamp-format (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-timestamp-format (org-element-context) "%Y-%m-%d" t)))))
+
+(ert-deftest test-org/timestamp-split-range ()
+  "Test `org-timestamp-split-range' specifications."
+  ;; Extract range start (active).
+  (should
+   (equal '(2012 3 29)
+	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
+	    (let ((ts (org-timestamp-split-range (org-element-context))))
+	      (mapcar (lambda (p) (org-element-property p ts))
+		      '(:year-end :month-end :day-end))))))
+  ;; Extract range start (inactive)
+  (should
+   (equal '(2012 3 29)
+	  (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
+	    (let ((ts (org-timestamp-split-range (org-element-context))))
+	      (mapcar (lambda (p) (org-element-property p ts))
+		      '(:year-end :month-end :day-end))))))
+  ;; Extract range end (active).
+  (should
+   (equal '(2012 3 30)
+	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
+	    (let ((ts (org-timestamp-split-range
+		       (org-element-context) t)))
+	      (mapcar (lambda (p) (org-element-property p ts))
+		      '(:year-end :month-end :day-end))))))
+  ;; Extract range end (inactive)
+  (should
+   (equal '(2012 3 30)
+	  (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
+	    (let ((ts (org-timestamp-split-range
+		       (org-element-context) t)))
+	      (mapcar (lambda (p) (org-element-property p ts))
+		      '(:year-end :month-end :day-end))))))
+  ;; Return the timestamp if not a range.
+  (should
+   (org-test-with-temp-text "[2012-03-29 Thu]"
+     (let* ((ts-orig (org-element-context))
+	    (ts-copy (org-timestamp-split-range ts-orig)))
+       (eq ts-orig ts-copy))))
+  (should
+   (org-test-with-temp-text "<%%(org-float t 4 2)>"
+     (let* ((ts-orig (org-element-context))
+	    (ts-copy (org-timestamp-split-range ts-orig)))
+       (eq ts-orig ts-copy))))
+  ;; Check that parent is the same when a range was split.
+  (should
+   (org-test-with-temp-text "[2012-03-29 Thu]--[2012-03-30 Fri]"
+     (let* ((ts-orig (org-element-context))
+	    (ts-copy (org-timestamp-split-range ts-orig)))
+       (eq (org-element-property :parent ts-orig)
+	   (org-element-property :parent ts-copy))))))
+
+(ert-deftest test-org/timestamp-translate ()
+  "Test `org-timestamp-translate' specifications."
+  ;; Translate whole date range.
+  (should
+   (equal "<29>--<30>"
+	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
+	      (org-timestamp-translate (org-element-context))))))
+  ;; Translate date range start.
+  (should
+   (equal "<29>"
+	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
+	      (org-timestamp-translate (org-element-context) 'start)))))
+  ;; Translate date range end.
+  (should
+   (equal "<30>"
+	  (org-test-with-temp-text "<2012-03-29 Thu>--<2012-03-30 Fri>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
+	      (org-timestamp-translate (org-element-context) 'end)))))
+  ;; Translate time range.
+  (should
+   (equal "<08>--<16>"
+	  (org-test-with-temp-text "<2012-03-29 Thu 8:30-16:40>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%H>")))
+	      (org-timestamp-translate (org-element-context))))))
+  ;; Translate non-range timestamp.
+  (should
+   (equal "<29>"
+	  (org-test-with-temp-text "<2012-03-29 Thu>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
+	      (org-timestamp-translate (org-element-context))))))
+  ;; Do not change `diary' timestamps.
+  (should
+   (equal "<%%(org-float t 4 2)>"
+	  (org-test-with-temp-text "<%%(org-float t 4 2)>"
+	    (let ((org-display-custom-times t)
+		  (org-time-stamp-custom-formats '("<%d>" . "<%d>")))
+	      (org-timestamp-translate (org-element-context)))))))
+
+
+\f
 ;;; Targets and Radio Targets
 
 (ert-deftest test-org/all-targets ()
-- 
1.8.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-12 11:30               ` Nicolas Goaziou
@ 2013-01-12 14:45                 ` Bastien
  2013-01-30 21:53                   ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Bastien @ 2013-01-12 14:45 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode, Rasmus

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> The attached patch moves them into org.el, with an org-timestamp-
> prefix.

Looks, good, please go ahead.

> Though, I think I have to withdraw my proposal about using #+DATE: value
> as a time format string. Indeed, date value, along with any document
> property, is parsed, which defeats the purpose of using it as a format
> string.
>
> We can still implement a convenient macro to handle timestamps in date
> keyword.
>
> What do you think?

Up to whatever you find more practical.

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-12 14:45                 ` Bastien
@ 2013-01-30 21:53                   ` Nicolas Goaziou
  2013-01-30 23:54                     ` Rasmus
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Goaziou @ 2013-01-30 21:53 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Rasmus

Hello,

Bastien <bzg@altern.org> writes:

>> Though, I think I have to withdraw my proposal about using #+DATE: value
>> as a time format string. Indeed, date value, along with any document
>> property, is parsed, which defeats the purpose of using it as a format
>> string.
>>
>> We can still implement a convenient macro to handle timestamps in date
>> keyword.
>>
>> What do you think?
>
> Up to whatever you find more practical.

I have added `org-e-latex-date-format', which can be set to a time
format string. When the #+DATE: value consists in a single timestamp, it
will be applied to format that timestamp. Otherwise it will be ignored.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [new exporter] adhere org-export-date-timestamp-format?
  2013-01-30 21:53                   ` Nicolas Goaziou
@ 2013-01-30 23:54                     ` Rasmus
  0 siblings, 0 replies; 12+ messages in thread
From: Rasmus @ 2013-01-30 23:54 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:
q
> Hello,
>
> Bastien <bzg@altern.org> writes:
>
>>> Though, I think I have to withdraw my proposal about using #+DATE:
>>> value
>>> as a time format string. Indeed, date value, along with any
>>> document
>>> property, is parsed, which defeats the purpose of using it as a
>>> format
>>> string.
>>>
>>> We can still implement a convenient macro to handle timestamps in
>>> date
>>> keyword.
>>>
>>> What do you think?
>>
>> Up to whatever you find more practical.
>
> I have added `org-e-latex-date-format', which can be set to a time
> format string. When the #+DATE: value consists in a single timestamp,
> it
> will be applied to format that timestamp. Otherwise it will be
> ignored.

Very cool!  I'll check it. 

-- 
When the facts change, I change my mind. What do you do, sir?

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-01-30 23:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-18 14:43 [new exporter] adhere org-export-date-timestamp-format? Rasmus
2012-12-24  1:50 ` Bastien
2013-01-06 10:00   ` Nicolas Goaziou
2013-01-06 11:45     ` Bastien
2013-01-09 15:29       ` Nicolas Goaziou
2013-01-09 17:15         ` Bastien
2013-01-09 18:03           ` Nicolas Goaziou
2013-01-09 18:30             ` Bastien
2013-01-12 11:30               ` Nicolas Goaziou
2013-01-12 14:45                 ` Bastien
2013-01-30 21:53                   ` Nicolas Goaziou
2013-01-30 23:54                     ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).