From 3dce80da95b0ac89da4cb953a8e5681627f64116 Mon Sep 17 00:00:00 2001 From: wlandau Date: Thu, 29 Feb 2024 14:03:02 -0500 Subject: [PATCH] Fix #1274 --- R/utils_cli.R | 20 ++++++++++---------- R/utils_time.R | 4 ++++ tests/testthat/test-utils_time.R | 10 +++++++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/R/utils_cli.R b/R/utils_cli.R index 04ebabef..57feb620 100644 --- a/R/utils_cli.R +++ b/R/utils_cli.R @@ -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) @@ -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), "]") @@ -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) } @@ -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) } @@ -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), "]") @@ -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), "]") @@ -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), "]") @@ -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), "]") @@ -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) } diff --git a/R/utils_time.R b/R/utils_time.R index 532ea0c0..0a52ef0b 100644 --- a/R/utils_time.R +++ b/R/utils_time.R @@ -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") } diff --git a/tests/testthat/test-utils_time.R b/tests/testthat/test-utils_time.R index fc63c55d..372ad5d0 100644 --- a/tests/testthat/test-utils_time.R +++ b/tests/testthat/test-utils_time.R @@ -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())