Struct TimeOfDayPeriod
pub struct TimeOfDayPeriod<Tz>where
Tz: TimeZone,{
start: NaiveTime,
end: NaiveTime,
tz: Tz,
}time only.Expand description
A time period defined by a start and end time of day.
This type represents a recurring time period that occurs daily. For example, it can represent “09:00 to 17:00”.
The period is defined as [start, end) (start is inclusive and end is
exclusive).
The word “period” is used here instead of “interval” to avoid confusion with
Interval, which represents an absolute range between two fixed points in
time.
§Format
The string representation is in the format <start>-<end> <offset>.
<start> and <end> are either HH:MM, HH:MM:SS, or
HH:MM:SS.ssssss and <offset> is a fixed offset in the format ±HH:MM.
If the serde feature is enabled, the type can be serialized and
deserialized as a string in this format.
§Wrapping behavior
Since the period repeats every day, the time range is allowed to wrap around midnight. This can be used to represent time ranges like “22:00 to 02:00”, which would be interpreted as “22:00 today to 02:00 tomorrow”.
§Normal time range
Normal time ranges where start < end can be used to represent a time range
on a specific day.
00:00 12:00 00:00
|----------+----|-----------+---|
start end§Time range wrapping around midnight
If start >= end, the time range wraps around midnight.
This is useful for conditions that should be satisfied at night.
12:00 00:00 12:00
|-------+-------|-------+-------|
start endPeriods with start == end are considered full-day periods.
All full-day periods are equivalent.
§Time zone handling
Due to the messy nature of time zones (daylight saving time, historical changes, etc.), this type currently only supports fixed offset time zones for most operations.
Fields§
§start: NaiveTime§end: NaiveTime§tz: TzImplementations§
Source§impl<Tz> TimeOfDayPeriod<Tz>where
Tz: TimeZone,
impl<Tz> TimeOfDayPeriod<Tz>where
Tz: TimeZone,
Sourcepub const fn new(
start: NaiveTime,
end: NaiveTime,
timezone: Tz,
) -> TimeOfDayPeriod<Tz>
pub const fn new( start: NaiveTime, end: NaiveTime, timezone: Tz, ) -> TimeOfDayPeriod<Tz>
Creates a new period with the given time zone.
Sourcepub fn is_full_day(&self) -> bool
pub fn is_full_day(&self) -> bool
Returns true if the period represents a full day.
Source§impl TimeOfDayPeriod<FixedOffset>
impl TimeOfDayPeriod<FixedOffset>
Sourcepub const fn new_fixed(
start: NaiveTime,
end: NaiveTime,
offset: FixedOffset,
) -> TimeOfDayPeriod<FixedOffset>
pub const fn new_fixed( start: NaiveTime, end: NaiveTime, offset: FixedOffset, ) -> TimeOfDayPeriod<FixedOffset>
Creates a new period with a fixed offset time zone.
start and end are in the local time of the given offset.
Sourcepub fn start_utc(&self) -> NaiveTime
pub fn start_utc(&self) -> NaiveTime
Returns the start time in UTC.
This is only implemented for TimeOfDayPeriod<FixedOffset> because
for the general case the start time in UTC will vary depending on the
date.
Sourcepub fn end_utc(&self) -> NaiveTime
pub fn end_utc(&self) -> NaiveTime
Returns the end time in UTC.
See the explanation in start_utc for why this is
only implemented for TimeOfDayPeriod<FixedOffset>.
Sourcepub fn interval_on_day(&self, date: NaiveDate) -> Option<Interval<FixedOffset>>
pub fn interval_on_day(&self, date: NaiveDate) -> Option<Interval<FixedOffset>>
Returns the earliest interval that overlaps with a date.
For normal time ranges there is only one interval per day, but for time ranges that wrap around midnight, there are two intervals: one starting on the previous day and one on the current day. As specified, this function always returns the one starting on the previous day as it is the earliest one.
Sourcepub fn interval_for_datetime(
&self,
dt: DateTime<FixedOffset>,
) -> Option<Interval<FixedOffset>>
pub fn interval_for_datetime( &self, dt: DateTime<FixedOffset>, ) -> Option<Interval<FixedOffset>>
Returns the next interval after the given datetime.
If the datetime is already within the time range, a interval for the same day is returned (i.e. one that contains the given datetime).
Returns None if the interval is unrepresentable. This only
happens if the dt is already at the edge of the representable range.
Trait Implementations§
Source§impl<Tz> Clone for TimeOfDayPeriod<Tz>
impl<Tz> Clone for TimeOfDayPeriod<Tz>
Source§fn clone(&self) -> TimeOfDayPeriod<Tz>
fn clone(&self) -> TimeOfDayPeriod<Tz>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TimeOfDayPeriod<FixedOffset>
impl Debug for TimeOfDayPeriod<FixedOffset>
Source§impl<'de> Deserialize<'de> for TimeOfDayPeriod<FixedOffset>
impl<'de> Deserialize<'de> for TimeOfDayPeriod<FixedOffset>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<TimeOfDayPeriod<FixedOffset>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TimeOfDayPeriod<FixedOffset>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for TimeOfDayPeriod<FixedOffset>
impl Display for TimeOfDayPeriod<FixedOffset>
Source§impl FromStr for TimeOfDayPeriod<FixedOffset>
impl FromStr for TimeOfDayPeriod<FixedOffset>
Source§type Err = ParseError
type Err = ParseError
Source§fn from_str(
s: &str,
) -> Result<TimeOfDayPeriod<FixedOffset>, <TimeOfDayPeriod<FixedOffset> as FromStr>::Err>
fn from_str( s: &str, ) -> Result<TimeOfDayPeriod<FixedOffset>, <TimeOfDayPeriod<FixedOffset> as FromStr>::Err>
s to return a value of this type. Read moreSource§impl PartialEq for TimeOfDayPeriod<FixedOffset>
impl PartialEq for TimeOfDayPeriod<FixedOffset>
Source§fn eq(&self, other: &TimeOfDayPeriod<FixedOffset>) -> bool
fn eq(&self, other: &TimeOfDayPeriod<FixedOffset>) -> bool
self and other values to be equal, and is used by ==.