Skip to content

floor_date(x, unit = 'weeks') ignores lubridate.week.start option #509

Description

@MichaelJW

Hello,

floor_date(x, unit = 'weeks') returns the same value (the previous Sunday, in my testing) regardless of what the lubridate.week.start option is set to:

library(lubridate)

options(lubridate.week.start = 7)
wday(ymd('2017-01-02'))                         # 2
floor_date(ymd('2017-01-02'), unit = 'weeks')   # "2017-01-01"

options(lubridate.week.start = 1)
wday(ymd('2017-01-02'))                         # 1
floor_date(ymd('2017-01-02'), unit = 'weeks')   # "2017-01-01"

As the above snippet shows, even though the results of wday(x) change according to lubridate.week.start, the results of floor_date(x, unit = 'weeks') do not. Intuitively, if the week start is set to Sunday, then floor_date() should always return a Sunday; if the option is set to Monday, then the function should always return a Monday, and so on.

I believe the issue is actually due to the update() function also ignoring this option:

options(lubridate.week.start = 7)
update(ymd('2017-01-02'), wday = 1)     # "2017-01-01"
wday(ymd('2017-01-01'))                 # 1

options(lubridate.week.start = 1)
update(ymd('2017-01-02'), wday = 1)     # "2017-01-01"
wday(ymd('2017-01-01'))                 # 7

In the latter case, wday(update(x, wday = 1)) does not give a result of 1, even though we explicitly set wday = 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions