clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
dharrigan 2020-12-01T06:40:08.042300Z

Good Morning!

thomas 2020-12-01T08:00:21.042500Z

morning

djm 2020-12-01T08:13:57.042700Z

πŸ‘‹

2020-12-01T08:30:33.042900Z

Morning

dominicm 2020-12-01T08:33:26.043200Z

Happy tiny chocolate day

πŸ˜‚ 3
jiriknesl 2020-12-01T09:03:52.043500Z

Good morning πŸ™‚

danm 2020-12-01T09:31:31.043800Z

Morning!

joetague 2020-12-01T10:07:53.044900Z

Morning

alexlynham 2020-12-01T10:12:51.045Z

morning

mccraigmccraig 2020-12-01T11:14:04.045400Z

Β‘mΓ₯nmΓ₯nΒ‘

jasonbell 2020-12-01T11:35:21.045600Z

Morning

maleghast 2020-12-01T12:44:14.046900Z

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?

maleghast 2020-12-01T12:45:19.048Z

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

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

maleghast 2020-12-01T12:46:23.048700Z

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

maleghast 2020-12-01T12:47:29.049500Z

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

alexlynham 2020-12-01T12:58:57.049600Z

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

alexlynham 2020-12-03T14:22:57.093800Z

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

alexlynham 2020-12-01T12:59:20.049800Z

quick and dirty but then it's utc/z

maleghast 2020-12-01T12:59:53.050600Z

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.

maleghast 2020-12-01T13:00:22.051200Z

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

yogidevbear 2020-12-01T13:42:54.051700Z

Morning

alexlynham 2020-12-01T13:56:32.051800Z

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

dominicm 2020-12-01T14:17:54.052Z

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

dominicm 2020-12-01T14:17:59.052100Z

You're a monster :D

dominicm 2020-12-01T14:21:07.052300Z

@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]"

maleghast 2020-12-01T14:23:17.052700Z

@dominicm - Thanks, that's very cool πŸ™‚ (I had forgotten about tick)

dominicm 2020-12-01T14:25:28.052800Z

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.

maleghast 2020-12-02T10:33:25.068300Z

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

2020-12-01T19:08:13.053400Z

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