rok commented on code in PR #13506:
URL: https://github.com/apache/arrow/pull/13506#discussion_r931723596
##########
r/R/dplyr-datetime-helpers.R:
##########
@@ -171,61 +171,35 @@ build_formats <- function(orders) {
# this is needed for 2 reasons:
# 1. strptime does not parse "2022-05" -> we add "-01", thus changing the
format,
# 2. for equivalence to lubridate, which parses `ym` to the first day of the
month
- short_orders <- c("ym", "my")
+ short_orders <- c("ym", "my", "yOm", "Omy")
+ quarter_orders <- c("yq", "qy")
if (any(orders %in% short_orders)) {
orders1 <- setdiff(orders, short_orders)
orders2 <- intersect(orders, short_orders)
orders2 <- paste0(orders2, "d")
orders <- unique(c(orders2, orders1))
}
-
- if (any(orders == "yq")) {
- orders1 <- setdiff(orders, "yq")
- orders2 <- "ymd"
- orders <- unique(c(orders1, orders2))
- }
-
- if (any(orders == "qy")) {
- orders1 <- setdiff(orders, "qy")
- orders2 <- "ymd"
- orders <- unique(c(orders1, orders2))
+ if (any(orders %in% quarter_orders)) {
+ orders <- c(setdiff(orders, quarter_orders), "ymd")
}
+ orders <- unique(orders)
- ymd_orders <- c("ymd", "ydm", "mdy", "myd", "dmy", "dym")
- ymd_hms_orders <- c(
- "ymd_HMS", "ymd_HM", "ymd_H", "dmy_HMS", "dmy_HM", "dmy_H", "mdy_HMS",
- "mdy_HM", "mdy_H", "ydm_HMS", "ydm_HM", "ydm_H"
- )
- # support "%I" hour formats
- ymd_ims_orders <- gsub("H", "I", ymd_hms_orders)
-
- supported_orders <- c(
- ymd_orders,
- ymd_hms_orders,
- gsub("_", " ", ymd_hms_orders), # allow "_", " " and "" as order separators
- gsub("_", "", ymd_hms_orders),
- ymd_ims_orders,
- gsub("_", " ", ymd_ims_orders), # allow "_", " " and "" as order separators
- gsub("_", "", ymd_ims_orders)
- )
-
- unsupported_passed_orders <- setdiff(orders, supported_orders)
- supported_passed_orders <- intersect(orders, supported_orders)
+ formats_list <- map(orders, build_format_from_order)
+ formats_length <- map(map(formats_list, nchar), max)
+ invalid_orders <- formats_length < 6
Review Comment:
I'm not exactly sure how to check if an order is valid as it really comes
down to strptime implementation used. I'm switching to detecting if no valid
formats are present or not and will check what lubridate does.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]