Fork me on GitHub
#fulcro
<
2023-01-11
>
Eva O16:01:43

I ran into this strange bug with date-time/set-timezone! I have a function (change-time [inst local-time]) that returns an inst with the time set to local-time. So for example

(= (dt/html-datetime-string->inst "2023-01-11T00:00:00")
   (change-time (dt/html-datetime-string->inst "2023-01-11T11:00:00") local-time/midnight))

Eva O16:01:31

When I call set-timezone! it stops working for all dates before 2015-11-02. Without set-timezone! it returns correctly. Here's the function:

(ns app.core
  (:require
   [cljc.java-time.instant :as instant]
   [cljc.java-time.local-date-time :as ldt]
   [cljc.java-time.local-time :as lt]
   [cljc.java-time.zoned-date-time :as zdt]
   [cljc.java-time.zone-id :as zone-id]
   [com.fulcrologic.rad.type-support.date-time :as dt]))

(defn change-time
  [inst local-time]
  ;; (dt/set-timezone! "America/New_York") ;; Uncomment to cause bug
  (let [z (zone-id/of "America/New_York")
        instant (instant/of-epoch-milli (inst-ms inst))
        dt (ldt/of-instant instant z)
        dt (ldt/with dt local-time)
        zdt (ldt/at-zone dt z)
        millis (instant/to-epoch-milli (zdt/to-instant zdt))
        result (js/Date. millis)]
    (js/console.log "inst" inst
                    "dt" (ldt/of-instant instant z)
                    "dt2" dt
                    "zdt" zdt
                    "result" result)
    result))

(defn ^:export start
  []
  (let [inst (js/Date. 1446350400000) ;; November 1, 2015 12:00:00 AM GMT-04:00
        local-time lt/midnight]
    ;; Should be Sun Nov 01 2015 00:00:00 GMT-0400
    ;; When broken it is Sat Oct 31 2015 01:00:00 GMT-0400
    (js/console.log (change-time inst local-time))))

Eva O16:01:42

This only happens in cljs not clj

tony.kay16:01:28

pretty sure the joda-time database is truncated for compactness…you can install one with more range if you need it. I think that is probably the problem

tony.kay16:01:47

see Reducing js-joda-timezone size

Eva O16:01:47

Wild. Adding ["@js-joda/timezone"] to the require fixed it. Thanks!

Eva O16:01:55

I feel like somewhere in one of the libraries there should be a warning in the README about this. Idk if it should be js-joda, cljc.java-time, or RAD

Eva O16:01:30

Actually probably not the RAD README. That'd be kinda weird. Maybe in the docstring of the date-time module

tony.kay16:01:36

I thought I did document it somewhere

tony.kay16:01:44

I don’t know if I’ve removed the selection from the source yet or not…TBH, I guess I should look

tony.kay16:01:48

Yeah, it’s still in the source on line 37 of date-time ns

Eva O16:01:11

Oh shoot you're right. My eyes glazed right over that

tony.kay16:01:07

So I guess if you require something after that, it’ll override it, but I should figure out some non-breaking way (if possible) to make that better

tony.kay16:01:13

it’s sort of a bad design to force that optimization onto unsuspecting users 😄 That, and it isn’t much of an optimization if you’re going to end up with both in your compiled bundle 😞

Eva O16:01:45

Yeah that makes sense. Thanks for the explanation

👍 2
tony.kay16:01:10

I guess I should require the entire database. The compressed size compared to todays network speeds are probably just not much of a concern. If you don’t use the date-time ns, you won’t get it.

Eva O17:01:25

I had another question. So the Fulcro Developers Guide explains how to create components just for their queries using defsc. But now there's nc and the even more new defnc. It looks like some of the components in fulcro have been migrated to nc, such as FormConfig. Is the new blessed way to create components just for their queries nc or is defsc still preferred?

tony.kay23:01:54

If you only need a query, then defnc is lighter weight. It still registers the component so that registry lookups work, which is necessary for UISM and some other bits that want to store the query by registry key instead of component.

tony.kay23:01:13

The intention of nc is for complete dynamic systems whre you want to create a query programatically on the fly

👍 2
Jakub Holý (HolyJak)20:01:30

I guess that adding something like > It registers the component so that registry lookups work, which is necessary for UISM and some other bits that want to store the query by registry key instead of component. The intention of nc is for complete dynamic systems whre you want to create a query programatically on the fly to the defnc docstring would be very helpful for users to understand whether to use this or nc . no?