Skip to content

Commit

Permalink
add instant->zdt-in-UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
henryw374 committed Mar 20, 2024
1 parent 11341ac commit 1d89b82
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ aka construction a new temporal from one of the same type

;; move date forward 3 days
(t/>> a-date 3 t/days-property)
(t/>> a-date 3 a-temporal-amount)
;; move forward by some amount
(t/>> a-date a-temporal-amount)

(t/date-next-or-same-weekday a-date 2) ; move date to next-or-same tuesday
(t/date-prev-or-same-weekday a-date 7) ; move date to prev-or-same sunday
Expand Down
9 changes: 7 additions & 2 deletions src/com/widdindustries/tempo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@

(defn legacydate->instant [d] (.toInstant ^java.util.Date d))

(defn
instant->zdt-in-UTC
[instant]
(ZonedDateTime/ofInstant instant (ZoneId/of "UTC")))

(defn greater [x y] (if (neg? (compare x y)) y x))

(defn
Expand All @@ -374,7 +379,7 @@
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__43218# p2__43219#] (greater p1__43218# p2__43219#))
(fn* [p1__31208# p2__31209#] (greater p1__31208# p2__31209#))
arg
args))

Expand All @@ -386,7 +391,7 @@
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__43220# p2__43221#] (lesser p1__43220# p2__43221#))
(fn* [p1__31210# p2__31211#] (lesser p1__31210# p2__31211#))
arg
args))

Expand Down
9 changes: 7 additions & 2 deletions src/com/widdindustries/tempo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@

(defn legacydate->instant [d] (.toTemporalInstant ^js d))

(defn
instant->zdt-in-UTC
[instant]
(.toZonedDateTimeISO ^js instant "UTC"))

(defn greater [x y] (if (neg? (compare x y)) y x))

(defn
Expand All @@ -422,7 +427,7 @@
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__43222# p2__43223#] (greater p1__43222# p2__43223#))
(fn* [p1__31212# p2__31213#] (greater p1__31212# p2__31213#))
arg
args))

Expand All @@ -434,7 +439,7 @@
[arg & args]
(assert (every? some? (cons arg args)))
(reduce
(fn* [p1__43224# p2__43225#] (lesser p1__43224# p2__43225#))
(fn* [p1__31214# p2__31215#] (lesser p1__31214# p2__31215#))
arg
args))

Expand Down
5 changes: 2 additions & 3 deletions test/com/widdindustries/tempo_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@
offset (t/clock-offset-millis fixed 1)]
(is (= now (t/instant-now fixed)))
(is (= (t/>> now 1 t/milliseconds-property) (t/instant-now offset)))
(is (t/> (t/instant-now (t/clock-system-default-zone)) (t/instant-now fixed)))
(is (= (t/zdt->timezone_id (t/zdt-now fixed)) (t/zdt->timezone_id (t/zdt-now offset))))
))
(is (t/>= (t/instant-now (t/clock-system-default-zone)) (t/instant-now fixed)))
(is (= (t/zdt->timezone_id (t/zdt-now fixed)) (t/zdt->timezone_id (t/zdt-now offset))))))

(deftest adjust-test
(testing "adjusting date"
Expand Down

0 comments on commit 1d89b82

Please sign in to comment.