Skip to content

Documentation of as_date is misleading for as_datetime #1195

@deschen1

Description

@deschen1

Trying to convert a number to a datetime object fails as compared to converting it to a date object. The issue is with the documentation, where it says:

origin: a Date object, or something which can be coerced by as.Date(origin, ...) to such an object (default: the Unix epoch of "1970-01-01"). Note that in this instance, x is assumed to reflect the number of days since origin at "UTC".

However, this only seems to be correct for as_date, but not for as_datetime, which seems to expect the number of SECONDS since the origin.

as_date(45628.75, origin = "1899-12-30")
[1] "2024-12-04" # correct

as_datetime(45628.75, origin = "1899-12-30")
[1] "1899-12-30 12:40:28 UTC" # wrong

as_datetime(45628.75 * 86400, origin = "1899-12-30")
[1] "2024-12-02 18:00:00 UTC" # correct again

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