This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-24
Channels
- # adventofcode (4)
- # announcements (1)
- # aws (6)
- # babashka (18)
- # babashka-sci-dev (18)
- # beginners (12)
- # calva (43)
- # circleci (3)
- # clj-kondo (96)
- # cljdoc (2)
- # clojure (89)
- # clojure-australia (2)
- # clojure-europe (26)
- # clojure-nl (3)
- # clojure-norway (11)
- # clojure-spec (8)
- # clojure-uk (1)
- # clojurescript (28)
- # cursive (25)
- # datahike (6)
- # datalevin (56)
- # datomic (12)
- # docker (15)
- # emacs (9)
- # events (2)
- # figwheel (3)
- # fulcro (15)
- # gratitude (10)
- # introduce-yourself (8)
- # lsp (16)
- # malli (6)
- # nbb (2)
- # off-topic (23)
- # other-languages (2)
- # pathom (4)
- # portal (25)
- # practicalli (1)
- # re-frame (9)
- # releases (1)
- # shadow-cljs (8)
- # sql (6)
- # timbre (3)
Quick/urgent question I am getting a time in UTC: 2022-11-24T11:50:26Z How can I convert it to IST (Israel Standard Time)?
This is the code I am trying to convert
(.utc moment date)
I already take the date from the backend
Here it is using java.time:
(import [java.time ZoneId Instant])
(-> (Instant/parse "2022-11-24T11:50:26Z")
(.atZone (ZoneId/of "Asia/Jerusalem")))
you'll want to install the additional moment-timezone
package
specifically, here's the docs you'll use https://momentjs.com/timezone/docs/#/using-timezones/converting-to-zone/
May also want to call https://momentjs.com/timezone/docs/#/using-timezones/getting-country-zones/ to get the zone names for Israel
Okay lets say I wanna use this exactly how do I convert it to clojure (sorry Im a beginner):
(
(moment/tz date "America/New_York")
or (.tz moment date "America/New_York")
the moment
reference may be different depending on how you required the libraries
Both give me same result:
(println (.utc moment date))
(println (.tz moment date "Israel/Jerusalem"))
When I run that I get
Moment Timezone has no data for Israel/Jerusalem. See .
The TZ name is just "Israel"
Okay thanks turns out its a bug with moment.js How do I do this then?
moment(startdate).add(2, 'hours')
I just used the
fn and regex matched against israel
(.add (moment startdate) 2 "hours")
I'd suggest reading this post that can help you understand how to access properties and call functions on js objects in clojurescript https://www.verypossible.com/insights/clojurescript-and-javascript-interoperability-a-comprehensive-guide
Kind of newbie question, but I didn't find anything mention about it on https://github.com/bbatsov/clojure-style-guide: What I should use on imports, brackets or parenthesis
(ns foo (:import (java.util Date)))
;; or
(ns foo (:import [java.util Date]))
I'm improving clojure-lsp to add imports automatically, and not sure I should add a flag for those or just go with the most recommended way...
So no tradeoffs, it's just visually in the end? maybe we should mention it somewhere on the style guide
I think How to ns by Sierra mentioned parens, because the first symbol was special, but you could also say: avoid parens since they remind of a function call. 🤷
oh, there was where I saw that mention, thanks Yeah, TBH I don't have a personal preference, so I was expecting someone say: always use that because of X, kind of annoying need to support both by a flag 😔
@U064WBEPL’s https://stuartsierra.com/2016/clojure-how-to-ns.html#vectors-or-lists-1 for reference
It is defined in the style guide (via examples), i.e., https://guide.clojure.style/#sort-requirements-and-imports
I see no :import mention on that example @U11EL3P9U
Yeah I saw that one, but didn't convinced me as it doesn't explicitly tell about those
Its also referened here: https://clojure.org/guides/learn/namespaces
yeah, ATM clojure-lsp is using full-package-import sym so no vectors or list 😂 (I think I did that in the past to not need to choose between any of those 😂)
clojure core contributions usually don't change style things, not even whitespace. you can't just hit format in emacs and then write a patch (found this out the painful way of course)
does lsp rewrite the extreme cases like this in require? https://github.com/clj-commons/aleph/blob/master/src/aleph/http.clj#L9-L13
Nope, I know that exists but I have no idea what will happen TBH 😅 , it's not officially supported and IIRC it's not recommended anymore right?
it is supported by clojure, not by accident. SCI / bb also supports them (because of compatibility)
"Programming Clojure" 2e by Halloway & Bedra uses parentheses on p.44 and square brackets on p.72
i wanted to use those in clojurescript because typing my-app.components.pages or my-app.api.middleware 67 times is a pain but sadly it's not in cljs 😞
something I noticed yesterday while playing with both styles + clojure-lsp: [a.b c\nd]
will get c indented under a
, and with (...) c and d will form a column
(:import (io.helidon.common.http Http$HeaderValue
Http$Status))
(:import [io.helidon.common.http Http$HeaderValue
Http$Status))
I find the former more readable personally, is that something we can/could customize if one would like to use [] and have the same indentation as with ()
the latter should hot happen, clojure-lsp should move all to the same line or all to the next line, BTW I made some improvements on that yesterday, maybe test with nightly #C032YH7P0R2
maybe, one thing I'm considering doing is calling cljfmt format after a clean-ns, to keep consistency, needs more research to avoid issues like that one
ah, my idea was to do that programaticaly on clojure-lsp side:
1. user reuqests clean-ns refactoring on editor
2. clojure-lsp does the clean-ns
3. clojure-lsp call cljfmt passing only the ns code to format
4. clojure-lsp returns the clean-ns code for editor apply
The idea was to add this 3.
during the clean-ns existing refactoring