[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 46df7bb 03/12: Add new function time-zone-format
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master 46df7bb 03/12: Add new function time-zone-format |
Date: |
Wed, 31 Jul 2019 15:47:57 -0400 (EDT) |
branch: master
commit 46df7bbe12cce4c9af7ce4357aa9f8d36c1d8933
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Add new function time-zone-format
* lisp/calendar/time-date.el (time-zone-format): New function.
---
etc/NEWS | 4 ++++
lisp/calendar/time-date.el | 10 ++++++++++
test/lisp/calendar/time-date-tests.el | 6 ++++++
3 files changed, 20 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 486e677..e1ac4eb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2110,6 +2110,10 @@ doing computations on a decoded time structure),
'make-decoded-time'
filled out), and 'encoded-time-set-defaults' (which fills in nil
elements as if it's midnight January 1st, 1970) have been added.
+*** The new function `time-zone-format' has been added to format
+Emacs time zones (which are in seconds) according to many standards
+(i.e., "+01:00").
+
** 'define-minor-mode' automatically documents the meaning of ARG.
+++
diff --git a/lisp/calendar/time-date.el b/lisp/calendar/time-date.el
index f14478e..efc9ae4 100644
--- a/lisp/calendar/time-date.el
+++ b/lisp/calendar/time-date.el
@@ -352,6 +352,16 @@ is output until the first non-zero unit is encountered."
(<= (car here) delay)))
(concat (format "%.2f" (/ delay (car (cddr here)))) (cadr
here))))))
+(defun time-zone-format (seconds)
+ "Format SECONDS as a valid time zone string.
+For instance, 3600 is \"+01:00\"."
+ (format "%s%02d:%02d"
+ (if (< seconds 0)
+ "-"
+ "+")
+ (/ (abs seconds) 3600)
+ (mod (abs seconds) 3600)))
+
(defun date-days-in-month (year month)
"The number of days in MONTH in YEAR."
(if (= month 2)
diff --git a/test/lisp/calendar/time-date-tests.el
b/test/lisp/calendar/time-date-tests.el
index b46a247..51250ce 100644
--- a/test/lisp/calendar/time-date-tests.el
+++ b/test/lisp/calendar/time-date-tests.el
@@ -104,6 +104,12 @@
(should (equal (decoded-time-add time (mdec :zone -7200))
'(12 15 14 8 7 2019 1 t 7200)))))
+(ert-deftest test-time-zone-format ()
+ (should (equal (time-zone-format 3600)
+ "+01:00"))
+ (should (equal (time-zone-format -7200)
+ "-02:00")))
+
(require 'ert)
;;; time-date-tests.el ends here
- [Emacs-diffs] master updated (794f8f2 -> a79e96f), Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 8c04e65 01/12: Have newsticker use iso8601 to parse dates, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 07ce3be 02/12: `decoded-time-set-defaults' refactored out from iso8601 code, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 46df7bb 03/12: Add new function time-zone-format,
Lars Ingebrigtsen <=
- [Emacs-diffs] master 14c0a63 04/12: Make time-zone-format take a SHORT parameter, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master e82ae1d 06/12: decoded-time-dst doc fix, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 6a87416 05/12: Use iso8601-parse in nnrss, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 4dcb692 07/12: Default DST to "undecided" in decoded-time-set-defaults, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master fa648a5 08/12: Allow timezone defaults in decoded-time-set-defaults, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 1ab6445 10/12: Fix time zone in previous rewrite of newsticker--decode-iso8601-date, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master c8f1e17 11/12: Rewrite `url-dav-process-date-property' to use parse-time, Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master a79e96f 12/12: Add more icalendar tests (for the isodatetime parser), Lars Ingebrigtsen, 2019/07/31
- [Emacs-diffs] master 296002b 09/12: Rewrite `parse-iso8601-time-string' to use `iso8601-parse', Lars Ingebrigtsen, 2019/07/31