tustvold commented on code in PR #3016:
URL: https://github.com/apache/arrow-rs/pull/3016#discussion_r1017699145


##########
arrow-cast/src/cast.rs:
##########
@@ -527,6 +534,29 @@ fn make_timestamp_array(
     }
 }
 
+fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
+    v: i64,
+    tz: Tz,
+) -> Result<NaiveTime, ArrowError> {
+    match as_datetime_with_timezone::<T>(v, tz) {
+        Some(dt) => Ok(dt.time()),
+        None => Err(ArrowError::CastError(format!(
+            "Failed to create naive time with {} {}",
+            std::any::type_name::<T>(),
+            v
+        ))),
+    }
+}
+
+fn as_timezone_res(tz: &Option<String>) -> Result<Tz, ArrowError> {
+    match tz {
+        Some(s) => s.parse(),
+        None => Err(ArrowError::ParseError(
+            "Timezone must not be none".to_string(),
+        )),
+    }
+}

Review Comment:
   We need to support both no timezone or a timezone, perhaps something like 
(not tested)
   
   
   ```suggestion
   fn as_time_res_with_timezone<T: ArrowPrimitiveType>(
       v: i64,
       tz: Option<Tz>,
   ) -> Result<NaiveTime, ArrowError> {
       let time = match tz {
           Some(tz) => as_datetime_with_timezone::<T>(v, tz).map(|d| d.time()),
           None => as_datetime::<T>(v).map(|d| d.time()),
       };
       
       time.ok_or_else(|| {
           ArrowError::CastError(format!(
               "Failed to create naive time with {} {}",
               std::any::type_name::<T>(),
               v
           ))
       })
   }
   ```
   
   And then parse the timezone with
   
   ```
   let tz = tz.map(|tz| tz.parse()).transpose()?
   ```



-- 
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]

Reply via email to