From 99abec0f82fefc6611d5dd56a255018e209a5e89 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 6 Dec 2024 09:40:01 -0500 Subject: [PATCH] Improve performance of `is_tz_present()` by vectorizing regex --- R/utils-date_time_parse.R | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/R/utils-date_time_parse.R b/R/utils-date_time_parse.R index 2d26793..0050fd4 100644 --- a/R/utils-date_time_parse.R +++ b/R/utils-date_time_parse.R @@ -44,14 +44,14 @@ is_time_present <- function(input) { is_tz_present <- function(input) { - any( - c( - grepl(get_tz_pattern_z(), input), - grepl(get_tz_pattern_hh(), input), - grepl(get_tz_pattern_hh_mm(), input), - grepl(get_tz_pattern_hhmm(), input) - ) + regex <- paste0( + get_tz_pattern_z(), + get_tz_pattern_hh(), + get_tz_pattern_hh_mm(), + get_tz_pattern_hhmm(), + collapse = "|" ) + any(grepl(regex, input)) } is_long_tzid_present <- function(input) {