# DateTimeOffset

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/utilities/struct-datetimeoffset/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

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

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L29)

## Members

- [`MIN_VALUE`](#assoc_const-min_value)
- [`MAX_VALUE`](#assoc_const-max_value)
- [`UNIX_EPOCH`](#assoc_const-unix_epoch)
- [`new`](#function-new)
- [`try_new`](#function-try_new)
- [`from_ticks`](#function-from_ticks)
- [`from_date_time`](#function-from_date_time)
- [`from_date_time_offset`](#function-from_date_time_offset)
- [`now`](#function-now)
- [`utc_now`](#function-utc_now)
- [`offset`](#function-offset)
- [`date_time`](#function-date_time)
- [`utc_date_time`](#function-utc_date_time)
- [`local_date_time`](#function-local_date_time)
- [`date`](#function-date)
- [`time_of_day`](#function-time_of_day)
- [`ticks`](#function-ticks)
- [`utc_ticks`](#function-utc_ticks)
- [`year`](#function-year)
- [`month`](#function-month)
- [`day`](#function-day)
- [`day_of_year`](#function-day_of_year)
- [`day_of_week`](#function-day_of_week)
- [`hour`](#function-hour)
- [`minute`](#function-minute)
- [`second`](#function-second)
- [`millisecond`](#function-millisecond)
- [`add`](#function-add)
- [`subtract`](#function-subtract)
- [`subtract_date_time_offset`](#function-subtract_date_time_offset)
- [`add_days`](#function-add_days)
- [`add_months`](#function-add_months)
- [`add_years`](#function-add_years)
- [`to_offset`](#function-to_offset)
- [`to_local_time`](#function-to_local_time)
- [`to_universal_time`](#function-to_universal_time)
- [`compare`](#function-compare)
- [`compare_to`](#function-compare_to)
- [`equals_exact`](#function-equals_exact)
- [`to_string_format`](#function-to_string_format)
- [`try_to_string_format`](#function-try_to_string_format)
- [`to_string_with`](#function-to_string_with)
- [`to_string_provider`](#function-to_string_provider)
- [`parse`](#function-parse)
- [`try_parse`](#function-try_parse)

<a id="assoc_const-min_value"></a>

### MIN_VALUE

```rust
const MIN_VALUE: DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L37)

<a id="assoc_const-max_value"></a>

### MAX_VALUE

```rust
const MAX_VALUE: DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L39)

<a id="assoc_const-unix_epoch"></a>

### UNIX_EPOCH

```rust
const UNIX_EPOCH: DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L41)

<a id="function-new"></a>

### new

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L65)

<a id="function-try_new"></a>

### try_new

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L71)

<a id="function-from_ticks"></a>

### from_ticks

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L87)

<a id="function-from_date_time"></a>

### from_date_time

```rust
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](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L96)

<a id="function-from_date_time_offset"></a>

### from_date_time_offset

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L111)

<a id="function-now"></a>

### now

```rust
fn now() -> DateTimeOffset
```

The current date and time with the local offset.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L124)

<a id="function-utc_now"></a>

### utc_now

```rust
fn utc_now() -> DateTimeOffset
```

The current date and time with the offset zero.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L129)

<a id="function-offset"></a>

### offset

```rust
const fn offset(self: Self) -> SignedDuration
```

The offset from UTC.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L137)

<a id="function-date_time"></a>

### date_time

```rust
const fn date_time(self: Self) -> DateTime
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L143)

<a id="function-utc_date_time"></a>

### utc_date_time

```rust
const fn utc_date_time(self: Self) -> DateTime
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L150)

<a id="function-local_date_time"></a>

### local_date_time

```rust
fn local_date_time(self: Self) -> DateTime
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L155)

<a id="function-date"></a>

### date

```rust
const fn date(self: Self) -> DateTime
```

The clock date at midnight, of unspecified kind.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L161)

<a id="function-time_of_day"></a>

### time_of_day

```rust
const fn time_of_day(self: Self) -> SignedDuration
```

The clock time elapsed since midnight.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L167)

<a id="function-ticks"></a>

### ticks

```rust
const fn ticks(self: Self) -> i64
```

The ticks of the clock date and time.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L173)

<a id="function-utc_ticks"></a>

### utc_ticks

```rust
const fn utc_ticks(self: Self) -> i64
```

The ticks of the UTC date and time.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L179)

<a id="function-year"></a>

### year

```rust
fn year(self: Self) -> i32
```

The year of the clock date.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L184)

<a id="function-month"></a>

### month

```rust
fn month(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L189)

<a id="function-day"></a>

### day

```rust
fn day(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L194)

<a id="function-day_of_year"></a>

### day_of_year

```rust
fn day_of_year(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L199)

<a id="function-day_of_week"></a>

### day_of_week

```rust
fn day_of_week(self: Self) -> DayOfWeek
```

The day of the week of the clock date.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L204)

<a id="function-hour"></a>

### hour

```rust
const fn hour(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L209)

<a id="function-minute"></a>

### minute

```rust
const fn minute(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L214)

<a id="function-second"></a>

### second

```rust
const fn second(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L219)

<a id="function-millisecond"></a>

### millisecond

```rust
const fn millisecond(self: Self) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L224)

<a id="function-add"></a>

### add

```rust
fn add(self: Self, value: SignedDuration) -> DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L237)

<a id="function-subtract"></a>

### subtract

```rust
fn subtract(self: Self, value: SignedDuration) -> DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L243)

<a id="function-subtract_date_time_offset"></a>

### subtract_date_time_offset

```rust
fn subtract_date_time_offset(self: Self, other: DateTimeOffset) -> SignedDuration
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L249)

<a id="function-add_days"></a>

### add_days

```rust
fn add_days(self: Self, value: f64) -> DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L255)

<a id="function-add_months"></a>

### add_months

```rust
fn add_months(self: Self, months: i32) -> DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L261)

<a id="function-add_years"></a>

### add_years

```rust
fn add_years(self: Self, years: i32) -> DateTimeOffset
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L267)

<a id="function-to_offset"></a>

### to_offset

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L276)

<a id="function-to_local_time"></a>

### to_local_time

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L284)

<a id="function-to_universal_time"></a>

### to_universal_time

```rust
const fn to_universal_time(self: Self) -> DateTimeOffset
```

The same instant at the offset zero.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L294)

<a id="function-compare"></a>

### compare

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

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L301)

<a id="function-compare_to"></a>

### compare_to

```rust
fn compare_to(self: Self, other: DateTimeOffset) -> i32
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L306)

<a id="function-equals_exact"></a>

### equals_exact

```rust
fn equals_exact(self: Self, other: DateTimeOffset) -> bool
```

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L311)

<a id="function-to_string_format"></a>

### to_string_format

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

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L322)

<a id="function-try_to_string_format"></a>

### try_to_string_format

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L331)

<a id="function-to_string_with"></a>

### to_string_with

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L342)

<a id="function-to_string_provider"></a>

### to_string_provider

```rust
fn to_string_provider(self: Self, provider: &impl DateTimeFormatProvider + ?Sized) -> String
```

Formats with the default format and the conventions of `provider`
(.NET `ToString(IFormatProvider)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L348)

<a id="function-parse"></a>

### parse

```rust
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`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L380)

<a id="function-try_parse"></a>

### try_parse

```rust
fn try_parse(text: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Option<DateTimeOffset>
```

Parses like `parse`; `None` on failure
(.NET `DateTimeOffset.TryParse`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/date_time_offset.rs#L402)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `FromStr`
- `Default`
- `From<DateTime>`
- `TryFrom<SystemTime>`
- `TryFrom<DateTimeOffset>`
- `PartialEq`
- `Eq`
- `PartialOrd`
- `Ord`
- `Hash`
- `Add<SignedDuration>`
- `Sub<SignedDuration>`
- `Sub`
- `AddAssign<SignedDuration>`
- `SubAssign<SignedDuration>`
- `Display`
- `Debug`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
