Skip to content

Commit

Permalink
Code review fixes and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
billdenney committed Nov 30, 2023
1 parent 56f3d7a commit ce621d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions R/excel_time_to_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.}
#' }
#' }
#'
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-excel_time_to_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ce621d3

Please sign in to comment.