-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datetime fxns #53
Datetime fxns #53
Conversation
Only works if fix_utc_offset is used when reading date/time strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for slogging through date/times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good!
R/dates_and_times.R
Outdated
#' fix_utc_offset(datetimes) # returns c("2023-11-16T03:32:49+0700", "2023-11-16T03:32:49-0700", "2023-11-16T03:32:49", "2023-11-16T03:32:49+0000") and warns about missing offset (see third element) | ||
#' | ||
fix_utc_offset <- function(datetime_strings) { | ||
datetime_strings <- stringr::str_replace_all(datetime_strings, "[−‐‑‒–—―﹘﹣-]", "-") # replace every possible type of dash with a regular minus sign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like non-ascii characters, likely in this line mucking up the package build.
fix_utc_offset <- function(datetime_strings) { | ||
datetime_strings <- stringr::str_replace_all(datetime_strings, "[−‐‑‒–—―﹘﹣-]", "-") # replace every possible type of dash with a regular minus sign | ||
|
||
datetime_strings <- stringr::str_replace_all(datetime_strings, "[\u2212\u2010\u2011\u2012\u2013\u2014\u2015\ufe58\ufe63\uff0d]", "-") # replace every possible type of dash with a regular minus sign |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, hopefully this does it!
Added fxn to make ISO 8601 formatted strings have R-friendly UTC offsets. In theory it shouldn't do anything to strings with no UTC offset.
Also moved convert_datetime_format to this package and fixed one of the regular expressions that had been commented out. Added a regular expression to replace UTC offset indicators (e.g. -hh, -hhhh) with %z. We should talk about how to handle format strings with "Z" to indicate UTC+0000 before you accept this PR.