Fork me on GitHub
#clojure-uk
<
2020-12-01
>
dharrigan06:12:08

Good Morning!

djm08:12:57

👋

dominicm08:12:26

Happy tiny chocolate day

😂 9
jiriknesl09:12:52

Good morning 🙂

danm09:12:31

Morning!

mccraigmccraig11:12:04

¡månmån¡

maleghast12:12:14

Morning All 🙂 Does anyone have a quick / reliable way to make #inst "2020-12-01T12:00:00" have a timezone, so that it can be formatted using the date / time formatting functions in clojure.java-time?

maleghast12:12:19

I get a type error when I try to do this:

(jt/format "dd/MM/yyyy" #inst "2020-12-01T12:00:00")

maleghast12:12:23

and I am pretty sure that this is because a bare Clojure Instant has no timezone info as it is assumed to be UTC

paul.legato19:12:13

Technically, an instant has no timezone because it’s the number of seconds elapsed since the epoch moment (Jan 1st 1970 at 00:00:00 UTC), which is the same number of seconds anywhere

maleghast12:12:29

(above, jt/ is as a result of (require '[java-time :as jt]) )

alexlynham12:12:57

where your datetime is dt, (str dt "Z")

alexlynham13:12:32

with the obvious caveat that this works IIF the format is exactly as above lol in practice i'd parse it and then coerce it using a lib and a threading form

dominicm14:12:59

You're a monster :D

alexlynham14:12:57

i know, def a case of 'just because you can doesn't mean you should' hahaha

alexlynham12:12:20

quick and dirty but then it's utc/z

maleghast12:12:53

In the spirit of full disclosure, this is the solution I have (now): (jt/format "dd/MM/yyyy" (.atZone (.toInstant #inst "2020-12-01T12:00:00") (jt/zone-id))) but i would like something less unwieldy and less Java-y if it's possible.

maleghast13:12:22

(assume that #inst "2020-12--1T12:00:00" would actually be passed in as a value / input)

dominicm14:12:54

With tick: (t/in #inst "2020-12-01T12:00:00" (t/zone "Europe/London"))

dominicm14:12:07

@maleghast there's 2 things you might want to have happen here: 1. You want to have 2020-12-01T12:00:00 in the target timezone. E.g. a shift into Tokyo would be "2020-12-01T12:00+09:00[Asia/Tokyo]" 2. You want to shift from UTC to the target timezone. E.g. a shift into Tokyo would be "2020-12-01T21:00+09:00[Asia/Tokyo]"

maleghast14:12:17

@dominicm - Thanks, that's very cool 🙂 (I had forgotten about tick)

dominicm14:12:28

Here's the code for (1). But assuming that your inst is an inst, you don't want this:

(let [dt #inst "2020-12-01T12:00:00"]
    (cljc.java-time.zoned-date-time/of
      (t/date dt)
      (t/time (t/instant dt))
      (t/zone "Asia/Tokyo")))
The first snippet I produced is probably what you want.

maleghast10:12:25

Thanks very much, have stored that away for myself and passed on the knowledge to the person who was having issues. 🙂