Fork me on GitHub
#clojure-doc
<
2023-10-30
>
adham05:10:10

Hi @seancorfield I was going through the Github repo for clojure-doc and I found this issue https://github.com/clojure-doc/clojure-doc.github.io/issues/44, I've been working with date/time quite a bit in the last 2~3 months and I'd like to contribute by writing the guide, https://github.com/clojure-doc/clojure-doc.github.io/tree/source#contributing-new-guides so here goes: • I want to point others towards the clojure.java-time lib instead of what comes first in search results which is clj-time a now deprecated lib. • Provide examples of using clojure.java-time in real-world applications, I use it with https://scicloj.github.io/tablecloth/ to build API endpoints that is consumed a front-end to build https://www.highcharts.com/ charts and graphs • I know what I'm writing about is mostly application/use-cases; I've found the https://dm3.github.io/clojure.java-time/README.html of clojure.java-time's README to be extensive and I must not copy that. What do you think?

seancorfield16:10:05

That would be great, thank you! As a maintainer of clj-time, I agree it shouldn't be used 🙂 and we use a mixture of clojure.java-time and pure Java Time via interop which I think is a sweet spot. I think it's worth mentioning https://github.com/henryw374/cljc.java-time since that is cross-platform, so perhaps showing at least some examples using both clojure.java-time and cljc.java-time. Worth mentioning juxt/tick as another option for date/time manipulation (I believe it's based on cljc.java-time but I haven't looked at it). But even a first pass entirely based on clojure.java-time would be a big help to the community, I think. Let me know if you need anything from me in order to get started.

adham13:10:28

I didn't know about juxt/tick I'll read on it and make a mention I got the repo running locally and I'm making edits and all is well for the "make changes" experience, now my current question is does a common style exist? I've looked at other cookbooks and it seems to be • What Clojure version does this guide cover • Intro/Preliminary Section • Recipes If I would follow this I'd be writing • What Clojure version does this guide cover • Intro/Preliminary Section ◦ Purpose/Context/Scope ◦ Libraries • Recipes ◦ clojure.java-time ◦ Java Time via interop ◦ ... Here I have the question of whether or not the recipes for different libraries should be mirrors or not, as in "This is how to add 1-day to today in clojure.java-time and how to do it with interop" or if it should be distinct recipes per lib What do you think?

seancorfield16:10:28

I think for the simple recipes, it would be good to show both java-time and interop. For now complex stuff, just java-time

adham20:11:22

Alright, sounds good, I'll begin work on it and have something to show by Saturday at most. Would a filing a PR be fine to get a first round of feedback? I believe I can make and push more changes later and the PR would be updated.

seancorfield20:11:54

That sounds great, yes. We can go through multiple rounds of changes in the PR if needed. Thank you!

adham20:11:38

Don't mention it! Then I'll begin and I'll let you know when I issue the PR

henryw37409:11:51

I would question whether the content suggested above belongs in this guide. I guess there's already a section on interop, so that would cover java.time, java.util.Date etc what might make sense is to cover • quirky things relating to clojure.core and dates • library features that add new capabilities (as opposed to sugar) quirky things for me would be #inst having a default reader and printer and the fact that the included date types can't be round-tripped - all covered in https://widdindustries.com/blog/what-is-inst.html (and linked from there https://ask.clojure.org/index.php/11898/printing-and-reading-date-types). tick and clojure.java-time are mostly just sugar - although there are some extra capabilities in them you might mention e.g. with-clock, but I think just pointing to https://www.clojure-toolbox.com/ would be fine tbh. other additional capabilities you could mention include: • cross platform - but again I don't know that this guide needs to go into it. • data-literals for date types not covered by #inst, and ability to round-trip • datafy and nav e.g. https://github.com/jimpil/jedi-time

adham20:11:55

Hey Henry, thank you for the feedback and comments What I had in mind when preparing this structure is to guide someone who is new to Clojure, has the basics down (REPL, Setting up a project) and wants to learn about using dates and time. I don't think there's anything to omit about libraries that are just sugar because I don't assume familiarity with the JVM and java.time and java.util.Date on the reader's part. From what I understood, what you are suggesting leans more towards a page of further reading about date and time in Clojure rather than a cookbook, let me know if I didn't understand you well

henryw37420:11:57

Yes exactly. If someone is new to working with date and time on the JVM then this https://docs.oracle.com/javase/tutorial/datetime/iso/overview.html is a good tutorial. Translating parts of that into clojure syntax doesn't seem like it would add anything useful. I would say the same for other platform APIs too.

henryw37420:11:51

But what could be useful is showing where clojure has some benefits when working with date time...for example the things I listed

seancorfield20:11:58

I think showing the Java Time interop for some of the Clojure examples is useful both to a) show how Clojure and the library can make things simpler and b) to show how you could do it with raw interop -- because one of the things that beginners tend to get told, here and in other forums, when they ask about date/time libraries is often "Oh, just use interop! It's not worth using a library."

seancorfield20:11:43

I think the cookbook should show some interop -- and could link to Oracle's overview page for more details.

seancorfield20:11:19

Let's perhaps get "Phase 1" of the cookbook done per @U03QTHYKXK7’s original suggestion and then we can do a "Phase 2" with some "further reading" and some of those quirks and caveats (which I agree definitely belong in a cookbook).

adham08:11:30

Alright I think this is a good resolution, after all I don't expect a "perfect" first pass on this and expect documentation to grow over time, I agree with @seancorfield that the quirks and caveats belong in the cookbook. I also agree with > Clojure and the library can make things simpler and > because one of the things that beginners tend to get told, here and in other forums, when they ask about date/time libraries is often "Oh, just use interop! It's not worth using a library." @U051B9FU1 One point I want to raise is that, for the moment at least, I won't demonstrate java.util.Date as it is legacy (https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html) but I'll mention it.

henryw37409:11:51

re https://clojurians.slack.com/archives/C02M6N5C137/p1698958018802909?thread_ts=1698642310.579109&cid=C02M6N5C137 for beginners to date/time, just use interop (as opposed to sugar) is the best advice in almost every case. everything they need is a google search and stackoverflow search away. in complete constrast to any clojure lib. but I'm just talking libs providing sugar. to avoid the problem of all beginners `

(.getYear (java.time.Instant/now))
` you can get https://widdindustries.com/blog/why-not-interop.html

henryw37409:11:29

re ne point I want to raise is that, for the moment at least, I won't demonstrate java.util.Date` as it is legacy (https://docs.oracle.com/javase/tutorial/datetime/iso/legacy.html) but I'll menti...` java.util.date may be on it's way out in the java world but it is alive and kicking in clojure. both in the clojure.core and dbs, incl. datomic afaik

adham18:11:27

Even if it is still alive and kicking in Clojure, I believe orienting beginners towards java-time will be better long term, as in not have new code be written with a legacy package.