From a4b4ce43a4fe6e2614c7e5195a3ffad2d97e70b2 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Fri, 21 Feb 2020 21:32:28 +0100 Subject: [PATCH] Add java.time.temporal.ChronoUnit class (#271) * Adding java.time.temporal.ChronoUnit to classes.clj This enables the two following kinds of calculations between LocalDateTime, LocalTime, Instant and other Temporal descendants: ChronoUnit.MILLIS.between(temporalOne, temporalTwo) temporalOne.until(temporalTwo, Chronounit.HOURS) and I assume a lot of other operations which require time units. * Add unit test Co-authored-by: Matias Bjarland --- doc/dev.md | 3 +++ src/babashka/impl/classes.clj | 1 + test/babashka/java_time_test.clj | 6 +++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/dev.md b/doc/dev.md index 4244149e..19f5151e 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -57,6 +57,9 @@ Keep notes here about how adding libraries and classes to Babashka affects the b +2020/02/21, +Added java.time.temporal.ChronoUnit +40651596 - 40598260 = 53kb added. 2020/02/19, e43727955a2cdabd2bb0189c20dd7f9a18156fc9 Added fipp.edn/pprint diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index e0451f08..d69a0d9a 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -83,6 +83,7 @@ java.time.ZonedDateTime java.time.ZoneId java.time.ZoneOffset + java.time.temporal.ChronoUnit java.time.temporal.TemporalAccessor java.util.regex.Pattern java.util.Base64 diff --git a/test/babashka/java_time_test.clj b/test/babashka/java_time_test.clj index 65b22709..c66fb8e4 100644 --- a/test/babashka/java_time_test.clj +++ b/test/babashka/java_time_test.clj @@ -16,4 +16,8 @@ (is (= "18-12-2019 16:01:41" (bb '(.format (java.time.LocalDateTime/parse "2019-12-18T16:01:41.485") - (java.time.format.DateTimeFormatter/ofPattern "dd-MM-yyyy HH:mm:ss")))))) + (java.time.format.DateTimeFormatter/ofPattern "dd-MM-yyyy HH:mm:ss"))))) + (is (number? (bb " +(let [x (java.time.LocalDateTime/parse \"2019-12-18T16:01:41.485\") + y (java.time.LocalDateTime/now)] + (.between java.time.temporal.ChronoUnit/MINUTES x y))"))))