forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rust, python): add dt.dst_offset feature (pola-rs#9629)
- Loading branch information
1 parent
906e379
commit 40af4dd
Showing
10 changed files
with
172 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#[cfg(feature = "timezones")] | ||
use chrono::TimeZone; | ||
#[cfg(feature = "timezones")] | ||
use chrono_tz::OffsetComponents; | ||
#[cfg(feature = "timezones")] | ||
use polars_arrow::time_zone::Tz; | ||
#[cfg(feature = "timezones")] | ||
use polars_core::prelude::*; | ||
#[cfg(feature = "timezones")] | ||
use polars_core::utils::arrow::temporal_conversions::{ | ||
timestamp_ms_to_datetime, timestamp_ns_to_datetime, timestamp_us_to_datetime, | ||
}; | ||
|
||
#[cfg(feature = "timezones")] | ||
pub fn dst_offset(ca: &DatetimeChunked, time_unit: &TimeUnit, time_zone: &Tz) -> DurationChunked { | ||
let timestamp_to_datetime = match time_unit { | ||
TimeUnit::Nanoseconds => timestamp_ns_to_datetime, | ||
TimeUnit::Microseconds => timestamp_us_to_datetime, | ||
TimeUnit::Milliseconds => timestamp_ms_to_datetime, | ||
}; | ||
ca.0.apply(|t| { | ||
let ndt = timestamp_to_datetime(t); | ||
let dt = time_zone.from_utc_datetime(&ndt); | ||
dt.offset().dst_offset().num_milliseconds() | ||
}) | ||
.into_duration(TimeUnit::Milliseconds) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters