mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-11 16:08:13 +00:00
`decoded-time-set-defaults' refactored out from iso8601 code
* lisp/calendar/iso8601.el (iso8601--encode-time): * lisp/calendar/time-date.el (decoded-time-set-defaults): Refactor out from `iso8601--encode-time', because it's helpful in other contexts.
This commit is contained in:
parent
8c04e65622
commit
07ce3be6aa
8
etc/NEWS
8
etc/NEWS
@ -2102,13 +2102,13 @@ with POSIX.1-2017.
|
||||
'decoded-time-weekday', 'decoded-time-dst' and 'decoded-time-zone'
|
||||
accessors can be used.
|
||||
|
||||
+++
|
||||
*** The new functions 'date-days-in-month' (which will say how many
|
||||
days there are in a month in a specific year), 'date-ordinal-to-time'
|
||||
(that computes the date of an ordinal day), 'decoded-time-add' for
|
||||
doing computations on a decoded time structure), and
|
||||
'make-decoded-time' (for making a decoded time structure with only the
|
||||
given keywords filled out) have been added.
|
||||
doing computations on a decoded time structure), 'make-decoded-time'
|
||||
(for making a decoded time structure with only the given keywords
|
||||
filled out), and 'encoded-time-set-defaults' (which fills in nil
|
||||
elements as if it's midnight January 1st, 1970) have been added.
|
||||
|
||||
** 'define-minor-mode' automatically documents the meaning of ARG.
|
||||
|
||||
|
@ -349,21 +349,7 @@ Return the number of minutes."
|
||||
|
||||
(defun iso8601--encode-time (time)
|
||||
"Like `encode-time', but fill in nil values in TIME."
|
||||
(setq time (copy-sequence time))
|
||||
(unless (decoded-time-second time)
|
||||
(setf (decoded-time-second time) 0))
|
||||
(unless (decoded-time-minute time)
|
||||
(setf (decoded-time-minute time) 0))
|
||||
(unless (decoded-time-hour time)
|
||||
(setf (decoded-time-hour time) 0))
|
||||
|
||||
(unless (decoded-time-day time)
|
||||
(setf (decoded-time-day time) 1))
|
||||
(unless (decoded-time-month time)
|
||||
(setf (decoded-time-month time) 1))
|
||||
(unless (decoded-time-year time)
|
||||
(setf (decoded-time-year time) 0))
|
||||
(encode-time time))
|
||||
(encode-time (decoded-time-set-defaults (copy-sequence time))))
|
||||
|
||||
(provide 'iso8601)
|
||||
|
||||
|
@ -498,6 +498,26 @@ changes in daylight saving time are not taken into account."
|
||||
"Return a `decoded-time' structure with only the keywords given filled out."
|
||||
(list second minute hour day month year nil dst zone))
|
||||
|
||||
(defun decoded-time-set-defaults (time)
|
||||
"Set any nil values in `decoded-time' TIME to default values.
|
||||
The default value is based on January 1st, 1970 at midnight.
|
||||
|
||||
TIME is modified and returned."
|
||||
(unless (decoded-time-second time)
|
||||
(setf (decoded-time-second time) 0))
|
||||
(unless (decoded-time-minute time)
|
||||
(setf (decoded-time-minute time) 0))
|
||||
(unless (decoded-time-hour time)
|
||||
(setf (decoded-time-hour time) 0))
|
||||
|
||||
(unless (decoded-time-day time)
|
||||
(setf (decoded-time-day time) 1))
|
||||
(unless (decoded-time-month time)
|
||||
(setf (decoded-time-month time) 1))
|
||||
(unless (decoded-time-year time)
|
||||
(setf (decoded-time-year time) 0))
|
||||
time)
|
||||
|
||||
(provide 'time-date)
|
||||
|
||||
;;; time-date.el ends here
|
||||
|
Loading…
Reference in New Issue
Block a user