Skip to content

wrong return type in ceiling_date when unit = "week" #479

Description

@shrektan

Hi, @vspinu, I tried the CRAN version of lubridate and found a bug related to ceiling_date when the unit = "week". It should return a date object instead of a datetime.

Here's the reproducible example:

library(lubridate)

# ceiling date returns a time
ceiling_date(ymd("20160927"), "week")
## [1] "2016-10-02 08:00:00 CST"

# while the floor_date returns a date
floor_date(ymd("20160927"), "week")
## [1] "2016-09-25"

Activity

  1. added a commit that references this issue on Sep 27, 2016
    d11aa4a
  2. shrektan commented on Sep 27, 2016

    @shrektan
    ContributorAuthor

    I've filed a PR.

  3. vspinu commented on Sep 27, 2016

    @vspinu
    Member

    It should return a date object instead of a datetime.

    Why do you think so?

    If it returns date for week, shouldn't it return date for "day", "month" and "year" as well?

  4. shrektan commented on Sep 27, 2016

    @shrektan
    ContributorAuthor

    It's true that day month and year returns a date. Isn't it?

  5. shrektan commented on Sep 27, 2016

    @shrektan
    ContributorAuthor

    @vspinu Here's is what's returned in lubridate version 1.6.0. As you can see, only unit = "week" behaves differently.

    ceiling_date(ymd("20160927"), "year")
    ## [1] "2017-01-01"
    ceiling_date(ymd("20160927"), "month")
    ## [1] "2016-10-01"
    ceiling_date(ymd("20160927"), "week")
    ## [1] "2016-10-02 08:00:00 CST"
    ceiling_date(ymd("20160927"), "day")
    ## [1] "2016-09-28"
  6. vspinu commented on Sep 27, 2016

    @vspinu
    Member

    Yes. You are right. I got confused for a second due to recent re-designing of rounding API.

  7. added a commit that references this issue on Sep 27, 2016
    21ffe91
  8. shrektan commented on Sep 27, 2016

    @shrektan
    ContributorAuthor

    It's a very powerful and useful package. Certainly it takes lots of effort to improve. 🍺

  9. added a commit that references this issue on Sep 27, 2016
    14774c8
  10. Henrik-P commented on Jun 12, 2017

    @Henrik-P

    Seems like this issue is alive again in lubridate_1.6.0:

    ceiling_date(ymd("20160927"), "year")
    # [1] "2017-01-01"
    
    ceiling_date(ymd("20160927"), "month")
    # [1] "2016-10-01"
    
    ceiling_date(ymd("20160927"), "week")
    # [1] "2016-10-02 02:00:00 CEST"
    
    ceiling_date(ymd("20160927"), "day")
    # [1] "2016-09-28"
    
    
  11. cderv commented on Jun 12, 2017

    @cderv
    Contributor

    It is ok in current development version of lubridate 1.6.0.9009.

    library(lubridate)
    ceiling_date(ymd("20160927"), "year")
    #> [1] "2017-01-01"
    ceiling_date(ymd("20160927"), "month")
    #> [1] "2016-10-01"
    ceiling_date(ymd("20160927"), "week")
    #> [1] "2016-10-02"
    ceiling_date(ymd("20160927"), "day")
    #> [1] "2016-09-28"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions