Skip to content

Commit

Permalink
Add datetime-format-test-format
Browse files Browse the repository at this point in the history
  • Loading branch information
zonuexe committed Jan 5, 2024
1 parent bff82c9 commit 5d6a9f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ jobs:
run: |
eask package
eask install
eask test ert datetime-format-test.el
eask compile
28 changes: 28 additions & 0 deletions datetime-format-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@
;;; Code:
(require 'ert)
(require 'datetime-format)
(require 'timecop)

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

(defmacro datetime-format--map (list function)
"Apply FUNCTION to each element of LIST.
This macro helps with expression expansion at compile time."
(declare (indent 1))
(let ((sequence (eval list)))
`(prog1 (quote ,sequence)
,@(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)))))))
(setenv "TZ" datetime-format-original-tz))

(provide 'datetime-format-test)
;;; datetime-format-test.el ends here

0 comments on commit 5d6a9f8

Please sign in to comment.