Function: rng-xsd-make-date-time-regexp
rng-xsd-make-date-time-regexp is a byte-compiled function defined in
rng-xsd.el.gz.
Signature
(rng-xsd-make-date-time-regexp TEMPLATE)
Documentation
Return a regular expression matching a ISO 8601 date/time.
The template is a string with Y standing for years field, M standing for months, D standing for day of month, T standing for a literal T, t standing for time and - standing for a literal hyphen. A time zone is always allowed at the end. Regardless of the fields appearing in the template, the regular expression will have twelve groups matching the year sign, year, month, day of month, hours, minutes, integer seconds, fractional seconds (including leading period), time zone, time zone sign, time zone hours, time zone minutes.
Source Code
;; Defined in /usr/src/emacs/lisp/nxml/rng-xsd.el.gz
(defun rng-xsd-make-date-time-regexp (template)
"Return a regular expression matching a ISO 8601 date/time.
The template is a string with Y standing for years field, M standing
for months, D standing for day of month, T standing for a literal T, t
standing for time and - standing for a literal hyphen. A time zone is
always allowed at the end. Regardless of the fields appearing in the
template, the regular expression will have twelve groups matching the
year sign, year, month, day of month, hours, minutes, integer seconds,
fractional seconds (including leading period), time zone, time zone
sign, time zone hours, time zone minutes."
(let ((i 0)
(len (length template))
(parts nil)
first last c)
(while (< i len)
(setq c (aref template i))
(setq parts
(cons (cond ((eq c ?Y)
(setq first 0)
(setq last 1)
"\\(-\\)?\\(\\(?:[1-9][0-9]*\\)?[0-9]\\{4\\}\\)")
((eq c ?M)
(or first
(setq first 2))
(setq last 2)
"\\([0-9][0-9]\\)")
((eq c ?D)
(or first
(setq first 3))
(setq last 3)
"\\([0-9][0-9]\\)")
((eq c ?t)
(or first
(setq first 4))
(setq last 7)
"\\([0-9][0-9]\\):\\([0-9][0-9]\\):\\([0-9][0-9]\\)\\(\\.[0-9]*\\)?")
(t (string c)))
parts))
(setq i (1+ i)))
(while (< last 7)
(setq last (1+ last))
;; Add dummy fields that can never much but keep the group
;; numbers uniform.
(setq parts (cons "\\(\\'X\\)?" parts)))
(setq parts (cons "\\(Z\\|\\([-+]\\)\\([0-9][0-9]\\):\\([0-5][0-9]\\)\\)?[ \t\n\r]*\\'"
parts))
(setq parts (cons "\\`[ \t\n\r]*" (nreverse parts)))
(while (> first 0)
(setq first (1- first))
(setq parts (cons "\\(X\\)?" parts)))
(apply 'concat parts)))