diff --git a/NEWS.md b/NEWS.md index 31bd1fd..8677d13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # crew.aws.batch 0.0.8 * Deprecate retryable options because `crew` 1.0.0 no longer supports them. +* In the monitor, return `POSIXct` time stamps for `created`, `started`, and `stopped`. # crew.aws.batch 0.0.7 diff --git a/R/crew_monitor_aws_batch.R b/R/crew_monitor_aws_batch.R index 4e24b26..fe6b1a5 100644 --- a/R/crew_monitor_aws_batch.R +++ b/R/crew_monitor_aws_batch.R @@ -260,9 +260,9 @@ crew_class_monitor_aws_batch <- R6::R6Class( arn = character(0L), status = character(0L), reason = character(0L), - created = numeric(0L), - started = numeric(0L), - stopped = numeric(0L) + created = as.POSIXct(numeric(0L)), + started = as.POSIXct(numeric(0L)), + stopped = as.POSIXct(numeric(0L)) ) ) } @@ -277,9 +277,9 @@ crew_class_monitor_aws_batch <- R6::R6Class( out$statusReason, NA_character_ ), - created = out$createdAt, - started = if_any(length(out$startedAt), out$startedAt, NA_real_), - stopped = if_any(length(out$stoppedAt), out$stoppedAt, NA_real_) + created = as_timestamp(out$createdAt), + started = as_timestamp(out$startedAt), + stopped = as_timestamp(out$stoppedAt) ) # nocov end }, @@ -420,9 +420,9 @@ crew_class_monitor_aws_batch <- R6::R6Class( job$statusReason, NA_character_ ), - created = job$createdAt, - started = if_any(length(job$startedAt), job$startedAt, NA_real_), - stopped = if_any(length(job$stoppedAt), job$stoppedAt, NA_real_) + created = as_timestamp(job$createdAt), + started = as_timestamp(job$startedAt), + stopped = as_timestamp(job$stoppedAt) ) } } @@ -433,9 +433,9 @@ crew_class_monitor_aws_batch <- R6::R6Class( arn = character(0L), status = character(0L), reason = character(0L), - created = numeric(0L), - started = numeric(0L), - stopped = numeric(0L) + created = as.POSIXct(numeric(0L)), + started = as.POSIXct(numeric(0L)), + stopped = as.POSIXct(numeric(0L)) ) } out <- do.call(what = vctrs::vec_rbind, args = out) diff --git a/R/utils_time.R b/R/utils_time.R new file mode 100644 index 0000000..245b573 --- /dev/null +++ b/R/utils_time.R @@ -0,0 +1,3 @@ +as_timestamp <- function(x) { + as.POSIXct(if_any(length(x) > 0L, x / 1000, NA_real_)) +} diff --git a/tests/testthat/test-utils_time.R b/tests/testthat/test-utils_time.R new file mode 100644 index 0000000..d55ccef --- /dev/null +++ b/tests/testthat/test-utils_time.R @@ -0,0 +1,4 @@ +test_that("as_timestamp()", { + expect_true(anyNA(as_timestamp(numeric(0L)))) + expect_s3_class(as_timestamp(1000), "POSIXct") +})