From ead237eee335fc3bc4cdfc88e3fb4af821878b3c Mon Sep 17 00:00:00 2001 From: Daniel Vingo Date: Fri, 10 Feb 2023 04:39:54 -0500 Subject: [PATCH] Add more java classes and interfaces to support juxt.tick (#1490) --- CHANGELOG.md | 1 + src/babashka/impl/classes.clj | 6 +++++- test/babashka/java_time_test.clj | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07ea7df5..8e716e1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ A preview of the next release can be installed from [Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting ## Unreleased +- Add more java.time and related classes with the goal of supporting juxt.tick https://github.com/juxt/tick/issues/86 - [#1000](https://github.com/babashka/babashka/issues/1000): add lib tests for xforms ([@bobisageek](https://github.com/bobisageek)) - [#1482](https://github.com/babashka/babashka/issues/1482): make loading of libs thread safe - [#1487](https://github.com/babashka/babashka/issues/1487): `babashka.tasks/clojure` should be supported without arguments to start a REPL diff --git a/src/babashka/impl/classes.clj b/src/babashka/impl/classes.clj index 351963a1..fd45ef0b 100644 --- a/src/babashka/impl/classes.clj +++ b/src/babashka/impl/classes.clj @@ -364,6 +364,7 @@ java.security.Security java.sql.Date java.text.ParseException + java.text.ParsePosition ;; adds about 200kb, same functionality provided by java.time: java.text.SimpleDateFormat ~@(when features/java-time? @@ -391,6 +392,7 @@ java.time.format.DateTimeFormatterBuilder java.time.format.DateTimeParseException java.time.format.DecimalStyle + java.time.format.FormatStyle java.time.format.ResolverStyle java.time.format.SignStyle java.time.temporal.ChronoField @@ -403,7 +405,9 @@ java.time.format.TextStyle java.time.temporal.Temporal java.time.temporal.TemporalAccessor - java.time.temporal.TemporalAdjuster]) + java.time.temporal.TemporalAdjuster + java.time.temporal.TemporalQuery + ~(symbol "[Ljava.time.temporal.TemporalQuery;")]) java.util.concurrent.atomic.AtomicInteger java.util.concurrent.atomic.AtomicLong java.util.concurrent.atomic.AtomicReference diff --git a/test/babashka/java_time_test.clj b/test/babashka/java_time_test.clj index 90d8f704..a2b3ed9a 100644 --- a/test/babashka/java_time_test.clj +++ b/test/babashka/java_time_test.clj @@ -2,6 +2,7 @@ (:require [babashka.test-utils :as test-utils] [clojure.edn :as edn] + [clojure.string :as str] [clojure.test :as test :refer [deftest is]])) (defn bb [expr] @@ -17,6 +18,12 @@ (bb '(.format (java.time.LocalDateTime/parse "2019-12-18T16:01:41.485") (java.time.format.DateTimeFormatter/ofPattern "dd-MM-yyyy HH:mm:ss"))))) + + (let [out (bb '(.format (java.time.LocalDateTime/parse "2019-12-18T16:01:41.485") + (java.time.format.DateTimeFormatter/ofLocalizedDateTime java.time.format.FormatStyle/SHORT)))] + (is (and (str/includes? out "12") (str/includes? out "18")))) + + (is (number? (bb " (let [x (java.time.LocalDateTime/parse \"2019-12-18T16:01:41.485\") y (java.time.LocalDateTime/now)]