Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions R/date.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
as_sys_time.Date <- function(x) {
names <- names(x)
x <- unstructure(x)
if (is.double(x)) {
x <- floor(x)
}
x <- duration_days(x)
new_sys_time_from_fields(x, PRECISION_DAY, names)
}
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ test_that("invalid dates must be resolved when converting to a Date", {
expect_snapshot_error(as.Date(year_month_day(2019, 2, 31)))
})

# ------------------------------------------------------------------------------
# as_sys_time()

test_that("converting to sys-time floors fractional dates (#191)", {
x <- new_date(c(-0.5, 1.5))
y <- new_date(c(-1, 1))

expect_identical(as_sys_time(x), as_sys_time(y))
expect_identical(as.Date(as_sys_time(x)), y)
})

test_that("converting to sys-time works with integer storage dates", {
# These can occur from `seq.Date(from, to, length.out)`
x <- structure(1L, class = "Date")
y <- new_date(1)

expect_identical(as_sys_time(x), as_sys_time(y))
expect_identical(as.Date(as_sys_time(x)), y)
})

# ------------------------------------------------------------------------------
# as_weekday()

Expand Down