Struct temporal_rs::components::duration::Duration
source · #[non_exhaustive]pub struct Duration { /* private fields */ }
Expand description
The native Rust implementation of Temporal.Duration
.
Duration
is made up of a DateDuration
and TimeDuration
as primarily
defined by Abtract Operation 7.5.1-5.
Implementations§
source§impl Duration
impl Duration
sourcepub fn new(
years: f64,
months: f64,
weeks: f64,
days: f64,
hours: f64,
minutes: f64,
seconds: f64,
milliseconds: f64,
microseconds: f64,
nanoseconds: f64
) -> TemporalResult<Self>
pub fn new( years: f64, months: f64, weeks: f64, days: f64, hours: f64, minutes: f64, seconds: f64, milliseconds: f64, microseconds: f64, nanoseconds: f64 ) -> TemporalResult<Self>
Creates a new validated Duration
.
sourcepub fn from_date_duration(date: &DateDuration) -> Self
pub fn from_date_duration(date: &DateDuration) -> Self
Creates a Duration
from only a DateDuration
.
sourcepub fn from_day_and_time(day: f64, time: &TimeDuration) -> Self
pub fn from_day_and_time(day: f64, time: &TimeDuration) -> Self
Creates a Duration
from a provided a day and a TimeDuration
.
Note: TimeDuration
records can store a day value to deal with overflow.
sourcepub fn from_partial(partial: &Duration) -> TemporalResult<Self>
pub fn from_partial(partial: &Duration) -> TemporalResult<Self>
Creates a new valid Duration
from a partial Duration
.
sourcepub fn is_time_within_range(&self) -> bool
pub fn is_time_within_range(&self) -> bool
Return if the Durations values are within their valid ranges.
source§impl Duration
impl Duration
sourcepub fn time(&self) -> &TimeDuration
pub fn time(&self) -> &TimeDuration
Returns a reference to the inner TimeDuration
sourcepub fn date(&self) -> &DateDuration
pub fn date(&self) -> &DateDuration
Returns a reference to the inner DateDuration
sourcepub fn set_time_duration(&mut self, time: TimeDuration)
pub fn set_time_duration(&mut self, time: TimeDuration)
Set this DurationRecord
’s TimeDuration
.
sourcepub fn set_months(&mut self, mo: f64)
pub fn set_months(&mut self, mo: f64)
Set the value for months
.
sourcepub fn set_minutes(&mut self, m: f64)
pub fn set_minutes(&mut self, m: f64)
Set the value for minutes
.
sourcepub fn set_seconds(&mut self, s: f64)
pub fn set_seconds(&mut self, s: f64)
Set the value for seconds
.
sourcepub fn set_milliseconds(&mut self, ms: f64)
pub fn set_milliseconds(&mut self, ms: f64)
Set the value for milliseconds
.
sourcepub const fn milliseconds(&self) -> f64
pub const fn milliseconds(&self) -> f64
Returns the hours
field of duration.
sourcepub fn set_microseconds(&mut self, mis: f64)
pub fn set_microseconds(&mut self, mis: f64)
Set the value for microseconds
.
sourcepub const fn microseconds(&self) -> f64
pub const fn microseconds(&self) -> f64
Returns the microseconds
field of duration.
sourcepub fn set_nanoseconds(&mut self, ns: f64)
pub fn set_nanoseconds(&mut self, ns: f64)
Set the value for nanoseconds
.
sourcepub const fn nanoseconds(&self) -> f64
pub const fn nanoseconds(&self) -> f64
Returns the nanoseconds
field of duration.
source§impl Duration
impl Duration
sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns whether the current Duration
is zero.
Equivalant to Temporal.Duration.blank()
.
sourcepub fn round<C: CalendarProtocol, Z: TzProtocol>(
&self,
increment: Option<f64>,
smallest_unit: Option<TemporalUnit>,
largest_unit: Option<TemporalUnit>,
rounding_mode: Option<TemporalRoundingMode>,
relative_to: &RelativeTo<'_, C, Z>,
context: &mut C::Context
) -> TemporalResult<Self>
pub fn round<C: CalendarProtocol, Z: TzProtocol>( &self, increment: Option<f64>, smallest_unit: Option<TemporalUnit>, largest_unit: Option<TemporalUnit>, rounding_mode: Option<TemporalRoundingMode>, relative_to: &RelativeTo<'_, C, Z>, context: &mut C::Context ) -> TemporalResult<Self>
Rounds the current Duration
.