Path: blob/main/crates/polars-time/src/chunkedarray/time.rs
6939 views
use polars_core::chunked_array::temporal::time_to_time64ns;12use super::*;34pub trait TimeMethods {5/// Extract hour from underlying NaiveDateTime representation.6/// Returns the hour number from 0 to 23.7fn hour(&self) -> Int8Chunked;89/// Extract minute from underlying NaiveDateTime representation.10/// Returns the minute number from 0 to 59.11fn minute(&self) -> Int8Chunked;1213/// Extract second from underlying NaiveDateTime representation.14/// Returns the second number from 0 to 59.15fn second(&self) -> Int8Chunked;1617/// Extract second from underlying NaiveDateTime representation.18/// Returns the number of nanoseconds since the whole non-leap second.19/// The range from 1,000,000,000 to 1,999,999,999 represents the leap second.20fn nanosecond(&self) -> Int32Chunked;2122fn parse_from_str_slice(name: PlSmallStr, v: &[&str], fmt: &str) -> TimeChunked;23}2425impl TimeMethods for TimeChunked {26/// Extract hour from underlying NaiveDateTime representation.27/// Returns the hour number from 0 to 23.28fn hour(&self) -> Int8Chunked {29self.physical().apply_kernel_cast::<Int8Type>(&time_to_hour)30}3132/// Extract minute from underlying NaiveDateTime representation.33/// Returns the minute number from 0 to 59.34fn minute(&self) -> Int8Chunked {35self.physical()36.apply_kernel_cast::<Int8Type>(&time_to_minute)37}3839/// Extract second from underlying NaiveDateTime representation.40/// Returns the second number from 0 to 59.41fn second(&self) -> Int8Chunked {42self.physical()43.apply_kernel_cast::<Int8Type>(&time_to_second)44}4546/// Extract second from underlying NaiveDateTime representation.47/// Returns the number of nanoseconds since the whole non-leap second.48/// The range from 1,000,000,000 to 1,999,999,999 represents the leap second.49fn nanosecond(&self) -> Int32Chunked {50self.physical()51.apply_kernel_cast::<Int32Type>(&time_to_nanosecond)52}5354fn parse_from_str_slice(name: PlSmallStr, v: &[&str], fmt: &str) -> TimeChunked {55v.iter()56.map(|s| {57NaiveTime::parse_from_str(s, fmt)58.ok()59.as_ref()60.map(time_to_time64ns)61})62.collect_trusted::<Int64Chunked>()63.with_name(name)64.into_time()65}66}676869