Skip to content

Commit

Permalink
Use with-environment-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Jan 7, 2024
1 parent b85d1fb commit 4c813cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions Eask
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
(source 'melpa)

(depends-on "emacs" "26.1")
(depends-on "compat" "29")

(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
33 changes: 18 additions & 15 deletions datetime-format-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; Created: 18 May 2016
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Keywords: datetime calendar
;; Keywords: lisp, datetime, calendar
;; Homepage: https://github.com/zonuexe/emacs-datetime

;; This file is NOT part of GNU Emacs.
Expand Down Expand Up @@ -35,6 +35,9 @@
(require 'datetime-format)
(require 'timecop)

(eval-when-compile
(require 'compat-28))

(defvar datetime-format-original-tz (getenv "TZ"))

(defmacro datetime-format--map (list function)
Expand All @@ -46,20 +49,20 @@ This macro helps with expression expansion at compile time."
,@(mapcar function sequence))))

(ert-deftest datetime-format-test-format ()
(setenv "TZ" "-9:30") ;; Australia/Darwin
(datetime-format--map '(("2009-02-14T09:01:30+09:30" (datetime-format 'atom))
("2009-02-14T09:01:30+09:30" (datetime-format 'atom (current-time)))
("1970-01-01T09:30:00+09:30" (datetime-format 'atom 0))
("1970-01-01T00:00:00+00:00" (datetime-format 'atom 0 :timezone "UTC"))
("2015-01-12T02:31:11+09:30" (datetime-format 'atom "2015-01-12 02:01:11"))
("2015-01-12T02:01:11+02:00" (datetime-format 'atom "2015-01-12 02:01:11"
:timezone "Europe/Kiev"))
("2015-01-11T17:01:11Z" (datetime-format 'atom-utc "2015-01-12 02:01:11"))
("2009-02-13T18:31:30-05:00" (datetime-format 'atom nil
:timezone "America/New_York")))
(lambda (pair)
(cl-destructuring-bind (expected expr) pair
`(timecop 1234567890 (should (string= ,expected (eval ,expr)))))))
(with-environment-variables (("TZ" "-9:30")) ;; Australia/Darwin
(datetime-format--map '(("2009-02-14T09:01:30+09:30" (datetime-format 'atom))
("2009-02-14T09:01:30+09:30" (datetime-format 'atom (current-time)))
("1970-01-01T09:30:00+09:30" (datetime-format 'atom 0))
("1970-01-01T00:00:00+00:00" (datetime-format 'atom 0 :timezone "UTC"))
("2015-01-12T02:31:11+09:30" (datetime-format 'atom "2015-01-12 02:01:11"))
("2015-01-12T02:01:11+02:00" (datetime-format 'atom "2015-01-12 02:01:11"
:timezone "Europe/Kiev"))
("2015-01-11T17:01:11Z" (datetime-format 'atom-utc "2015-01-12 02:01:11"))
("2009-02-13T18:31:30-05:00" (datetime-format 'atom nil
:timezone "America/New_York")))
(lambda (pair)
(cl-destructuring-bind (expected expr) pair
`(timecop 1234567890 (should (string= ,expected (eval ,expr))))))))
(setenv "TZ" datetime-format-original-tz))

(provide 'datetime-format-test)
Expand Down
2 changes: 1 addition & 1 deletion datetime-format.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: USAMI Kenta <[email protected]>
;; Created: 16 May 2016
;; Version: 0.0.1
;; Package-Requires: ((emacs "26.3"))
;; Package-Requires: ((emacs "26.3") (compat "29"))
;; Keywords: lisp, datetime, calendar
;; Homepage: https://github.com/emacs-php/emacs-datetime

Expand Down

0 comments on commit 4c813cc

Please sign in to comment.