Skip to content

Commit

Permalink
check plausible year for timestamp #68
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentvanhees committed Sep 26, 2024
1 parent 9e2ea7c commit 859ac7d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions R/utils_for_countdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ checkTimeFormat = function(timestamp_POSIX, rawValue = " ?? ", timeformat = " ??
" does not match with time format ", timeformat,
" as specified by argument ", timeformatName,
", please correct.\n"), call. = FALSE)
} else {
year = as.numeric(format(timestamp_POSIX, format = "%Y"))
if (year < 1980 || year > 2500) {
# Assumption that after 2500 no new ActiGraph data will be collected!
stop(paste0("\nTimestamp recognised as ", format(timestamp_POSIX),
" with year identified as ", year,
". This does not seem to be correct. Raw timestamp value is stored as ",
rawValue, ". please change specification of ",
"argument ", timeformatName, " (currently ",
timeformat, ") to ensure correct interpretation of timestamp.\n"),
call. = FALSE)
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion tests/testthat/test_readActiwatchCount.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ test_that("Actiwatch awd error correctly", {

})

test_that("checkTimeFormat also detect implausible year", {
rawValue = "6/28/21 10:10:10"
timeformat = "%m/%d/%y %H:%M:%S"
timestamp_POSIX = as.POSIXlt("6/28/21 10:10:10", format = "%m/%d/%Y %H:%M:%S")
expect_error(checkTimeFormat(timestamp_POSIX, rawValue = rawValue, timeformat = timeformat,
timeformatName = NULL),
regexpr = "Timestamp recognised as 0021*")

"\nThe short epoch size as specified by the user (5 seconds) does NOT match the short epoch size we see in the data (60 seconds). Please correct."
})

0 comments on commit 859ac7d

Please sign in to comment.