Skip to main content

DateTimeOffset

Struct DateTimeOffset 

Source
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

Source

pub const MIN_VALUE: DateTimeOffset

The smallest value, 0001-01-01T00:00:00 +00:00.

Source

pub const MAX_VALUE: DateTimeOffset

The largest value, 9999-12-31T23:59:59.9999999 +00:00.

Source

pub const UNIX_EPOCH: DateTimeOffset

1970-01-01T00:00:00 +00:00.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn now() -> DateTimeOffset

The current date and time with the local offset.

Source

pub fn utc_now() -> DateTimeOffset

The current date and time with the offset zero.

Source

pub const fn offset(self) -> TimeSpan

The offset from UTC.

Source

pub const fn date_time(self) -> DateTime

The clock date and time, of unspecified kind (.NET DateTime).

Source

pub const fn utc_date_time(self) -> DateTime

The UTC date and time, of kind UTC (.NET UtcDateTime).

Source

pub fn local_date_time(self) -> DateTime

The date and time in local time, of kind local (.NET LocalDateTime).

Source

pub const fn date(self) -> DateTime

The clock date at midnight, of unspecified kind.

Source

pub const fn time_of_day(self) -> TimeSpan

The clock time elapsed since midnight.

Source

pub const fn ticks(self) -> i64

The ticks of the clock date and time.

Source

pub const fn utc_ticks(self) -> i64

The ticks of the UTC date and time.

Source

pub fn year(self) -> i32

The year of the clock date.

Source

pub fn month(self) -> i32

The month of the clock date, 1..=12.

Source

pub fn day(self) -> i32

The day of the month of the clock date, 1..=31.

Source

pub fn day_of_year(self) -> i32

The day of the year of the clock date, 1..=366.

Source

pub fn day_of_week(self) -> DayOfWeek

The day of the week of the clock date.

Source

pub const fn hour(self) -> i32

The hour of the clock time, 0..=23.

Source

pub const fn minute(self) -> i32

The minute of the clock time, 0..=59.

Source

pub const fn second(self) -> i32

The second of the clock time, 0..=59.

Source

pub const fn millisecond(self) -> i32

The millisecond of the clock time, 0..=999.

Source

pub fn add(self, value: TimeSpan) -> DateTimeOffset

The value value later, with the same offset. Panics when out of range.

Source

pub fn subtract(self, value: TimeSpan) -> DateTimeOffset

The value value earlier, with the same offset. Panics when out of range.

Source

pub fn subtract_date_time_offset(self, other: DateTimeOffset) -> TimeSpan

The interval from other to this value (by UTC instants).

Source

pub fn add_days(self, value: f64) -> DateTimeOffset

The value value days later. Panics when out of range.

Source

pub fn add_months(self, months: i32) -> DateTimeOffset

The value months months later (see DateTime::add_months).

Source

pub fn add_years(self, years: i32) -> DateTimeOffset

The value years years later (see DateTime::add_years).

Source

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.

Source

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.

Source

pub const fn to_universal_time(self) -> DateTimeOffset

The same instant at the offset zero.

Source

pub fn compare(first: DateTimeOffset, second: DateTimeOffset) -> i32

Compares two values by their UTC instants: -1, 0 or 1.

Source

pub fn compare_to(self, other: DateTimeOffset) -> i32

Compares this value with other by their UTC instants: -1, 0 or 1.

Source

pub fn equals_exact(self, other: DateTimeOffset) -> bool

Whether both the UTC instant and the offset are the same.

Source

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).

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source§

type Output = DateTimeOffset

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeSpan) -> DateTimeOffset

Performs the + operation. Read more
Source§

impl AddAssign<TimeSpan> for DateTimeOffset

Source§

fn add_assign(&mut self, rhs: TimeSpan)

Performs the += operation. Read more
Source§

impl Clone for DateTimeOffset

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for DateTimeOffset

Source§

impl Debug for DateTimeOffset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DateTimeOffset

Source§

fn default() -> Self

DateTimeOffset::MIN_VALUE, the C# default(DateTimeOffset).

Source§

impl Display for DateTimeOffset

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The short date, long time and offset of the current culture (.NET ToString()).

Source§

impl Eq for DateTimeOffset

Source§

impl From<DateTime> for DateTimeOffset

Source§

fn from(value: DateTime) -> Self

The C# implicit conversion; see DateTimeOffset::from_date_time.

Source§

impl FromStr for DateTimeOffset

Source§

fn from_str(text: &str) -> Result<Self, Self::Err>

DateTimeOffset::parse: the invariant culture.

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

impl Hash for DateTimeOffset

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MarkupTyped for DateTimeOffset

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl Ord for DateTimeOffset

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for DateTimeOffset

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for DateTimeOffset

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub for DateTimeOffset

Source§

type Output = TimeSpan

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DateTimeOffset) -> TimeSpan

Performs the - operation. Read more
Source§

impl Sub<TimeSpan> for DateTimeOffset

Source§

type Output = DateTimeOffset

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeSpan) -> DateTimeOffset

Performs the - operation. Read more
Source§

impl SubAssign<TimeSpan> for DateTimeOffset

Source§

fn sub_assign(&mut self, rhs: TimeSpan)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.