pub struct DateTimeOffset { /* private fields */ }Expand description
A date and time of day relative to UTC.
Equality, ordering and hashing consider the UTC instant only: two values
with different offsets that name the same instant are equal, as in .NET
(use equals_exact to compare the offsets too).
Implementations§
Source§impl DateTimeOffset
impl DateTimeOffset
Sourcepub const MIN_VALUE: DateTimeOffset
pub const MIN_VALUE: DateTimeOffset
The smallest value, 0001-01-01T00:00:00 +00:00.
Sourcepub const MAX_VALUE: DateTimeOffset
pub const MAX_VALUE: DateTimeOffset
The largest value, 9999-12-31T23:59:59.9999999 +00:00.
Sourcepub const UNIX_EPOCH: DateTimeOffset
pub const UNIX_EPOCH: DateTimeOffset
1970-01-01T00:00:00 +00:00.
Sourcepub fn new(
year: i32,
month: i32,
day: i32,
hour: i32,
minute: i32,
second: i32,
offset: TimeSpan,
) -> DateTimeOffset
pub fn new( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, offset: TimeSpan, ) -> DateTimeOffset
The given clock date and time at offset from UTC. Panics when the
date and time are invalid, the offset is not a whole number of
minutes within 14 hours of UTC, or the UTC instant is out of range.
Sourcepub fn try_new(
year: i32,
month: i32,
day: i32,
hour: i32,
minute: i32,
second: i32,
offset: TimeSpan,
) -> Option<DateTimeOffset>
pub fn try_new( year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, offset: TimeSpan, ) -> Option<DateTimeOffset>
Like new; None instead of a panic.
Sourcepub fn from_ticks(ticks: i64, offset: TimeSpan) -> DateTimeOffset
pub fn from_ticks(ticks: i64, offset: TimeSpan) -> DateTimeOffset
The clock time with ticks ticks at offset from UTC. Panics when
the ticks, the offset or the UTC instant are out of range.
Sourcepub fn from_date_time(date_time: DateTime) -> DateTimeOffset
pub fn from_date_time(date_time: DateTime) -> DateTimeOffset
The instant of a DateTime: a UTC value gets the offset zero, a
local or unspecified value the local offset at that time
(.NET new DateTimeOffset(DateTime)). Panics when the UTC instant is
out of range.
Sourcepub fn from_date_time_offset(
date_time: DateTime,
offset: TimeSpan,
) -> DateTimeOffset
pub fn from_date_time_offset( date_time: DateTime, offset: TimeSpan, ) -> DateTimeOffset
The clock time date_time at offset from UTC
(.NET new DateTimeOffset(DateTime, TimeSpan)). Panics when the offset
is invalid, when a UTC value is given a non-zero offset, when a local
value is given an offset other than the local one, or when the UTC
instant is out of range.
Sourcepub fn now() -> DateTimeOffset
pub fn now() -> DateTimeOffset
The current date and time with the local offset.
Sourcepub fn utc_now() -> DateTimeOffset
pub fn utc_now() -> DateTimeOffset
The current date and time with the offset zero.
Sourcepub const fn date_time(self) -> DateTime
pub const fn date_time(self) -> DateTime
The clock date and time, of unspecified kind (.NET DateTime).
Sourcepub const fn utc_date_time(self) -> DateTime
pub const fn utc_date_time(self) -> DateTime
The UTC date and time, of kind UTC (.NET UtcDateTime).
Sourcepub fn local_date_time(self) -> DateTime
pub fn local_date_time(self) -> DateTime
The date and time in local time, of kind local (.NET LocalDateTime).
Sourcepub const fn time_of_day(self) -> TimeSpan
pub const fn time_of_day(self) -> TimeSpan
The clock time elapsed since midnight.
Sourcepub fn day_of_year(self) -> i32
pub fn day_of_year(self) -> i32
The day of the year of the clock date, 1..=366.
Sourcepub fn day_of_week(self) -> DayOfWeek
pub fn day_of_week(self) -> DayOfWeek
The day of the week of the clock date.
Sourcepub const fn millisecond(self) -> i32
pub const fn millisecond(self) -> i32
The millisecond of the clock time, 0..=999.
Sourcepub fn add(self, value: TimeSpan) -> DateTimeOffset
pub fn add(self, value: TimeSpan) -> DateTimeOffset
The value value later, with the same offset. Panics when out of range.
Sourcepub fn subtract(self, value: TimeSpan) -> DateTimeOffset
pub fn subtract(self, value: TimeSpan) -> DateTimeOffset
The value value earlier, with the same offset. Panics when out of range.
Sourcepub fn subtract_date_time_offset(self, other: DateTimeOffset) -> TimeSpan
pub fn subtract_date_time_offset(self, other: DateTimeOffset) -> TimeSpan
The interval from other to this value (by UTC instants).
Sourcepub fn add_days(self, value: f64) -> DateTimeOffset
pub fn add_days(self, value: f64) -> DateTimeOffset
The value value days later. Panics when out of range.
Sourcepub fn add_months(self, months: i32) -> DateTimeOffset
pub fn add_months(self, months: i32) -> DateTimeOffset
The value months months later (see DateTime::add_months).
Sourcepub fn add_years(self, years: i32) -> DateTimeOffset
pub fn add_years(self, years: i32) -> DateTimeOffset
The value years years later (see DateTime::add_years).
Sourcepub fn to_offset(self, offset: TimeSpan) -> DateTimeOffset
pub fn to_offset(self, offset: TimeSpan) -> DateTimeOffset
The same instant at another offset. Panics when the offset is invalid or the clock time at that offset is out of range.
Sourcepub fn to_local_time(self) -> DateTimeOffset
pub fn to_local_time(self) -> DateTimeOffset
The same instant at the local offset. A clock time that would leave the range keeps the instant and gets the offset zero.
Sourcepub const fn to_universal_time(self) -> DateTimeOffset
pub const fn to_universal_time(self) -> DateTimeOffset
The same instant at the offset zero.
Sourcepub fn compare(first: DateTimeOffset, second: DateTimeOffset) -> i32
pub fn compare(first: DateTimeOffset, second: DateTimeOffset) -> i32
Compares two values by their UTC instants: -1, 0 or 1.
Sourcepub fn compare_to(self, other: DateTimeOffset) -> i32
pub fn compare_to(self, other: DateTimeOffset) -> i32
Compares this value with other by their UTC instants: -1, 0 or 1.
Sourcepub fn equals_exact(self, other: DateTimeOffset) -> bool
pub fn equals_exact(self, other: DateTimeOffset) -> bool
Whether both the UTC instant and the offset are the same.
Sourcepub fn to_string_format(
self,
format: &str,
provider: &(impl DateTimeFormatProvider + ?Sized),
) -> String
pub fn to_string_format( self, format: &str, provider: &(impl DateTimeFormatProvider + ?Sized), ) -> String
Formats with a standard or custom .NET date and time format string
and the conventions of provider. An empty format gives the short
date, the long time and the offset ("G" followed by zzz). Panics
when the format string is invalid (.NET throws FormatException).
Sourcepub fn try_to_string_format(
self,
format: &str,
provider: &(impl DateTimeFormatProvider + ?Sized),
) -> Result<String, FormatError>
pub fn try_to_string_format( self, format: &str, provider: &(impl DateTimeFormatProvider + ?Sized), ) -> Result<String, FormatError>
Like to_string_format, but gives the error
of an invalid format string.
Sourcepub fn to_string_with(self, format: &str) -> String
pub fn to_string_with(self, format: &str) -> String
Formats with a format string and the conventions of the current
culture (.NET ToString(string)). Panics when the format is invalid.
Sourcepub fn to_string_provider(
self,
provider: &(impl DateTimeFormatProvider + ?Sized),
) -> String
pub fn to_string_provider( self, provider: &(impl DateTimeFormatProvider + ?Sized), ) -> String
Formats with the default format and the conventions of provider
(.NET ToString(IFormatProvider)).
Source§impl DateTimeOffset
impl DateTimeOffset
Sourcepub fn parse(
text: &str,
provider: &(impl DateTimeFormatProvider + ?Sized),
) -> Result<DateTimeOffset, FormatError>
pub fn parse( text: &str, provider: &(impl DateTimeFormatProvider + ?Sized), ) -> Result<DateTimeOffset, FormatError>
Parses a date and time with an optional offset written in the
conventions of provider (.NET
DateTimeOffset.Parse(string, IFormatProvider)): the forms
DateTime::parse accepts. The value has the offset the text
states; a text without an offset is a local time and gets the local
offset at that time, and a text without a date the current local
date, as in .NET. The offset is Z, GMT, or a signed hh:mm,
hhmm or h[h] after the time or the date. An offset of more than
14 hours and an instant outside of the years 1 to 9999 are errors.
Checked against results recorded from .NET for the invariant culture
(date_time_tests.rs, date_time_offset_parse_matches_net). Not
supported, as for DateTime::parse: what the heuristic parser of
.NET accepts beyond those forms (other time zone names, era names,
genitive month names), the DateTimeStyles overloads and
ParseExact.
Sourcepub fn try_parse(
text: &str,
provider: &(impl DateTimeFormatProvider + ?Sized),
) -> Option<DateTimeOffset>
pub fn try_parse( text: &str, provider: &(impl DateTimeFormatProvider + ?Sized), ) -> Option<DateTimeOffset>
Parses like parse; None on failure
(.NET DateTimeOffset.TryParse).
Trait Implementations§
Source§impl Add<TimeSpan> for DateTimeOffset
impl Add<TimeSpan> for DateTimeOffset
Source§type Output = DateTimeOffset
type Output = DateTimeOffset
+ operator.Source§impl AddAssign<TimeSpan> for DateTimeOffset
impl AddAssign<TimeSpan> for DateTimeOffset
Source§fn add_assign(&mut self, rhs: TimeSpan)
fn add_assign(&mut self, rhs: TimeSpan)
+= operation. Read moreSource§impl Clone for DateTimeOffset
impl Clone for DateTimeOffset
impl Copy for DateTimeOffset
Source§impl Debug for DateTimeOffset
impl Debug for DateTimeOffset
Source§impl Default for DateTimeOffset
impl Default for DateTimeOffset
Source§fn default() -> Self
fn default() -> Self
DateTimeOffset::MIN_VALUE, the C# default(DateTimeOffset).
Source§impl Display for DateTimeOffset
impl Display for DateTimeOffset
impl Eq for DateTimeOffset
Source§impl From<DateTime> for DateTimeOffset
impl From<DateTime> for DateTimeOffset
Source§fn from(value: DateTime) -> Self
fn from(value: DateTime) -> Self
The C# implicit conversion; see DateTimeOffset::from_date_time.
Source§impl FromStr for DateTimeOffset
impl FromStr for DateTimeOffset
Source§impl Hash for DateTimeOffset
impl Hash for DateTimeOffset
Source§impl MarkupTyped for DateTimeOffset
impl MarkupTyped for DateTimeOffset
Source§const MARKUP: &'static MarkupType
const MARKUP: &'static MarkupType
Source§impl Ord for DateTimeOffset
impl Ord for DateTimeOffset
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for DateTimeOffset
impl PartialEq for DateTimeOffset
Source§impl PartialOrd for DateTimeOffset
impl PartialOrd for DateTimeOffset
Source§impl Sub for DateTimeOffset
impl Sub for DateTimeOffset
Source§impl Sub<TimeSpan> for DateTimeOffset
impl Sub<TimeSpan> for DateTimeOffset
Source§type Output = DateTimeOffset
type Output = DateTimeOffset
- operator.Source§impl SubAssign<TimeSpan> for DateTimeOffset
impl SubAssign<TimeSpan> for DateTimeOffset
Source§fn sub_assign(&mut self, rhs: TimeSpan)
fn sub_assign(&mut self, rhs: TimeSpan)
-= operation. Read moreAuto Trait Implementations§
impl Freeze for DateTimeOffset
impl RefUnwindSafe for DateTimeOffset
impl Send for DateTimeOffset
impl Sync for DateTimeOffset
impl Unpin for DateTimeOffset
impl UnsafeUnpin for DateTimeOffset
impl UnwindSafe for DateTimeOffset
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more