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

Equal to == operator doesn't work as expected with lubridate intervals #1135

Open
jakemanger opened this issue Sep 26, 2023 · 2 comments · May be fixed by #1136
Open

Equal to == operator doesn't work as expected with lubridate intervals #1135

jakemanger opened this issue Sep 26, 2023 · 2 comments · May be fixed by #1136

Comments

@jakemanger
Copy link

jakemanger commented Sep 26, 2023

If you attempt to use an == check with lubridate intervals, it uses the interval duration, rather than the interval object itself.

Reading the docs for lubridate::interval, this doesn't seem like this should be the default behaviour. Shouldn't this act like comparing two time ranges?

library(lubridate)
> interval(start=ymd('2018-01-01'), end=ymd('2018-01-02')) == interval(start=ymd('2018-01-02'), end=ymd('2018-01-02')) 
[1] FALSE
> interval(start=ymd('2018-01-01'), end=ymd('2018-01-02')) == interval(start=ymd('2018-01-03'), end=ymd('2018-01-04')) 
[1] TRUE

Note, I am using lubridate 1.9.2

@jakemanger jakemanger changed the title Equal to == operator doesn't work with lubridate intervals Equal to == operator doesn't work with lubridate intervals when created with a date string Sep 26, 2023
@jakemanger jakemanger changed the title Equal to == operator doesn't work with lubridate intervals when created with a date string Equal to == operator doesn't work as expected with lubridate intervals Sep 26, 2023
@vspinu
Copy link
Member

vspinu commented Sep 27, 2023

Agreed. Intervals are not exactly comparable, so comparison operations don't make sense and == is a special case of those.

Two options, either implement comparison operations as a partial order or, alternatively, error on all comparisons.

@jakemanger
Copy link
Author

@vspinu I believe the comparison as a partial order approach would be much more useful (at least for me). I've implemented a proposed solution here #1136

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

Successfully merging a pull request may close this issue.

2 participants