Skip to content

POSIXct objects that differ by fractional seconds are considered equal when run manually but not within reprex()Β #1977

@billdenney

Description

@billdenney

When I ran the code below within reprex::reprex() I got the expected error below. When I ran it manually, I got no error.

testthat::expect_equal(
  as.POSIXct("2024-08-02 20:47:03.123", tz = "UTC"),
  as.POSIXct("2024-08-02 20:47:03", tz = "UTC")
)
#> Error: as.POSIXct("2024-08-02 20:47:03.123", tz = "UTC") not equal to as.POSIXct("2024-08-02 20:47:03", tz = "UTC").
#> 1/1 mismatches
#> [1] 2024-08-02 20:47:03.122 - 2024-08-02 20:47:03 == 0.123 secs

dput(as.POSIXct("2024-08-02 20:47:03.123", tz = "UTC"))
#> structure(1722631623.123, class = c("POSIXct", "POSIXt"), tzone = "UTC")
dput(as.POSIXct("2024-08-02 20:47:03", tz = "UTC"))
#> structure(1722631623, class = c("POSIXct", "POSIXt"), tzone = "UTC")

Created on 2024-08-03 with reprex v2.1.1

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