dragosmg commented on code in PR #13506:
URL: https://github.com/apache/arrow/pull/13506#discussion_r930806145
##########
r/R/dplyr-datetime-helpers.R:
##########
@@ -240,25 +214,24 @@ build_formats <- function(orders) {
#' @noRd
build_format_from_order <- function(order) {
char_list <- list(
- "y" = c("%y", "%Y"),
- "m" = c("%m", "%B", "%b"),
- "d" = "%d",
- "H" = "%H",
- "M" = "%M",
- "S" = "%S",
- "I" = "%I"
+ "%T" = "%H-%M-%S",
+ "%y" = c("%y", "%Y"),
+ "%m" = c("%m", "%B", "%b"),
+ "%b" = c("%m", "%B", "%b")
)
- split_order <- strsplit(order, split = "")[[1]]
+ formats <- regmatches(order, gregexpr("(O{0,1}[a-zA-Z])", order))[[1]]
Review Comment:
Same as above, I think a comment / comments would make this easier to
follow.
##########
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 think adding some comments here would help for our future selves. For
example, on why you think 6 is a good threshold.
--
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]