emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 07ce3be 02/12: `decoded-time-set-defaults' refactor


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 07ce3be 02/12: `decoded-time-set-defaults' refactored out from iso8601 code
Date: Wed, 31 Jul 2019 15:47:57 -0400 (EDT)

branch: master
commit 07ce3be6aa15fdf2092bdf3c60a132d5f4b9c980
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    `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.
---
 etc/NEWS                   |  8 ++++----
 lisp/calendar/iso8601.el   | 16 +---------------
 lisp/calendar/time-date.el | 20 ++++++++++++++++++++
 3 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 7dfb082..486e677 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 ab0077a..c69156c 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 e195f71..f14478e 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]