Skip to content

Inconsistent results dividing an interval by a period #926

Description

@petehobo

I'm using current version of lubridate (1.7.9) from CRAN.

While investigating some code left by a predecessor, I found the following inconsistency:

library(lubridate)
interval(ymd('2019-01-29'), ymd('2019-01-30'))/months(1)  # 0.06451613
interval(ymd('2020-01-29'), ymd('2020-01-30'))/months(1)  # 0.03225806

The 2019 figure seems wrong, equating to 2 (/31) days, when it should be 1.

I have a workaround using time_length(), which returns consistent results

time_length(interval(ymd('2019-01-29'), ymd('2019-01-30')), 'month')  # 0.03225806
time_length(interval(ymd('2020-01-29'), ymd('2020-01-30')), 'month')  # 0.03225806

Perhaps the approach taken by my predecessor is an anti-pattern, but I figured it was worth raising, as it does seem like a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions