Fork me on GitHub
#babashka
<
2021-08-23
>
indy05:08:40

Just starting out with Babashka. This probably has been asked before: Is it possible for me to use java.util Calendar Date TimeZone and java.text.SimpleDateFormat? I looked at pods and bb.edn and didn't find what I was looking for or at least not in a straight forward way.

indy05:08:46

I guess the most straight forward way I was expecting is for it to be part of the babashka binary itself. What is the simplest alternative to use it without spinning up a JVM (via pods?).

viesti05:08:06

java.time classes are support, you can use those:

user=> (import '(java.time.format DateTimeFormatter) '(java.time LocalDateTime))
java.time.LocalDateTime
user=> (.format (DateTimeFormatter/ofPattern "yyyy-MM-dd") (LocalDateTime/now))
"2021-08-23"

indy05:08:53

Sweet! Thank you so much :)

borkdude06:08:11

Yes, java.time :)

indy06:08:20

The java.time APIs are slick. Used to convert everything to epoch timestamps and work on them and format them back. Now I can directly work with what I want, example just the date. TIL about this.

nate20:08:07

Is there a way to have babashka's -I flag use the default tagged-literal function as a fallback?

nate20:08:58

example:

❯ echo '{:foo "bar"}' | bb -I -O '(map :foo *input*)'
"bar"
with a tagged literal:
❯ echo '{:foo #some-tag "bar"}' | bb -I -O '(map :foo *input*)'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.EdnReader$ReaderException
Message:  java.lang.RuntimeException: No reader function for tag some-tag
Location: <expr>:1:1

----- Context ------------------------------------------------------------------
1: (map :foo *input*)
   ^--- java.lang.RuntimeException: No reader function for tag some-tag

----- Stack trace --------------------------------------------------------------
clojure.core/map - <built-in>
user             - <expr>:1:1

nate20:08:47

I tried using set! to change *data-readers*:

❯ echo '{:foo #some-tag "bar"}' | bb -I -O '(set! *data-readers* {:default tagged-literal})(map :foo *input*)'
----- Error --------------------------------------------------------------------
Type:     clojure.lang.EdnReader$ReaderException
Message:  java.lang.RuntimeException: No reader function for tag some-tag
Location: <expr>:1:48

----- Context ------------------------------------------------------------------
1: (set! *data-readers* {:default tagged-literal})(map :foo *input*)
                                                  ^--- java.lang.RuntimeException: No reader function for tag some-tag

----- Stack trace --------------------------------------------------------------
clojure.core/map - <built-in>
user             - <expr>:1:48

borkdude20:08:22

I think that would be a reasonable default

borkdude20:08:56

The *input* one isn't hooked up to the *data-readers* var I think, currently

borkdude20:08:37

we can fix both

borkdude20:08:09

please post an issue

nate21:08:43

sure thing

nate21:08:46

I would like to work on this, can you give me a hint as to where to start looking for relevant code?

borkdude21:08:35

yes, actually all of this code is in babashka/main.clj I think

nate21:08:15

ok cool, I'll take a look in the next couple of days

borkdude21:08:17

the input var is handled via edn/read-string, you just have to pass the value from the SCI data-readers value to there

borkdude21:08:31

+ add the default there