diff --git a/README.md b/README.md index bef0d9c..078e87a 100644 --- a/README.md +++ b/README.md @@ -98,10 +98,21 @@ namespace exists which contains a subset of the functions from `tick.core` which [![Clojars Project](https://img.shields.io/clojars/v/com.widdindustries/time-literals-tempo.svg)](https://clojars.org/com.widdindustries/time-literals-tempo) -* As of March 2024, a polyfill (e.g. [this](https://github.com/fullcalendar/temporal-polyfill)) of Temporal will be required for all javascript environments. -* The new underlying Javascript platform time API [Temporal](https://github.com/tc39/proposal-temporal) has semi-stabilized at +As of March 2024 + +* [Temporal](https://github.com/tc39/proposal-temporal) has semi-stabilized at `ecma stage 3`, meaning implementors - can still suggest changes - although at this point any changes will be superficial. + can still suggest changes - although at this point any changes will be superficial. +* a polyfill (e.g. [this](https://github.com/fullcalendar/temporal-polyfill)) of Temporal will be required for all javascript environments. + +```html + +``` + ### Setup @@ -195,11 +206,14 @@ to as `timezone_id`. Call `str` on a timezone to get its id. (t/yearmonth+day-at-end-of-month a-yearmonth) ; => a date (t/datetime+timezone a-datetime "Pacific/Honolulu") ; => a zdt -; to get parts of an entity, start with the subject and add -> +; to get parts of an entity, the function name will start with the type of the entity, then add -> then put the target type. For example: (t/date->yearmonth a-date) (t/date->month a-date) (t/zdt->nanosecond a-zdt) (t/instant->epochmillisecond an-instant) +(t/epochmilli->instant 123) +(t/legacydate->instant d) +; & etc ``` diff --git a/gen_in/tempo.cljc b/gen_in/tempo.cljc index 80aa727..8758aa8 100644 --- a/gen_in/tempo.cljc +++ b/gen_in/tempo.cljc @@ -104,6 +104,10 @@ #?(:cljay (.toInstant ^java.util.Date d) :cljs (.toTemporalInstant ^js d))) +(defn instant->zdt-in-UTC [instant] + #?(:cljay (ZonedDateTime/ofInstant instant (ZoneId/of "UTC")) + :cljs (.toZonedDateTimeISO ^js instant "UTC"))) + (defn greater [x y] (if (neg? (compare x y)) y x)) diff --git a/test/com/widdindustries/tempo_test.cljc b/test/com/widdindustries/tempo_test.cljc index 7609829..fee8b42 100644 --- a/test/com/widdindustries/tempo_test.cljc +++ b/test/com/widdindustries/tempo_test.cljc @@ -80,9 +80,12 @@ (is (= i (t/instant-from {:epochmilli (t/instant->epochmilli i)})))) (let [d #?(:clj (Date.) :cljs (js/Date.)) i (t/instant-from {:legacydate d})] - (= (.getTime d) (t/instant->epochmilli i)) - (is (= (.getTime d) (-> (.getTime d) (t/epochmilli->instant) (t/instant->epochmilli)))) - )) + (is (= (.getTime d) (t/instant->epochmilli i))) + (is (= i (-> i (t/instant->legacydate) (t/legacydate->instant)))) + (is (= (.getTime d) (-> (.getTime d) (t/epochmilli->instant) (t/instant->epochmilli)))))) + (testing "zdt-instant" + (let [i (t/instant-parse "2024-01-16T12:43:44.196000Z")] + (is (= i (-> i (t/instant->zdt-in-UTC) (t/zdt->instant)))))) (testing "zdt with offset" (is (= "+05:50" (->