Function: rng-xsd-convert-date-time
rng-xsd-convert-date-time is a byte-compiled function defined in
rng-xsd.el.gz.
Signature
(rng-xsd-convert-date-time STRING REGEXP)
Documentation
Convert an XML Schema date/time to a list.
Returns nil if invalid. REGEXP is a regexp for parsing the date time
as returned by rng-xsd-make-date-time-regexp. The list has 4 members
(HAS-TIME-ZONE DAY SECOND SECOND-FRACTION), where HAS-TIME-ZONE is t
or nil depending on whether a time zone was specified, DAY is an
integer giving a day number (with Jan 1 1AD being day 1), SECOND is the
second within that day, and SECOND-FRACTION is a float giving the
fractional part of the second.
Source Code
;; Defined in /usr/src/emacs/lisp/nxml/rng-xsd.el.gz
(defun rng-xsd-convert-date-time (string regexp)
"Convert an XML Schema date/time to a list.
Returns nil if invalid. REGEXP is a regexp for parsing the date time
as returned by `rng-xsd-make-date-time-regexp'. The list has 4 members
\(HAS-TIME-ZONE DAY SECOND SECOND-FRACTION), where HAS-TIME-ZONE is t
or nil depending on whether a time zone was specified, DAY is an
integer giving a day number (with Jan 1 1AD being day 1), SECOND is the
second within that day, and SECOND-FRACTION is a float giving the
fractional part of the second."
(and (string-match regexp string)
(let ((year-sign (match-string 1 string))
(year (match-string 2 string))
(month (match-string 3 string))
(day (match-string 4 string))
(hour (match-string 5 string))
(minute (match-string 6 string))
(second (match-string 7 string))
(second-fraction (match-string 8 string))
(has-time-zone (match-string 9 string))
(time-zone-sign (match-string 10 string))
(time-zone-hour (match-string 11 string))
(time-zone-minute (match-string 12 string)))
(setq year-sign (if year-sign -1 1))
(setq year
(if year
(* year-sign
(string-to-number year))
2000))
(setq month
(if month (string-to-number month) 1))
(setq day
(if day (string-to-number day) 1))
(setq hour
(if hour (string-to-number hour) 0))
(setq minute
(if minute (string-to-number minute) 0))
(setq second
(if second (string-to-number second) 0))
(setq second-fraction
(if second-fraction
(float (string-to-number second-fraction))
0.0))
(setq has-time-zone (and has-time-zone t))
(setq time-zone-sign
(if (equal time-zone-sign "-") -1 1))
(setq time-zone-hour
(if time-zone-hour (string-to-number time-zone-hour) 0))
(setq time-zone-minute
(if time-zone-minute (string-to-number time-zone-minute) 0))
(and (>= month 1)
(<= month 12)
(>= day 1)
(<= day (rng-xsd-days-in-month year month))
(<= hour 23)
(<= minute 59)
(<= second 60) ; leap second
(<= time-zone-hour 23)
(<= time-zone-minute 59)
(cons has-time-zone
(rng-xsd-add-seconds
(list (rng-xsd-date-to-days year month day)
(rng-xsd-time-to-seconds hour minute second)
second-fraction)
(* (rng-xsd-time-to-seconds time-zone-hour
time-zone-minute
0)
(- time-zone-sign))))))))