From: Lars Ingebrigtsen Date: Tue, 30 Jul 2019 14:46:10 +0000 (+0200) Subject: `decoded-time-set-defaults' refactored out from iso8601 code X-Git-Tag: emacs-27.0.90~1801 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=07ce3be6aa15fdf2092bdf3c60a132d5f4b9c980;p=emacs.git `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. --- diff --git a/etc/NEWS b/etc/NEWS index 7dfb08256f2..486e677539d 100644 --- a/etc/NEWS +++ b/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. diff --git a/lisp/calendar/iso8601.el b/lisp/calendar/iso8601.el index ab0077ac58d..c69156cbeb6 100644 --- a/lisp/calendar/iso8601.el +++ b/lisp/calendar/iso8601.el @@ -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) diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el index e195f71c58a..f14478e67cc 100644 --- a/lisp/calendar/time-date.el +++ b/lisp/calendar/time-date.el @@ -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