Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove utctime ref #2 #15

Merged
merged 1 commit into from
Mar 15, 2024
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
4 changes: 0 additions & 4 deletions R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ collectorGuess <- function(input, locale_, guessInteger) {
.Call(`_minty_collectorGuess`, input, locale_, guessInteger)
}

utctime_ <- function(year, month, day, hour, min, sec, psec) {
.Call(`_minty_utctime_`, year, month, day, hour, min, sec, psec)
}

parse_vector_ <- function(x, collectorSpec, locale_, na, trim_ws) {
.Call(`_minty_parse_vector_`, x, collectorSpec, locale_, na, trim_ws)
}
Expand Down
7 changes: 0 additions & 7 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -1272,13 +1272,6 @@ is_named <- function(x) {
all(nms != "" & !is.na(nms))
}

utctime <- function(year, month, day, hour, min, sec, psec) {
utctime_(
as.integer(year), as.integer(month), as.integer(day),
as.integer(hour), as.integer(min), as.integer(sec), as.numeric(psec)
)
}

POSIXct <- function(x, tz = "UTC") {
structure(x, class = c("POSIXct", "POSIXt"), tzone = tz)
}
Expand Down
8 changes: 0 additions & 8 deletions src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ extern "C" SEXP _minty_collectorGuess(SEXP input, SEXP locale_, SEXP guessIntege
return cpp11::as_sexp(collectorGuess(cpp11::as_cpp<cpp11::decay_t<const cpp11::strings&>>(input), cpp11::as_cpp<cpp11::decay_t<const cpp11::list&>>(locale_), cpp11::as_cpp<cpp11::decay_t<bool>>(guessInteger)));
END_CPP11
}
// datetime.cpp
cpp11::writable::doubles utctime_(const cpp11::integers& year, const cpp11::integers& month, const cpp11::integers& day, const cpp11::integers& hour, const cpp11::integers& min, const cpp11::integers& sec, const cpp11::doubles& psec);
extern "C" SEXP _minty_utctime_(SEXP year, SEXP month, SEXP day, SEXP hour, SEXP min, SEXP sec, SEXP psec) {
BEGIN_CPP11
return cpp11::as_sexp(utctime_(cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(year), cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(month), cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(day), cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(hour), cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(min), cpp11::as_cpp<cpp11::decay_t<const cpp11::integers&>>(sec), cpp11::as_cpp<cpp11::decay_t<const cpp11::doubles&>>(psec)));
END_CPP11
}
// parse.cpp
SEXP parse_vector_(const cpp11::strings& x, const cpp11::list& collectorSpec, const cpp11::list& locale_, const std::vector<std::string>& na, bool trim_ws);
extern "C" SEXP _minty_parse_vector_(SEXP x, SEXP collectorSpec, SEXP locale_, SEXP na, SEXP trim_ws) {
Expand All @@ -39,7 +32,6 @@ static const R_CallMethodDef CallEntries[] = {
{"_minty_collectorGuess", (DL_FUNC) &_minty_collectorGuess, 3},
{"_minty_parse_vector_", (DL_FUNC) &_minty_parse_vector_, 5},
{"_minty_type_convert_col", (DL_FUNC) &_minty_type_convert_col, 6},
{"_minty_utctime_", (DL_FUNC) &_minty_utctime_, 7},
{NULL, NULL, 0}
};
}
Expand Down
33 changes: 0 additions & 33 deletions src/datetime.cpp

This file was deleted.

25 changes: 5 additions & 20 deletions tests/testthat/test-parsing-datetime.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
test_that("utctime is equivalent to R conversion", {
year <- seq(0, 4000)
mon <- rep(3L, length(year))
day <- rep(1L, length(year))
zero_i <- rep(0L, length(year))
zero_d <- rep(0, length(year))

expect_equal(
utctime(year, mon, day, zero_i, zero_i, zero_i, zero_d),
ISOdatetime(year, mon, day, zero_i, zero_i, zero_i, tz = "UTC")
)
})

# Parsing ----------------------------------------------------------------------

r_parse <- function(x, fmt) as.POSIXct(strptime(x, fmt, tz = "UTC"))

test_that("%d, %m and %y", {
target <- utctime(2010L, 2L, 3L, 0L, 0L, 0L, 0)

target <- as.POSIXct("2010-02-03", tz = "UTC")
expect_equal(parse_datetime("10-02-03", "%y-%m-%d"), target)
expect_equal(parse_datetime("10-03-02", "%y-%d-%m"), target)
expect_equal(parse_datetime("03/02/10", "%d/%m/%y"), target)
expect_equal(parse_datetime("02/03/10", "%m/%d/%y"), target)
})

test_that("Compound formats work", {
target <- utctime(2010L, 2L, 3L, 0L, 0L, 0L, 0)

target <- as.POSIXct("2010-02-03", tz = "UTC")
expect_equal(parse_datetime("02/03/10", "%D"), target)
expect_equal(parse_datetime("2010-02-03", "%F"), target)
expect_equal(parse_datetime("10/02/03", "%x"), target)
Expand All @@ -44,7 +29,7 @@ test_that("%y matches R behaviour", {
})

test_that("%e allows leading space", {
expect_equal(parse_datetime("201010 1", "%Y%m%e"), utctime(2010L, 10L, 1L, 0L, 0L, 0L, 0))
expect_equal(parse_datetime("201010 1", "%Y%m%e"), as.POSIXct("2010-10-1", tz = "UTC"))
})

test_that("%OS captures partial seconds", {
Expand Down Expand Up @@ -221,8 +206,8 @@ test_that("same times with different offsets parsed as same time", {
# From http://en.wikipedia.org/wiki/ISO_8601#Time_offsets_from_UTC
same_time <- paste("2010-02-03", c("18:30Z", "22:30+04", "1130-0700", "15:00-03:30"))
parsed <- parse_datetime(same_time)

expect_equal(parsed, rep(utctime(2010L, 2L, 3L, 18L, 30L, 0L, 0), 4))
target <- as.POSIXct("2010-02-03 18:30:00", tz = "UTC")
expect_equal(parsed, rep(target, 4))
})

test_that("offsets can cross date boundaries", {
Expand Down