#[repr(C)]pub struct Interval { /* private fields */ }
Expand description
Interval represents delta time.
Implementations§
Source§impl Interval
impl Interval
Sourcepub fn try_from_ymwd_hms(
years: i32,
months: i32,
weeks: i32,
days: i32,
hours: i32,
minutes: i32,
seconds: f64,
) -> Result<Interval, DateTimeError>
pub fn try_from_ymwd_hms( years: i32, months: i32, weeks: i32, days: i32, hours: i32, minutes: i32, seconds: f64, ) -> Result<Interval, DateTimeError>
Constructs Interval
from year, month, weak, day, hour, minute and second. second can indicate millisecond and microsecond.
Sourcepub fn add_interval(self, span: Self) -> Result<Self, DateTimeError>
pub fn add_interval(self, span: Self) -> Result<Self, DateTimeError>
Interval
subtracts Interval
.
Sourcepub fn negate(self) -> Result<Self, DateTimeError>
pub fn negate(self) -> Result<Self, DateTimeError>
Negate of Interval
.
Sourcepub fn sub_interval(self, span: Self) -> Result<Self, DateTimeError>
pub fn sub_interval(self, span: Self) -> Result<Self, DateTimeError>
Interval
subtracts Interval
.
Sourcepub fn justify_hours(self) -> Self
pub fn justify_hours(self) -> Self
Adjusts Interval
. so time
of Interval
contains less than a whole day, adding
the excess to day
of Interval
. This is useful for
situations (such as non-TZ) where ‘1 day’ = ‘24 hours’ is valid,
e.g. interval subtraction and division.
Sourcepub fn justify_days(self) -> Self
pub fn justify_days(self) -> Self
Adjust Interval
so day
of Interval
contains less than 30 days, adding
the excess to ‘month’.
Sourcepub fn justify_interval(self) -> Self
pub fn justify_interval(self) -> Self
Adjusts Interval
. so month
, day
, and time
portions are within
customary bounds. Specifically:
0 <= abs(time) < 24 hours
0 <= abs(day) < 30 days
Also, the sign bit on all three fields is made equal, so either
all three fields are negative or all are positive.
Sourcepub fn mul_f64(self, factor: f64) -> Result<Self, DateTimeError>
pub fn mul_f64(self, factor: f64) -> Result<Self, DateTimeError>
Interval
multiply float64.
Sourcepub fn div_f64(self, factor: f64) -> Result<Self, DateTimeError>
pub fn div_f64(self, factor: f64) -> Result<Self, DateTimeError>
Interval
divides float64.
Sourcepub fn try_from_str(
s: &str,
type_mod: i32,
format_type: IntervalStyle,
) -> Result<Self, DateTimeError>
pub fn try_from_str( s: &str, type_mod: i32, format_type: IntervalStyle, ) -> Result<Self, DateTimeError>
Parses Internal
from string.
Sourcepub fn format(
self,
interval_format: IntervalStyle,
) -> Result<String, DateTimeError>
pub fn format( self, interval_format: IntervalStyle, ) -> Result<String, DateTimeError>
Converts Interval
to string.
Trait Implementations§
Source§impl DateTime for Interval
impl DateTime for Interval
Source§fn date_part(
&self,
ty: FieldType,
unit: DateUnit,
) -> Result<Option<f64>, DateTimeError>
fn date_part( &self, ty: FieldType, unit: DateUnit, ) -> Result<Option<f64>, DateTimeError>
Extracts specified field from Interval
.
Source§fn truncate(&self, ty: FieldType, unit: DateUnit) -> Result<Self, DateTimeError>
fn truncate(&self, ty: FieldType, unit: DateUnit) -> Result<Self, DateTimeError>
Truncates Interval
to specified units.
Source§fn is_infinite(&self) -> bool
fn is_infinite(&self) -> bool
Source§impl From<Interval> for Time
Converts Interval
to Time
.
This is defined as producing the fractional-day portion of the interval.
Therefore, we can just ignore the months field. It is not real clear
what to do with negative intervals, but we choose to subtract the floor,
so that, say, ‘-2 hours’ becomes ‘22:00:00’.
impl From<Interval> for Time
Converts Interval
to Time
.
This is defined as producing the fractional-day portion of the interval.
Therefore, we can just ignore the months field. It is not real clear
what to do with negative intervals, but we choose to subtract the floor,
so that, say, ‘-2 hours’ becomes ‘22:00:00’.