tidyverse / lubridate

Make working with dates in R just that little bit easier
https://lubridate.tidyverse.org
GNU General Public License v3.0
724 stars 207 forks source link

FR: int_overlaps with exclusive endpoints #1153

Open ismirsehregal opened 6 months ago

ismirsehregal commented 6 months ago

It would be great for int_overlaps to gain a exclusive parameter (for both - start and endpoint). Currently, via int_overlaps I can't properly test if a timestamp greater than 23:59:59 but smaller 00:00:00 of the next day belongs to a certain day.

# this includes endpoints greater than 23:59:59:
int_overlaps(interval(today(), today() + days(1)), interval(ymd_hms(paste(today(), "23:59:59.3")), today() + days(1)))

# but it also includes 00:00:00 of the next day:
int_overlaps(interval(today(), today() + days(1)), interval(today() + days(1), today() + days(2)))

# we can avoid this by removing one second from the first interval:
int_overlaps(interval(today(), today() + days(1) - seconds(1)), interval(today() + days(1), today() + days(2)))

# but this excludes endpoints greater than 23:59:59:
int_overlaps(interval(today(), today() + days(1) - seconds(1)), interval(ymd_hms(paste(today(), "23:59:59.3")), today() + days(1)))

For now I'm using format(my_timestamp, digits = 0L) / floor_date as a workaround.

Same question came up here: https://github.com/tidyverse/lubridate/issues/805 and here: https://stackoverflow.com/questions/27280338/exclusive-time-intervals-in-rs-lubridate