diff options
| author | Lars Ingebrigtsen | 2019-09-29 21:55:20 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-09-29 21:55:20 +0200 |
| commit | e68fa34d62edb62d58f1280a84c2f45d25a33423 (patch) | |
| tree | 89ce7d6e00e19b3b1dcf5bf1f8005bced6ab0b42 | |
| parent | 0df01e3aa5f8372995bdc39be36c444c54a52f7e (diff) | |
| download | emacs-e68fa34d62edb62d58f1280a84c2f45d25a33423.tar.gz emacs-e68fa34d62edb62d58f1280a84c2f45d25a33423.zip | |
Make iso8601-parse take a FORM parameter like `decode-time'
* lisp/calendar/iso8601.el (iso8601-parse-time, iso8601-parse):
Take a FORM parameter like `decode-time'.
| -rw-r--r-- | lisp/calendar/iso8601.el | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el index 66446dafb96..3ff91d910c7 100644 --- a/lisp/calendar/iso8601.el +++ b/lisp/calendar/iso8601.el | |||
| @@ -111,7 +111,7 @@ | |||
| 111 | iso8601--duration-week-match | 111 | iso8601--duration-week-match |
| 112 | iso8601--duration-combined-match))) | 112 | iso8601--duration-combined-match))) |
| 113 | 113 | ||
| 114 | (defun iso8601-parse (string) | 114 | (defun iso8601-parse (string &optional form) |
| 115 | "Parse an ISO 8601 date/time string and return a `decode-time' structure. | 115 | "Parse an ISO 8601 date/time string and return a `decode-time' structure. |
| 116 | 116 | ||
| 117 | The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\", | 117 | The ISO 8601 date/time strings look like \"2008-03-02T13:47:30\", |
| @@ -119,9 +119,7 @@ but shorter, incomplete strings like \"2008-03-02\" are valid, as | |||
| 119 | well as variants like \"2008W32\" (week number) and | 119 | well as variants like \"2008W32\" (week number) and |
| 120 | \"2008-234\" (ordinal day number). | 120 | \"2008-234\" (ordinal day number). |
| 121 | 121 | ||
| 122 | The `decode-time' value returned will have the same precision as | 122 | See `decode-time' for the meaning of FORM." |
| 123 | STRING, so if a sub-second STRING is passed in, the `decode-time' | ||
| 124 | seconds field will be on the (SECONDS . HZ) format." | ||
| 125 | (if (not (iso8601-valid-p string)) | 123 | (if (not (iso8601-valid-p string)) |
| 126 | (signal 'wrong-type-argument string) | 124 | (signal 'wrong-type-argument string) |
| 127 | (let* ((date-string (match-string 1 string)) | 125 | (let* ((date-string (match-string 1 string)) |
| @@ -130,7 +128,7 @@ seconds field will be on the (SECONDS . HZ) format." | |||
| 130 | (date (iso8601-parse-date date-string))) | 128 | (date (iso8601-parse-date date-string))) |
| 131 | ;; The time portion is optional. | 129 | ;; The time portion is optional. |
| 132 | (when time-string | 130 | (when time-string |
| 133 | (let ((time (iso8601-parse-time time-string))) | 131 | (let ((time (iso8601-parse-time time-string form))) |
| 134 | (setf (decoded-time-hour date) (decoded-time-hour time)) | 132 | (setf (decoded-time-hour date) (decoded-time-hour time)) |
| 135 | (setf (decoded-time-minute date) (decoded-time-minute time)) | 133 | (setf (decoded-time-minute date) (decoded-time-minute time)) |
| 136 | (setf (decoded-time-second date) (decoded-time-second time)))) | 134 | (setf (decoded-time-second date) (decoded-time-second time)))) |
| @@ -221,10 +219,12 @@ seconds field will be on the (SECONDS . HZ) format." | |||
| 221 | (1- (- year)) | 219 | (1- (- year)) |
| 222 | year)))) | 220 | year)))) |
| 223 | 221 | ||
| 224 | (defun iso8601-parse-time (string) | 222 | (defun iso8601-parse-time (string &optional form) |
| 225 | "Parse STRING, which should be an ISO 8601 time string. | 223 | "Parse STRING, which should be an ISO 8601 time string. |
| 226 | The return value will be a `decode-time' structure with just the | 224 | The return value will be a `decode-time' structure with just the |
| 227 | hour/minute/seconds/zone fields filled in." | 225 | hour/minute/seconds/zone fields filled in. |
| 226 | |||
| 227 | See `decode-time' for the meaning of FORM." | ||
| 228 | (if (not (iso8601--match iso8601--full-time-match string)) | 228 | (if (not (iso8601--match iso8601--full-time-match string)) |
| 229 | (signal 'wrong-type-argument string) | 229 | (signal 'wrong-type-argument string) |
| 230 | (let ((time (match-string 1 string)) | 230 | (let ((time (match-string 1 string)) |
| @@ -238,7 +238,8 @@ hour/minute/seconds/zone fields filled in." | |||
| 238 | (string-to-number (match-string 3 time)))) | 238 | (string-to-number (match-string 3 time)))) |
| 239 | (fraction (and (match-string 4 time) | 239 | (fraction (and (match-string 4 time) |
| 240 | (string-to-number (match-string 4 time))))) | 240 | (string-to-number (match-string 4 time))))) |
| 241 | (when fraction | 241 | (when (and fraction |
| 242 | (eq form t)) | ||
| 242 | (cond | 243 | (cond |
| 243 | ;; Sub-second time. | 244 | ;; Sub-second time. |
| 244 | (second | 245 | (second |