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

How can I compare two dates with specified precision? #137

Open
khmelevskii opened this issue Dec 17, 2018 · 1 comment
Open

How can I compare two dates with specified precision? #137

khmelevskii opened this issue Dec 17, 2018 · 1 comment

Comments

@khmelevskii
Copy link

Hello.

I need to compare two dates without hours, minutes, seconds.
I can do something like this:

(and
  (= (t/year date1) (t/year date2))
  (= (t/month date1) (t/month date2))
  (= (t/day date1) (t/day date2)))

but it looks verbose.
it would be great to have function something like this:

(same? date1 date2 :day)
(same? date1 date2 :hour)
(same? date1 date2 :month)
etc
@khmelevskii khmelevskii changed the title How can I compare two dates with other precision? How can I compare two dates with specified precision? Dec 17, 2018
@danielcompton
Copy link
Collaborator

Hi @khmelevskii, what are the types of the dates that you are comparing? UtcDateTimes? You could perhaps cast them to midnight and compare them with an equality check as an alternative.

I'm not sure whether a function like what you describe would fit into cljs-time, as its API is meant to be modelled after clj-time. Feel free to write it and drop a link to it here though. Also, if something like this exists in clj-time then I'm happy to revisit this more.

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

2 participants