Skip to content

as.Date.POSIXct() inherit time zone #172

Description

@m-muecke

This wouldn't be backwards compatible, but I've seen many bugs due to using:

x <- as.POSIXct("2025-07-09 00:00:00", tz = "Europe/Zurich")
as.Date(x)
#> [1] "2025-07-08"
# instead of
as.Date(x, tz = attr(x, "tzone"))
#> [1] "2025-07-09"
# or use a date library instead
lubridate::as_date(x)
#> [1] "2025-07-09"

Created on 2025-07-09 with reprex v2.1.1

I would argue that in most cases the user would expect the default to be the latter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions