Function: org-odt--build-date-styles

org-odt--build-date-styles is a byte-compiled function defined in ox-odt.el.gz.

Signature

(org-odt--build-date-styles FMT STYLE)

Source Code

;; Defined in /usr/src/emacs/lisp/org/ox-odt.el.gz
;;; Template

(defun org-odt--build-date-styles (fmt style)
  ;; In LibreOffice 3.4.6, there doesn't seem to be a convenient way
  ;; to modify the date fields.  A date could be modified by
  ;; offsetting in days.  That's about it.  Also, date and time may
  ;; have to be emitted as two fields - a date field and a time field
  ;; - separately.

  ;; One can add Form Controls to date and time fields so that they
  ;; can be easily modified.  But then, the exported document will
  ;; become tightly coupled with LibreOffice and may not function
  ;; properly with other OpenDocument applications.

  ;; I have a strange feeling that Date styles are a bit flaky at the
  ;; moment.

  ;; The feature is experimental.
  (when (and fmt style)
    (let* ((fmt-alist
	    '(("%A" . "<number:day-of-week number:style=\"long\"/>")
	      ("%B" . "<number:month number:textual=\"true\" number:style=\"long\"/>")
	      ("%H" . "<number:hours number:style=\"long\"/>")
	      ("%M" . "<number:minutes number:style=\"long\"/>")
	      ("%S" . "<number:seconds number:style=\"long\"/>")
	      ("%V" . "<number:week-of-year/>")
	      ("%Y" . "<number:year number:style=\"long\"/>")
	      ("%a" . "<number:day-of-week number:style=\"short\"/>")
	      ("%b" . "<number:month number:textual=\"true\" number:style=\"short\"/>")
	      ("%d" . "<number:day number:style=\"long\"/>")
	      ("%e" . "<number:day number:style=\"short\"/>")
	      ("%h" . "<number:month number:textual=\"true\" number:style=\"short\"/>")
	      ("%k" . "<number:hours number:style=\"short\"/>")
	      ("%m" . "<number:month number:style=\"long\"/>")
	      ("%p" . "<number:am-pm/>")
	      ("%y" . "<number:year number:style=\"short\"/>")))
	   (case-fold-search nil)
	   (re (mapconcat 'identity (mapcar 'car fmt-alist) "\\|"))
	   match rpl (start 0) (filler-beg 0) filler-end filler output)
      (dolist (pair
	       '(("\\(?:%[[:digit:]]*N\\)" . "") ; strip ns, us and ns
		 ("%C" . "Y")		; replace century with year
		 ("%D" . "%m/%d/%y")
		 ("%G" . "Y")	      ; year corresponding to iso week
		 ("%I" . "%H")	      ; hour on a 12-hour clock
		 ("%R" . "%H:%M")
		 ("%T" . "%H:%M:%S")
		 ("%U\\|%W" . "%V")   ; week no. starting on Sun./Mon.
		 ("%Z" . "")	      ; time zone name
		 ("%c" . "%Y-%M-%d %a %H:%M" ) ; locale's date and time format
		 ("%g" . "%y")
		 ("%X" . "%x" )		; locale's pref. time format
		 ("%j" . "")		; day of the year
		 ("%l" . "%k")		; like %I blank-padded
		 ("%s" . "") ; no. of secs since 1970-01-01 00:00:00 +0000
		 ("%n" . "<text:line-break/>")
		 ("%r" . "%I:%M:%S %p")
		 ("%t" . "<text:tab/>")
		 ("%u\\|%w" . "") ; numeric day of week - Mon (1-7), Sun(0-6)
		 ("%x" . "%Y-%M-%d %a")	; locale's pref. time format
		 ("%z" . "")		; time zone in numeric form
		 ))
	(setq fmt (replace-regexp-in-string (car pair) (cdr pair) fmt t t)))
      (while (string-match re fmt start)
	(setq match (match-string 0 fmt))
	(setq rpl (assoc-default match fmt-alist))
	(setq start (match-end 0))
	(setq filler-end (match-beginning 0))
	(setq filler (substring fmt (prog1 filler-beg
				      (setq filler-beg (match-end 0)))
				filler-end))
	(setq filler (and (not (string= filler ""))
			  (format "<number:text>%s</number:text>"
				  (org-odt--encode-plain-text filler))))
	(setq output (concat output "\n" filler "\n" rpl)))
      (setq filler (substring fmt filler-beg))
      (unless (string= filler "")
	(setq output (concat output
			     (format "\n<number:text>%s</number:text>"
				     (org-odt--encode-plain-text filler)))))
      (format "\n<number:date-style style:name=\"%s\" %s>%s\n</number:date-style>"
	      style
	      (concat " number:automatic-order=\"true\""
		      " number:format-source=\"fixed\"")
	      output ))))