Skip to content

Commit

Permalink
Fix #1274
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Feb 29, 2024
1 parent 0625aa2 commit 3dce80d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
20 changes: 10 additions & 10 deletions R/utils_cli.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cli_dispatched <- function(
print = TRUE,
pending = FALSE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
action <- if_any(pending, "dispatched (pending)", "dispatched")
msg <- paste(c(time, action, prefix, name), collapse = " ")
cli_blue_play(msg, print = print)
Expand All @@ -18,7 +18,7 @@ cli_completed <- function(
seconds_elapsed = NULL,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "completed", prefix, name), collapse = " ")
if (!is.null(seconds_elapsed)) {
msg_time <- paste0(" [", units_seconds(seconds_elapsed), "]")
Expand All @@ -28,13 +28,13 @@ cli_completed <- function(
}

cli_skip <- function(name, prefix = NULL, time_stamp = FALSE, print = TRUE) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "skipped", prefix, name), collapse = " ")
cli_green_check(msg, print = print)
}

cli_error <- function(name, prefix = NULL, time_stamp = FALSE, print = TRUE) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "errored", prefix, name), collapse = " ")
cli_red_x(msg, print = print)
}
Expand All @@ -45,7 +45,7 @@ cli_cancel <- function(
time_stamp = FALSE,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "canceled", prefix, name), collapse = " ")
cli_yellow_box(msg, print = print)
}
Expand All @@ -55,7 +55,7 @@ cli_pipeline_uptodate <- function(
seconds_elapsed = NULL,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "skipped pipeline"), collapse = " ")
if (!is.null(seconds_elapsed)) {
msg_time <- paste0(" [", units_seconds(seconds_elapsed), "]")
Expand All @@ -69,7 +69,7 @@ cli_pipeline_done <- function(
seconds_elapsed = NULL,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "ended pipeline"), collapse = " ")
if (!is.null(seconds_elapsed)) {
msg_time <- paste0(" [", units_seconds(seconds_elapsed), "]")
Expand All @@ -83,7 +83,7 @@ cli_pipeline_empty <- function(
seconds_elapsed = NULL,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "empty pipeline"), collapse = " ")
if (!is.null(seconds_elapsed)) {
msg_time <- paste0(" [", units_seconds(seconds_elapsed), "]")
Expand All @@ -97,7 +97,7 @@ cli_pipeline_errored <- function(
seconds_elapsed = NULL,
print = TRUE
) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "errored pipeline"), collapse = " ")
if (!is.null(seconds_elapsed)) {
msg_time <- paste0(" [", units_seconds(seconds_elapsed), "]")
Expand All @@ -107,7 +107,7 @@ cli_pipeline_errored <- function(
}

cli_workspace <- function(name, time_stamp = FALSE, print = TRUE) {
time <- if_any(time_stamp, time_stamp(), NULL)
time <- if_any(time_stamp, time_stamp_cli(), NULL)
msg <- paste(c(time, "recorded workspace", name), collapse = " ")
cli_blue_play(msg, print = print)
}
Expand Down
4 changes: 4 additions & 0 deletions R/utils_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ time_stamp <- function(time = Sys.time()) {
format(time, "%Y-%m-%d %H:%M:%OS2", tz = "UTC")
}

time_stamp_cli <- function(time = Sys.time()) {
paste(time_stamp(time = time), "UTC")
}

time_stamp_short <- function(time = Sys.time()) {
format(time, "%H:%M %OS2")
}
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-utils_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ tar_test("time_seconds_local()", {
expect_equal(2 * 2, 4)
})

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

tar_test("time_stamp_cli()", {
skip_cran()
out <- time_stamp_cli(time = Sys.time())
expect_true(is.character(out))
expect_false(anyNA(out))
expect_true(grepl("UTC$", out))
})

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

0 comments on commit 3dce80d

Please sign in to comment.