diff --git a/R/excel_time_to_numeric.R b/R/excel_time_to_numeric.R index 8a6eb66b..2632c7c6 100644 --- a/R/excel_time_to_numeric.R +++ b/R/excel_time_to_numeric.R @@ -10,8 +10,8 @@ #' \item{character}{Any of the following (or a mixture of the choices):} #' \itemize{ #' \item{A character string that is a number between 0 and 1 (exclusive of 1), converted like a numeric value.} -#' \item{A character string that looks like a date on 1899-12-31 (specifically, it must start with \code{"1899-12-31 "}), converted like a POSIXct object.} -#' \item{A character string that looks like a time. Choices are 12-hour time ""} +#' \item{A character string that looks like a date on 1899-12-31 (specifically, it must start with \code{"1899-12-31 "}), converted like a POSIXct object as described above.} +#' \item{A character string that looks like a time. Choices are 12-hour time as hour, minute, and optionally second followed by "am" or "pm" (case insensitive) or 24-hour time when hour, minute, optionally second, and no "am" or "pm" is included.} #' } #' } #' @@ -38,8 +38,8 @@ excel_time_to_numeric.logical <- function(time_value, round_seconds = TRUE) { #' @export excel_time_to_numeric.numeric <- function(time_value, round_seconds = TRUE) { if (all(is.na(time_value) | - time_value >= 0 & - time_value < 1)) { + (time_value >= 0 & + time_value < 1))) { seconds <- time_value * 86400 if (round_seconds) { seconds <- round(seconds) diff --git a/tests/testthat/test-excel_time_to_numeric.R b/tests/testthat/test-excel_time_to_numeric.R index e0fe0a31..da994fbb 100644 --- a/tests/testthat/test-excel_time_to_numeric.R +++ b/tests/testthat/test-excel_time_to_numeric.R @@ -8,6 +8,7 @@ test_that("excel_time_to_numeric numbers function correctly", { }) test_that("excel_time_to_numeric POSIX objects extract the correct part of the time", { + expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 00:01")), 60) expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 08:00")), 8 * 3600) expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 13:00")), 13 * 3600) expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 13:05:10")), 13 * 3600 + 5 * 60 + 10)