Skip to content

Commit

Permalink
Switch to lubridate for parsing dates
Browse files Browse the repository at this point in the history
  • Loading branch information
nruigrok committed Oct 5, 2023
1 parent 2864479 commit 26572c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Imports:
remotes,
rlang,
tibble,
utils
utils,
lubridate
Suggests:
covr,
dockr,
Expand Down
10 changes: 3 additions & 7 deletions R/lib.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 26572c9

Please sign in to comment.