Function: icalendar--datestring-to-isodate
icalendar--datestring-to-isodate is a byte-compiled function defined
in icalendar.el.gz.
Signature
(icalendar--datestring-to-isodate DATESTRING &optional DAY-SHIFT YEAR-SHIFT)
Documentation
Convert diary-style DATESTRING to iso-style date.
If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days
-- DAY-SHIFT must be either nil or an integer. If YEAR-SHIFT is
non-nil, the result is shifted by YEAR-SHIFT years -- YEAR-SHIFT
must be either nil or an integer. This function tries to figure
the date style from DATESTRING itself. If that is not possible
it uses the current calendar date style.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/icalendar.el.gz
(defun icalendar--datestring-to-isodate (datestring &optional day-shift year-shift)
"Convert diary-style DATESTRING to iso-style date.
If DAY-SHIFT is non-nil, the result is shifted by DAY-SHIFT days
-- DAY-SHIFT must be either nil or an integer. If YEAR-SHIFT is
non-nil, the result is shifted by YEAR-SHIFT years -- YEAR-SHIFT
must be either nil or an integer. This function tries to figure
the date style from DATESTRING itself. If that is not possible
it uses the current calendar date style."
(let ((day -1) month year)
(save-match-data
(cond ( ;; iso-style numeric date
(string-match (concat "\\s-*"
"\\([0-9]\\{4\\}\\)[ \t/-]\\s-*"
"0?\\([1-9][0-9]?\\)[ \t/-]\\s-*"
"0?\\([1-9][0-9]?\\)")
datestring)
(setq year (read (substring datestring (match-beginning 1)
(match-end 1))))
(setq month (read (substring datestring (match-beginning 2)
(match-end 2))))
(setq day (read (substring datestring (match-beginning 3)
(match-end 3)))))
( ;; non-iso numeric date -- must rely on configured
;; calendar style
(string-match (concat "\\s-*"
"0?\\([1-9][0-9]?\\)[ \t/]\\s-*"
"0?\\([1-9][0-9]?\\),?[ \t/]\\s-*"
"\\([0-9]\\{4\\}\\)")
datestring)
(setq day (read (substring datestring (match-beginning 1)
(match-end 1))))
(setq month (read (substring datestring (match-beginning 2)
(match-end 2))))
(setq year (read (substring datestring (match-beginning 3)
(match-end 3))))
(if (eq calendar-date-style 'american)
(let ((x month))
(setq month day)
(setq day x))))
( ;; date contains month names -- iso style
(string-match (concat "\\s-*"
"\\([0-9]\\{4\\}\\)[ \t/]\\s-*"
"\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
"0?\\([123]?[0-9]\\)")
datestring)
(setq year (read (substring datestring (match-beginning 1)
(match-end 1))))
(setq month (icalendar--get-month-number
(substring datestring (match-beginning 2)
(match-end 2))))
(setq day (read (substring datestring (match-beginning 3)
(match-end 3)))))
( ;; date contains month names -- european style
(string-match (concat "\\s-*"
"0?\\([123]?[0-9]\\)[ \t/]\\s-*"
"\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
"\\([0-9]\\{4\\}\\)")
datestring)
(setq day (read (substring datestring (match-beginning 1)
(match-end 1))))
(setq month (icalendar--get-month-number
(substring datestring (match-beginning 2)
(match-end 2))))
(setq year (read (substring datestring (match-beginning 3)
(match-end 3)))))
( ;; date contains month names -- american style
(string-match (concat "\\s-*"
"\\([A-Za-z][^ ]+\\)[ \t/]\\s-*"
"0?\\([123]?[0-9]\\),?[ \t/]\\s-*"
"\\([0-9]\\{4\\}\\)")
datestring)
(setq day (read (substring datestring (match-beginning 2)
(match-end 2))))
(setq month (icalendar--get-month-number
(substring datestring (match-beginning 1)
(match-end 1))))
(setq year (read (substring datestring (match-beginning 3)
(match-end 3)))))
(t
nil)))
(when year-shift
(setq year (+ year year-shift)))
(if (> day 0)
(let ((mdy (calendar-gregorian-from-absolute
(+ (calendar-absolute-from-gregorian (list month day
year))
(or day-shift 0)))))
(icalendar--dmsg (format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy)))
(format "%04d%02d%02d" (nth 2 mdy) (nth 0 mdy) (nth 1 mdy)))
nil)))