1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-03 10:31:37 -08:00

add ability to understand ISO8601 basic format as well as the extended one.

This commit is contained in:
Mark A. Hershberger 2009-08-14 18:18:39 +00:00
parent 4e021e652a
commit b6377f1dc3
2 changed files with 90 additions and 77 deletions

View file

@ -1,3 +1,9 @@
2009-08-14 Mark A. Hershberger <mah@everybody.org>
* timezone.el (timezone-parse-date): Add ability to understand ISO
basic format (minimal separators) dates in addition to the
already-supported extended format dates.
2009-08-14 Eli Zaretskii <eliz@gnu.org>
* international/ucs-normalize.el: Add a `coding' file variable.

View file

@ -134,7 +134,8 @@ Understands the following styles:
(6) Thu, 11 Apr 16:17:12 91 [MET]
(7) Mon, 6 Jul 16:47:20 T 1992 [MET]
(8) 1996-06-24 21:13:12 [GMT]
(9) 1996-06-24 21:13-ZONE"
(9) 1996-06-24 21:13-ZONE
(10) 19960624T211312"
;; Get rid of any text properties.
(and (stringp date)
(or (text-properties-at 0 date)
@ -190,26 +191,32 @@ Understands the following styles:
;; Styles: (8) with timezone.
(setq year 1 month 2 day 3 time 4 zone 5))
((string-match
"\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[T \t]+\\([0-9]+:[0-9]+\\)[ \t]+\\([-+a-zA-Z0-9:]+\\)" date)
"\\([0-9]\\{4\\}\\)-?\\([0-9]\\{0,2\\}\\)-?\\([0-9]\\{0,2\\}\\)[T \t]+\\([0-9]\\{0,2\\}:?[0-9]\\{0,2\\}:?[0-9]\\{0,2\\}\\)[ \t]*\\([-+a-zA-Z]+[0-9:]*\\)" date)
;; Styles: (8) with timezone with a colon in it.
(setq year 1 month 2 day 3 time 4 zone 5))
((string-match
"\\([0-9]+\\)-\\([0-9]+\\)-\\([0-9]+\\)[T \t]+\\([0-9]+:[0-9]+:[0-9]+\\)" date)
"\\([0-9]\\{4\\}\\)-?\\([0-9]\\{0,2\\}\\)-?\\([0-9]\\{0,2\\}\\)[T \t]+\\([0-9]+:?[0-9]+:?[0-9]+\\)" date)
;; Styles: (8) without timezone.
(setq year 1 month 2 day 3 time 4 zone nil))
)
(when year
(setq year (match-string year date))
;; Guess ambiguous years. Assume years < 69 don't predate the
;; Unix Epoch, so are 2000+. Three-digit years are assumed to
;; be relative to 1900.
(if (< (length year) 4)
(when (< (length year) 4)
(let ((y (string-to-number year)))
(if (< y 69)
(when (< y 69)
(setq y (+ y 100)))
(setq year (int-to-string (+ 1900 y)))))
(setq month
(if (= (aref date (+ (match-beginning month) 2)) ?-)
(if (or (= (aref date (+ (match-beginning month) 2)) ?-)
(let ((n (string-to-number
(char-to-string
(aref date (+ (match-beginning month) 2))))))
(= (aref (number-to-string n) 0)
(aref date (+ (match-beginning month) 2)))))
;; Handle numeric months, spanning exactly two digits.
(substring date
(match-beginning month)
@ -219,11 +226,11 @@ Understands the following styles:
(+ (match-beginning month) 3)))
(monthnum
(cdr (assoc (upcase string) timezone-months-assoc))))
(if monthnum
(when monthnum
(int-to-string monthnum)))))
(setq day (match-string day date))
(setq time (match-string time date)))
(if zone (setq zone (match-string zone date)))
(when zone (setq zone (match-string zone date)))
;; Return a vector.
(if (and year month)
(vector year month day time zone)