From 26572c9d6e728260a0ef092aca803d1f58ebbab7 Mon Sep 17 00:00:00 2001 From: Nel Ruigrok Date: Thu, 5 Oct 2023 10:15:21 +0200 Subject: [PATCH] Switch to lubridate for parsing dates --- DESCRIPTION | 3 ++- R/lib.R | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d71d2ca..526512d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,8 @@ Imports: remotes, rlang, tibble, - utils + utils, + lubridate Suggests: covr, dockr, diff --git a/R/lib.R b/R/lib.R index 3cec982..bfcc7c4 100644 --- a/R/lib.R +++ b/R/lib.R @@ -124,13 +124,9 @@ convert_datecols <- function(df, index) { datecols <- dplyr::filter(get_fields(index), type == "date")$name for (date_col in intersect(colnames(df), datecols)) { - # check if date or time - if (any(grepl("T", df[[date_col]], fixed = TRUE))) { - d_col <- strptime(df[[date_col]], format = "%Y-%m-%dT%H:%M:%S") - } else { - d_col <- as.Date(df[[date_col]]) - } - df[[date_col]] <- d_col + # AmCAT / elastic does not standardize date input/output, so try different formats + # (and maybe complain to whoever is in charge of AmCAT?) + df[[date_col]] <- lubridate::parse_date_time(df[[date_col]], orders=c("ymdHMSz", "ymdHMS", "ymdHM", "ymd")) } df }