DateTimeOffset
struct · ferroui-base · v0.5.0
struct DateTimeOffset
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).
Members
MIN_VALUEMAX_VALUEUNIX_EPOCHnewtry_newfrom_ticksfrom_date_timefrom_date_time_offsetnowutc_nowoffsetdate_timeutc_date_timelocal_date_timedatetime_of_dayticksutc_ticksyearmonthdayday_of_yearday_of_weekhourminutesecondmillisecondaddsubtractsubtract_date_time_offsetadd_daysadd_monthsadd_yearsto_offsetto_local_timeto_universal_timecomparecompare_toequals_exactto_string_formattry_to_string_formatto_string_withto_string_providerparsetry_parse
MIN_VALUE
const MIN_VALUE: DateTimeOffset
The smallest value, 0001-01-01T00:00:00 +00:00.
MAX_VALUE
const MAX_VALUE: DateTimeOffset
The largest value, 9999-12-31T23:59:59.9999999 +00:00.
UNIX_EPOCH
const UNIX_EPOCH: DateTimeOffset
1970-01-01T00:00:00 +00:00.
new
fn new(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, offset: SignedDuration) -> 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.
try_new
fn try_new(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, offset: SignedDuration) -> Option<DateTimeOffset>
Like new; None instead of a panic.
from_ticks
fn from_ticks(ticks: i64, offset: SignedDuration) -> 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.
from_date_time
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.
from_date_time_offset
fn from_date_time_offset(date_time: DateTime, offset: SignedDuration) -> 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.
now
fn now() -> DateTimeOffset
The current date and time with the local offset.
utc_now
fn utc_now() -> DateTimeOffset
The current date and time with the offset zero.
offset
const fn offset(self: Self) -> SignedDuration
The offset from UTC.
date_time
const fn date_time(self: Self) -> DateTime
The clock date and time, of unspecified kind (.NET DateTime).
utc_date_time
const fn utc_date_time(self: Self) -> DateTime
The UTC date and time, of kind UTC (.NET UtcDateTime).
local_date_time
fn local_date_time(self: Self) -> DateTime
The date and time in local time, of kind local (.NET LocalDateTime).
date
const fn date(self: Self) -> DateTime
The clock date at midnight, of unspecified kind.
time_of_day
const fn time_of_day(self: Self) -> SignedDuration
The clock time elapsed since midnight.
ticks
const fn ticks(self: Self) -> i64
The ticks of the clock date and time.
utc_ticks
const fn utc_ticks(self: Self) -> i64
The ticks of the UTC date and time.
year
fn year(self: Self) -> i32
The year of the clock date.
month
fn month(self: Self) -> i32
The month of the clock date, 1..=12.
day
fn day(self: Self) -> i32
The day of the month of the clock date, 1..=31.
day_of_year
fn day_of_year(self: Self) -> i32
The day of the year of the clock date, 1..=366.
day_of_week
fn day_of_week(self: Self) -> DayOfWeek
The day of the week of the clock date.
hour
const fn hour(self: Self) -> i32
The hour of the clock time, 0..=23.
minute
const fn minute(self: Self) -> i32
The minute of the clock time, 0..=59.
second
const fn second(self: Self) -> i32
The second of the clock time, 0..=59.
millisecond
const fn millisecond(self: Self) -> i32
The millisecond of the clock time, 0..=999.
add
fn add(self: Self, value: SignedDuration) -> DateTimeOffset
The value value later, with the same offset. Panics when out of range.
subtract
fn subtract(self: Self, value: SignedDuration) -> DateTimeOffset
The value value earlier, with the same offset. Panics when out of range.
subtract_date_time_offset
fn subtract_date_time_offset(self: Self, other: DateTimeOffset) -> SignedDuration
The interval from other to this value (by UTC instants).
add_days
fn add_days(self: Self, value: f64) -> DateTimeOffset
The value value days later. Panics when out of range.
add_months
fn add_months(self: Self, months: i32) -> DateTimeOffset
The value months months later (see DateTime::add_months).
add_years
fn add_years(self: Self, years: i32) -> DateTimeOffset
The value years years later (see DateTime::add_years).
to_offset
fn to_offset(self: Self, offset: SignedDuration) -> DateTimeOffset
The same instant at another offset. Panics when the offset is invalid or the clock time at that offset is out of range.
to_local_time
fn to_local_time(self: 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.
to_universal_time
const fn to_universal_time(self: Self) -> DateTimeOffset
The same instant at the offset zero.
compare
fn compare(first: DateTimeOffset, second: DateTimeOffset) -> i32
Compares two values by their UTC instants: -1, 0 or 1.
compare_to
fn compare_to(self: Self, other: DateTimeOffset) -> i32
Compares this value with other by their UTC instants: -1, 0 or 1.
equals_exact
fn equals_exact(self: Self, other: DateTimeOffset) -> bool
Whether both the UTC instant and the offset are the same.
to_string_format
fn to_string_format(self: 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).
try_to_string_format
fn try_to_string_format(self: Self, format: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Result<String, FormatError>
Like to_string_format, but gives the error
of an invalid format string.
to_string_with
fn to_string_with(self: 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.
to_string_provider
fn to_string_provider(self: Self, provider: &impl DateTimeFormatProvider + ?Sized) -> String
Formats with the default format and the conventions of provider
(.NET ToString(IFormatProvider)).
parse
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),
the DateTimeStyles overloads and ParseExact.
try_parse
fn try_parse(text: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Option<DateTimeOffset>
Parses like parse; None on failure
(.NET DateTimeOffset.TryParse).
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeResourceKeyObjectPropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedToStringErasedDestructorIntoEitherCloneCopyFromStrDefaultFrom<DateTime>TryFrom<SystemTime>TryFrom<DateTimeOffset>PartialEqEqPartialOrdOrdHashAdd<SignedDuration>Sub<SignedDuration>SubAddAssign<SignedDuration>SubAssign<SignedDuration>DisplayDebugMarkupTypedValueTypeRegistration
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.