alamb commented on a change in pull request #771:
URL: https://github.com/apache/arrow-rs/pull/771#discussion_r719695192
##########
File path: arrow/src/compute/kernels/temporal.rs
##########
@@ -294,4 +308,87 @@ mod tests {
assert!(!b.is_valid(1));
assert_eq!(7, b.value(2));
}
+
+ #[test]
+ fn test_temporal_array_timestamp_second_with_timezone() {
+ use std::sync::Arc;
+
+ let a = Arc::new(TimestampSecondArray::from_vec(
+ vec![10, 20],
+ Some("+00:00".to_string()),
Review comment:
I was thinking that maybe this test for `second` should be called with a
non zero offset, but then I realized that the answer will be the same, so this
is probably good enough coverage
##########
File path: arrow/src/compute/kernels/temporal.rs
##########
@@ -22,6 +22,60 @@ use chrono::{Datelike, Timelike};
use crate::array::*;
use crate::datatypes::*;
use crate::error::{ArrowError, Result};
+
+use chrono::format::strftime::StrftimeItems;
+use chrono::format::{parse, Parsed};
+
+macro_rules! extract_component_from_array {
+ ($array:ident, $builder:ident, $extract_fn:ident, $using:ident) => {
+ for i in 0..$array.len() {
+ if $array.is_null(i) {
+ $builder.append_null()?;
+ } else {
+ match $array.$using(i) {
+ Some(dt) => $builder.append_value(dt.$extract_fn() as
i32)?,
+ None => $builder.append_null()?,
+ }
+ }
+ }
+ };
+ ($array:ident, $builder:ident, $extract_fn:ident, $using:ident, $tz:ident,
$parsed:ident) => {
+ if ($tz.starts_with('+') || $tz.starts_with('-')) &&
!$tz.contains(':') {
+ return_compute_error_with!(
+ "Invalid timezone",
+ "Expected format [+-]XX:XX".to_string()
+ )
+ } else {
+ match parse(&mut $parsed, $tz, StrftimeItems::new("%z")) {
Review comment:
It is interesting that the [chrono
docs](https://docs.rs/chrono/0.4.19/chrono/format/strftime/index.html) suggests
that the correct format string would be `%:z` rather than `%z`.
```
%z | +0930 | Offset from the local time to UTC (with UTC being +0000).
%:z | +09:30 | Same as %z but with a colon.
```
However, I think your test cases look good and demonstrate the correct
parsing behavior.
--
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]