Skip to content

Commit

Permalink
Precise time stamps for checking the process
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Feb 21, 2024
1 parent 8fe67df commit 58141c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 3 additions & 8 deletions R/utils_time.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
time_stamp <- function(time = Sys.time()) {
format(time, time_stamp_format, tz = "UTC")
}

posixct_time <- function(time_stamp) {
as.POSIXct(x = time_stamp, format = time_stamp_format, tz = "UTC")
format(time, "%Y-%m-%d %H:%M:%OS2", tz = "UTC")
}

time_stamp_short <- function(time = Sys.time()) {
Expand All @@ -18,7 +14,8 @@ time_stamp_pid <- function(pid = Sys.getpid()) {
if (is.null(handle)) {
return(NA_character_)
}
time_stamp(time = ps::ps_create_time(p = handle))
time <- ps::ps_create_time(p = handle)
format(time, "%Y-%m-%d %H:%M:%OS6", tz = "UTC")
}

time_seconds <- function() {
Expand All @@ -39,5 +36,3 @@ time_seconds_local <- function() {
as.numeric(proc.time()["elapsed"])
)
}

time_stamp_format <- "%Y-%m-%d %H:%M:%OS2"
5 changes: 3 additions & 2 deletions tests/testthat/test-utils_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ tar_test("time_seconds_local()", {

tar_test("time stamps", {
skip_cran()
expect_s3_class(posixct_time(time_stamp()), "POSIXct")
out <- time_stamp(time = Sys.time())
expect_true(is.character(out))
expect_false(anyNA(out))
})


tar_test("time stamp_pid", {
skip_cran()
out <- time_stamp_pid(pid = Sys.getpid())
Expand Down

0 comments on commit 58141c9

Please sign in to comment.