thisisnic commented on a change in pull request #11105:
URL: https://github.com/apache/arrow/pull/11105#discussion_r714677839
##########
File path: r/R/dplyr-functions.R
##########
@@ -672,6 +672,40 @@ nse_funcs$strptime <- function(x, format = "%Y-%m-%d
%H:%M:%S", tz = NULL, unit
Expression$create("strptime", x, options = list(format = format, unit =
unit))
}
+nse_funcs$strftime <- function(x, format = "", tz = "", usetz = FALSE) {
+ if (usetz) {
+ format <- paste(format, "%Z")
+ }
+ if (tz == "") {
+ tz <- Sys.timezone()
+ }
+ # Arrow's strftime prints in timezone of the timestamp. To match R's
strftime behavior we first
+ # cast the timestamp to desired timezone. This is a metadata only change.
+ ts <- Expression$create("cast", x, options = list(to_type =
timestamp(x$type()$unit(), tz)))
+ Expression$create("strftime", ts, options = list(format = format, locale =
Sys.getlocale("LC_TIME")))
+}
+
+ISO8601_precision_map <-
+ list(y = "%Y",
+ ym = "%Y-%m",
+ ymd = "%Y-%m-%d",
+ ymdh = "%Y-%m-%dT%H",
+ ymdhm = "%Y-%m-%dT%H:%M",
+ ymdhms = "%Y-%m-%dT%H:%M:%S")
+
+nse_funcs$format_ISO8601 <- function(x, usetz = FALSE, precision = NULL, ...) {
+ if (is.null(precision)) {
+ precision <- "ymdhms"
+ }
+ if (is.null(format <- ISO8601_precision_map[[precision]])) {
+ stop("Invalid value for precision provided: ", precision)
+ }
Review comment:
Minor change to make the checking a little more idiomatic and expand the
error details.
```suggestion
if(!precision %in% names(ISO8601_precision_map)){
abort(
paste(
"`precision` must be one of the following values:",
paste(names(ISO8601_precision_map), collapse = ", "),
"\nValue supplied was: ",
precision
)
)
}
```
##########
File path: r/R/dplyr-functions.R
##########
@@ -672,6 +672,40 @@ nse_funcs$strptime <- function(x, format = "%Y-%m-%d
%H:%M:%S", tz = NULL, unit
Expression$create("strptime", x, options = list(format = format, unit =
unit))
}
+nse_funcs$strftime <- function(x, format = "", tz = "", usetz = FALSE) {
+ if (usetz) {
+ format <- paste(format, "%Z")
+ }
+ if (tz == "") {
+ tz <- Sys.timezone()
+ }
+ # Arrow's strftime prints in timezone of the timestamp. To match R's
strftime behavior we first
+ # cast the timestamp to desired timezone. This is a metadata only change.
+ ts <- Expression$create("cast", x, options = list(to_type =
timestamp(x$type()$unit(), tz)))
+ Expression$create("strftime", ts, options = list(format = format, locale =
Sys.getlocale("LC_TIME")))
+}
+
+ISO8601_precision_map <-
Review comment:
Please could you pop this list inside the function?
--
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]