#[cfg(feature = "python")]
use pyo3::prelude::*;
use crate::{Duration, Epoch};
#[cfg_attr(feature = "python", pymethods)]
impl Epoch {
pub fn with_hms(&self, hours: u64, minutes: u64, seconds: u64) -> Self {
let (sign, days, _, _, _, milliseconds, microseconds, nanoseconds) =
self.duration.decompose();
Self::from_duration(
Duration::compose(
sign,
days,
hours,
minutes,
seconds,
milliseconds,
microseconds,
nanoseconds,
),
self.time_scale,
)
}
pub fn with_hms_from(&self, other: Self) -> Self {
let (sign, days, _, _, _, milliseconds, microseconds, nanoseconds) =
self.duration.decompose();
let other = other.to_time_scale(self.time_scale);
Self::from_duration(
Duration::compose(
sign,
days,
other.hours(),
other.minutes(),
other.seconds(),
milliseconds,
microseconds,
nanoseconds,
),
self.time_scale,
)
}
pub fn with_time_from(&self, other: Self) -> Self {
let (sign, days, _, _, _, _, _, _) = self.duration.decompose();
let (_, _, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) =
other.to_duration_in_time_scale(self.time_scale).decompose();
Self::from_duration(
Duration::compose(
sign,
days,
hours,
minutes,
seconds,
milliseconds,
microseconds,
nanoseconds,
),
self.time_scale,
)
}
pub fn with_hms_strict(&self, hours: u64, minutes: u64, seconds: u64) -> Self {
let (sign, days, _, _, _, _, _, _) = self.duration.decompose();
Self::from_duration(
Duration::compose(sign, days, hours, minutes, seconds, 0, 0, 0),
self.time_scale,
)
}
pub fn with_hms_strict_from(&self, other: Self) -> Self {
let (sign, days, _, _, _, _, _, _) = self.duration.decompose();
let other = other.to_time_scale(self.time_scale);
Self::from_duration(
Duration::compose(
sign,
days,
other.hours(),
other.minutes(),
other.seconds(),
0,
0,
0,
),
self.time_scale,
)
}
}