MCPcopy Create free account
hub / github.com/apache/arrow-rs / as_time

Function as_time

arrow-array/src/temporal_conversions.rs:272–293  ·  view source on GitHub ↗

Converts an [`ArrowPrimitiveType`] to [`NaiveTime`]

(v: i64)

Source from the content-addressed store, hash-verified

270
271/// Converts an [`ArrowPrimitiveType`] to [`NaiveTime`]
272pub fn as_time<T: ArrowPrimitiveType>(v: i64) -> Option<NaiveTime> {
273 match T::DATA_TYPE {
274 DataType::Time32(unit) => {
275 // safe to immediately cast to u32 as `self.value(i)` is positive i32
276 let v = v as u32;
277 match unit {
278 TimeUnit::Second => time32s_to_time(v as i32),
279 TimeUnit::Millisecond => time32ms_to_time(v as i32),
280 _ => None,
281 }
282 }
283 DataType::Time64(unit) => match unit {
284 TimeUnit::Microsecond => time64us_to_time(v),
285 TimeUnit::Nanosecond => time64ns_to_time(v),
286 _ => None,
287 },
288 DataType::Timestamp(_, _) => as_datetime::<T>(v).map(|datetime| datetime.time()),
289 DataType::Date32 | DataType::Date64 => NaiveTime::from_hms_opt(0, 0, 0),
290 DataType::Interval(_) => None,
291 _ => None,
292 }
293}
294
295/// Converts an [`ArrowPrimitiveType`] to [`Duration`]
296pub fn as_duration<T: ArrowPrimitiveType>(v: i64) -> Option<Duration> {

Callers

nothing calls this directly

Calls 5

time32s_to_timeFunction · 0.85
time32ms_to_timeFunction · 0.85
time64us_to_timeFunction · 0.85
time64ns_to_timeFunction · 0.85
timeMethod · 0.45

Tested by

no test coverage detected