-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We barely used it, and can use java.time in all cases instead.
- Loading branch information
Showing
6 changed files
with
51 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns clojars.time | ||
(:import | ||
(java.time | ||
Instant) | ||
(java.time.temporal | ||
ChronoUnit))) | ||
|
||
(set! *warn-on-reflection* true) | ||
|
||
(defn now | ||
"Returns the current time as a j.t.Instant." | ||
^Instant [] | ||
(Instant/now)) | ||
|
||
(defmacro with-now | ||
"Use in tests to set the value returned by `now`." | ||
[now & body] | ||
`(with-redefs [now (constantly ~now)] | ||
~@body)) | ||
|
||
(defn days-ago | ||
([days] | ||
(days-ago (now) days)) | ||
([^Instant instant ^long days] | ||
(.minus instant days ChronoUnit/DAYS))) | ||
|
||
(defn days-from | ||
([days] | ||
(days-from (now) days)) | ||
([^Instant instant ^long days] | ||
(.plus instant days ChronoUnit/DAYS))) | ||
|
||
(defn parse-instant | ||
^Instant [^String instant-string] | ||
(Instant/parse instant-string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters