From 1d89b82c3d741eec1e48ba0795614dcbefcd5b62 Mon Sep 17 00:00:00 2001 From: Henry Widd Date: Wed, 20 Mar 2024 15:07:43 +0000 Subject: [PATCH] add instant->zdt-in-UTC --- README.md | 3 ++- src/com/widdindustries/tempo.clj | 9 +++++++-- src/com/widdindustries/tempo.cljs | 9 +++++++-- test/com/widdindustries/tempo_test.cljc | 5 ++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 078e87a..2f1ce08 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/com/widdindustries/tempo.clj b/src/com/widdindustries/tempo.clj index 7acab2b..73667f9 100644 --- a/src/com/widdindustries/tempo.clj +++ b/src/com/widdindustries/tempo.clj @@ -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 @@ -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)) @@ -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)) diff --git a/src/com/widdindustries/tempo.cljs b/src/com/widdindustries/tempo.cljs index 4f6c918..da27f29 100644 --- a/src/com/widdindustries/tempo.cljs +++ b/src/com/widdindustries/tempo.cljs @@ -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 @@ -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)) @@ -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)) diff --git a/test/com/widdindustries/tempo_test.cljc b/test/com/widdindustries/tempo_test.cljc index fee8b42..4986023 100644 --- a/test/com/widdindustries/tempo_test.cljc +++ b/test/com/widdindustries/tempo_test.cljc @@ -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"