This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-08
Channels
- # announcements (1)
- # babashka (28)
- # beginners (13)
- # calva (10)
- # clerk (18)
- # clj-on-windows (39)
- # clj-otel (1)
- # cljdoc (17)
- # clojars (12)
- # clojure (40)
- # clojure-austin (11)
- # clojure-brasil (1)
- # clojure-europe (23)
- # clojure-nl (3)
- # clojure-norway (16)
- # clojure-uk (2)
- # clojurescript (28)
- # clr (4)
- # conjure (1)
- # emacs (14)
- # hoplon (6)
- # hyperfiddle (59)
- # interop (2)
- # leiningen (1)
- # off-topic (37)
- # pathom (1)
- # polylith (5)
- # portal (7)
- # reagent (9)
- # releases (3)
- # shadow-cljs (22)
- # spacemacs (6)
- # tools-build (12)
- # tools-deps (51)
- # web-security (6)
- # xtdb (7)
How do you handle working with time across Clojure & ClojureScript? I currently have clj-time
in the backend, which I gather can't be made to work in the browser. There's plenty of business logic that involves filtering in different intervals and so on that I'd like to share. Any favorite solutions?
@U6T7M9DBR as the clj-time readme says: "look at clojure.java-time if you want a Clojure wrapper for that, or cljc.java-time for a thin Clojure(Script) wrapper, or juxt/tick for another cross-platform option." You need cljs, so either cljc.java-time or tick.
https://github.com/juxt/tick to be exact (Googling "tick" is not fun! 🕷️)
The clj-time readme helpfully links to both projects:grin:
And you want to start with https://juxt.github.io/tick/#_intervals if I understand correctly
tick is a different model of time - if you just want "the same code" cljc-java-time is the way
tick is built on top of it, and there is stuff that might be worth considering in tick , but thats a bigger change than I think you want atm
Is there any way I can read and write a record? Say for example:
(ns test.core
(:require [cljs.data.xml :as xml]
[cljs.tools.reader :as t]))
(t/read-string (pr-str #xml/element{}))
gives me
#error {:message "No reader function for tag xml/element.", :data {:type :reader-exception, :ex-kind :reader-error}}
For reading - data readers should work just fine.
For converting - (into {} my-record)
.
@U2FRKM4TW data readers? Do you mean like edn?
To whom it may concern, the link to to the documentation for data_readers.cljc
.
https://clojure.org/reference/reader#tagged_literals
Even if the Clojure doc is just an essay collection, data_readers.cljc
deserves a headline. Really hard to find.
clojure.tools.reader
does not mention data_readers.cljc
. clojure.edn
doesn't, too - only links to the old Rich Hickey text about what edn should be.
https://clojuredocs.org/clojure.core/*data-readers*
data_readers.cljc
mentioned here, but the mechanism isn't obvious.
personally I hate data_readers.cljc
, since its some implicit state where the mere presence on the classpath changes how your code works.
there is also cljs.reader/register-tag-parser!
if you want to register it "globally"
> where the mere presence on the classpath changes how your code works
To be the devil's advocate - isn't that how all required namespaces work? ;) I get what you mean, but that file, along with user
and deps.edn
files in specific locations outside of the project, is something fixed and known, a part of Clojure itself.
if you ask me data_readers.cljc
is configuration, not code. as such it has no place on the classpath. but I also banned tagged literals in my code, and limit it to my data, so I'm never in a situation where I need a reader literal available to read my source code