Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datetime is unintuitive/inaccurate for date arguments #44

Open
jf opened this issue Nov 15, 2024 · 0 comments
Open

datetime is unintuitive/inaccurate for date arguments #44

jf opened this issue Nov 15, 2024 · 0 comments

Comments

@jf
Copy link

jf commented Nov 15, 2024

given a date argument, datetime can be at best unintuitive, or at worst inaccurate, as opposed to a datetime. If I pass in today's date, depending on the time of day, my results would vary:

$ clj
Clojure 1.12.0
user=> (add-lib 'org.clj-commons/humanize)
[com.widdindustries/cljc.java-time com.widdindustries/cljs.java-time org.clj-commons/humanize]
user=> (require '[clj-commons.humanize :as h])
nil
user=> (h/datetime (java.time.LocalDate/now))
"5 hours ago"
user=>

passing in a date N days in the future, the intuitive result should be "in N days". Instead, I typically get a reply in the form of "in (N-1) days" where one day is dropped off because of the current time:

user=> (h/datetime (.plusDays (java.time.LocalDate/now) 1))
"in 18 hours"
user=> (h/datetime (.plusDays (java.time.LocalDate/now) 3))
"in 2 days"
user=>

Contrast this with how the number reported is as per the intuitive expected result when passing in a date N days in the past:

user=> (h/datetime (.minusDays (java.time.LocalDate/now) 1))
"1 day ago"
user=> (h/datetime (.minusDays (java.time.LocalDate/now) 3))
"3 days ago"

This really comes down to how, at the end of the day, everything is coerced to a datetime before doing the calculation, even if ultimately, I am only thinking in terms of dates / days for the difference (I think that would be the natural interpretation if a date, as opposed to a datetime, is passed in).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant