struct RelativeCivil {
datetime: DateTime,
timestamp: Timestamp,
}
Expand description
A wrapper around a civil datetime and a timestamp corresponding to that civil datetime in UTC.
Haphazardly interpreting a civil datetime in UTC is an odd and usually incorrect thing to do. But the way we use it here is basically just to give it an “anchoring” point such that we can represent it using a single integer for rounding purposes. It is only used in a context relative to another civil datetime interpreted in UTC. In this fashion, the selection of UTC specifically doesn’t really matter. We could use any time zone. (Although, it must be a time zone without any transitions, otherwise we could wind up with time zone aware results in a context where that would be unexpected since this is civil time.)
Fields§
§datetime: DateTime
§timestamp: Timestamp
Implementations§
Source§impl RelativeCivil
impl RelativeCivil
Sourcefn new(datetime: DateTime) -> Result<RelativeCivil, Error>
fn new(datetime: DateTime) -> Result<RelativeCivil, Error>
Creates a new relative wrapper around the given civil datetime.
This wrapper bundles a timestamp for the given datetime by interpreting it as being in UTC. This is an “odd” thing to do, but it’s only used in the context of determining the length of time between two civil datetimes. So technically, any time zone without transitions could be used.
§Errors
This returns an error if the datetime could not be converted to a timestamp. This only occurs near the minimum and maximum civil datetime values.
Sourcefn checked_add(&self, span: Span) -> Result<RelativeCivil, Error>
fn checked_add(&self, span: Span) -> Result<RelativeCivil, Error>
Returns the result of DateTime::checked_add
.
§Errors
Returns an error in the same cases as DateTime::checked_add
. That is,
when adding the span to this zoned datetime would overflow.
This also returns an error if the resulting datetime could not be converted to a timestamp in UTC. This only occurs near the minimum and maximum datetime values.
Sourcefn checked_add_duration(
&self,
duration: SignedDuration,
) -> Result<RelativeCivil, Error>
fn checked_add_duration( &self, duration: SignedDuration, ) -> Result<RelativeCivil, Error>
Returns the result of DateTime::checked_add
with an absolute
duration.
§Errors
Returns an error in the same cases as DateTime::checked_add
. That is,
when adding the span to this zoned datetime would overflow.
This also returns an error if the resulting datetime could not be converted to a timestamp in UTC. This only occurs near the minimum and maximum datetime values.
Sourcefn until(&self, largest: Unit, other: &RelativeCivil) -> Result<Span, Error>
fn until(&self, largest: Unit, other: &RelativeCivil) -> Result<Span, Error>
Returns the result of DateTime::until
.
§Errors
Returns an error in the same cases as DateTime::until
. That is, when
the span for the given largest unit cannot be represented. This can
generally only happen when largest
is Unit::Nanosecond
and the span
cannot be represented as a 64-bit integer of nanoseconds.
Trait Implementations§
Source§impl Clone for RelativeCivil
impl Clone for RelativeCivil
Source§fn clone(&self) -> RelativeCivil
fn clone(&self) -> RelativeCivil
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more