Table of Contents

Struct ZonedDateTime

Namespace
LfrlAnvil.Chrono
Assembly
LfrlAnvil.Chrono.dll

Represents a DateTime with time zone.

public readonly struct ZonedDateTime : IEquatable<ZonedDateTime>, IComparable<ZonedDateTime>, IComparable
Implements
Inherited Members

Properties

DayOfMonth

Day of month component.

public int DayOfMonth { get; }

Property Value

int

DayOfWeek

Day of week component.

public IsoDayOfWeek DayOfWeek { get; }

Property Value

IsoDayOfWeek

DayOfYear

Day of year component.

public int DayOfYear { get; }

Property Value

int

IsAmbiguous

Checks whether or not this date time is ambiguous.

public bool IsAmbiguous { get; }

Property Value

bool

IsInDaylightSavingTime

Checks whether or not this date time is in daylight saving time.

public bool IsInDaylightSavingTime { get; }

Property Value

bool

IsLocal

Checks whether or not the TimeZone is local.

public bool IsLocal { get; }

Property Value

bool

IsUtc

Checks whether or not the TimeZone is UTC.

public bool IsUtc { get; }

Property Value

bool

Month

Month component.

public IsoMonthOfYear Month { get; }

Property Value

IsoMonthOfYear

TimeOfDay

TimeOfDay component.

public TimeOfDay TimeOfDay { get; }

Property Value

TimeOfDay

TimeZone

Time zone of this date time.

public TimeZoneInfo TimeZone { get; }

Property Value

TimeZoneInfo

Timestamp

Timestamp equivalent to this date time.

public Timestamp Timestamp { get; }

Property Value

Timestamp

UtcOffset

Calculates the UTC offset of this date time.

public Duration UtcOffset { get; }

Property Value

Duration

Value

Underlying DateTime value.

public DateTime Value { get; }

Property Value

DateTime

Year

Year component.

public int Year { get; }

Property Value

int

Methods

Add(Duration)

Creates a new ZonedDateTime instance by adding value to this instance.

[Pure]
public ZonedDateTime Add(Duration value)

Parameters

value Duration

Duration to add.

Returns

ZonedDateTime

New ZonedDateTime instance.

Add(Period)

Creates a new ZonedDateTime instance by adding value to this instance.

[Pure]
public ZonedDateTime Add(Period value)

Parameters

value Period

Period to add.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When result is not valid in this instance's TimeZone.

CompareTo(ZonedDateTime)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(ZonedDateTime other)

Parameters

other ZonedDateTime

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in the sort order.

CompareTo(object?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

[Pure]
public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

A value that indicates the relative order of the objects being compared. The return value has these meanings:

Value Meaning
Less than zero This instance precedes obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is not the same type as this instance.

Create(DateTime, TimeZoneInfo)

Creates a new ZonedDateTime instance.

[Pure]
public static ZonedDateTime Create(DateTime dateTime, TimeZoneInfo timeZone)

Parameters

dateTime DateTime

Underlying date time.

timeZone TimeZoneInfo

Target time zone.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When dateTime is not valid in the given timeZone.

CreateLocal(DateTime)

Creates a new ZonedDateTime instance in Local time zone.

[Pure]
public static ZonedDateTime CreateLocal(DateTime localDateTime)

Parameters

localDateTime DateTime

Underlying date time.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When localDateTime is not valid in Local time zone.

CreateUtc(Timestamp)

Creates a new ZonedDateTime instance in Utc time zone.

[Pure]
public static ZonedDateTime CreateUtc(Timestamp timestamp)

Parameters

timestamp Timestamp

Underlying timestamp.

Returns

ZonedDateTime

New ZonedDateTime instance.

CreateUtc(DateTime)

Creates a new ZonedDateTime instance in Utc time zone.

[Pure]
public static ZonedDateTime CreateUtc(DateTime utcDateTime)

Parameters

utcDateTime DateTime

Underlying date time.

Returns

ZonedDateTime

New ZonedDateTime instance.

Equals(ZonedDateTime)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(ZonedDateTime other)

Parameters

other ZonedDateTime

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetDay()

Creates a new ZonedDay instance that contains this instance.

[Pure]
public ZonedDay GetDay()

Returns

ZonedDay

New ZonedDay instance.

GetDurationOffset(ZonedDateTime)

Calculates a difference in Duration between this instance and the start instance, where this instance is treated as the end of the range.

[Pure]
public Duration GetDurationOffset(ZonedDateTime start)

Parameters

start ZonedDateTime

Instance to subtract.

Returns

Duration

New Duration instance.

GetGreedyPeriodOffset(ZonedDateTime, PeriodUnits)

Creates a new Period instance by calculating a difference between this instance and the start instance, where this instance is treated as the end of the range, using the specified units.

[Pure]
public Period GetGreedyPeriodOffset(ZonedDateTime start, PeriodUnits units)

Parameters

start ZonedDateTime

Start date time.

units PeriodUnits

PeriodUnits to include in the calculated difference.

Returns

Period

New Period instance.

Remarks

Greedy Period may contain components with negative values.

GetHashCode()

Returns the hash code for this instance.

[Pure]
public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

GetMonth()

Creates a new ZonedMonth instance that contains this instance.

[Pure]
public ZonedMonth GetMonth()

Returns

ZonedMonth

New ZonedMonth instance.

GetOppositeAmbiguousDateTime()

Attempts to create a new ZonedDateTime instance by calculating the other version of an ambiguous value, if this instance represents an ambiguous date time in its TimeZone.

[Pure]
public ZonedDateTime? GetOppositeAmbiguousDateTime()

Returns

ZonedDateTime?

New ZonedDateTime instance or null when this instance is not ambiguous.

GetPeriodOffset(ZonedDateTime, PeriodUnits)

Creates a new Period instance by calculating a difference between this instance and the start instance, where this instance is treated as the end of the range, using the specified units.

[Pure]
public Period GetPeriodOffset(ZonedDateTime start, PeriodUnits units)

Parameters

start ZonedDateTime

Start date time.

units PeriodUnits

PeriodUnits to include in the calculated difference.

Returns

Period

New Period instance.

GetWeek(IsoDayOfWeek)

Creates a new ZonedWeek instance that contains this instance.

[Pure]
public ZonedWeek GetWeek(IsoDayOfWeek weekStart = IsoDayOfWeek.Monday)

Parameters

weekStart IsoDayOfWeek

First day of the week.

Returns

ZonedWeek

New ZonedWeek instance.

GetYear()

Creates a new ZonedYear instance that contains this instance.

[Pure]
public ZonedYear GetYear()

Returns

ZonedYear

New ZonedYear instance.

SetDayOfMonth(int)

Creates a new ZonedDateTime instance by setting the DayOfMonth component in this instance.

[Pure]
public ZonedDateTime SetDayOfMonth(int day)

Parameters

day int

Day of month to set.

Returns

ZonedDateTime

New ZonedDateTime instance.

Remarks

Result may end up with modified components other than the day of month, if it lands in the range of invalid values of this instance's TimeZone.

Exceptions

ArgumentOutOfRangeException

When day is not valid for the current month.

SetDayOfYear(int)

Creates a new ZonedDateTime instance by setting the DayOfYear component in this instance.

[Pure]
public ZonedDateTime SetDayOfYear(int day)

Parameters

day int

Day of year to set.

Returns

ZonedDateTime

New ZonedDateTime instance.

Remarks

Result may end up with modified components other than the day of year, if it lands in the range of invalid values of this instance's TimeZone.

Exceptions

ArgumentOutOfRangeException

When day is not valid for the current year.

SetMonth(IsoMonthOfYear)

Creates a new ZonedDateTime instance by setting the Month component in this instance.

[Pure]
public ZonedDateTime SetMonth(IsoMonthOfYear month)

Parameters

month IsoMonthOfYear

Month to set.

Returns

ZonedDateTime

New ZonedDateTime instance.

Remarks

Result may end up with modified components other than the month, if it lands in the range of invalid values of this instance's TimeZone.

SetTimeOfDay(TimeOfDay)

Creates a new ZonedDateTime instance by setting the TimeOfDay component in this instance.

[Pure]
public ZonedDateTime SetTimeOfDay(TimeOfDay timeOfDay)

Parameters

timeOfDay TimeOfDay

Time of day to set.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When result is not valid in this instance's TimeZone.

SetYear(int)

Creates a new ZonedDateTime instance by setting the Year component in this instance.

[Pure]
public ZonedDateTime SetYear(int year)

Parameters

year int

Year to set.

Returns

ZonedDateTime

New ZonedDateTime instance.

Remarks

Result may end up with modified components other than the year, if it lands in the range of invalid values of this instance's TimeZone.

Exceptions

ArgumentOutOfRangeException

When year is not valid.

Subtract(Duration)

Creates a new ZonedDateTime instance by subtracting value from this instance.

[Pure]
public ZonedDateTime Subtract(Duration value)

Parameters

value Duration

Duration to subtract.

Returns

ZonedDateTime

New ZonedDateTime instance.

Subtract(Period)

Creates a new ZonedDateTime instance by subtracting value from this instance.

[Pure]
public ZonedDateTime Subtract(Period value)

Parameters

value Period

Period to subtract.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When result is not valid in this instance's TimeZone.

ToLocalTimeZone()

Creates a new ZonedDateTime in Local time zone from this instance.

[Pure]
public ZonedDateTime ToLocalTimeZone()

Returns

ZonedDateTime

New ZonedDateTime instance.

ToString()

Returns a string representation of this ZonedDateTime instance.

[Pure]
public override string ToString()

Returns

string

String representation.

ToTimeZone(TimeZoneInfo)

Creates a new ZonedDateTime in the targetTimeZone from this instance.

[Pure]
public ZonedDateTime ToTimeZone(TimeZoneInfo targetTimeZone)

Parameters

targetTimeZone TimeZoneInfo

Target time zone.

Returns

ZonedDateTime

New ZonedDateTime instance.

ToUtcTimeZone()

Creates a new ZonedDateTime in Utc time zone from this instance.

[Pure]
public ZonedDateTime ToUtcTimeZone()

Returns

ZonedDateTime

New ZonedDateTime instance.

TryAdd(Period)

Attempts to create a new ZonedDateTime instance by adding value to this instance.

[Pure]
public ZonedDateTime? TryAdd(Period value)

Parameters

value Period

Period to add.

Returns

ZonedDateTime?

New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.

TryCreate(DateTime, TimeZoneInfo)

Attempts to create a new ZonedDateTime instance.

[Pure]
public static ZonedDateTime? TryCreate(DateTime dateTime, TimeZoneInfo timeZone)

Parameters

dateTime DateTime

Underlying date time.

timeZone TimeZoneInfo

Target time zone.

Returns

ZonedDateTime?

New ZonedDateTime instance or null when dateTime is not valid in the given timeZone.

TrySetTimeOfDay(TimeOfDay)

Attempts to create a new ZonedDateTime instance by setting the TimeOfDay component in this instance.

[Pure]
public ZonedDateTime? TrySetTimeOfDay(TimeOfDay timeOfDay)

Parameters

timeOfDay TimeOfDay

Time of day to set.

Returns

ZonedDateTime?

New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.

TrySubtract(Period)

Attempts to create a new ZonedDateTime instance by subtracting value from this instance.

[Pure]
public ZonedDateTime? TrySubtract(Period value)

Parameters

value Period

Period to subtract.

Returns

ZonedDateTime?

New ZonedDateTime instance or null when result is not valid in this instance's TimeZone.

Operators

operator +(ZonedDateTime, Duration)

Creates a new ZonedDateTime instance by adding a and b together.

[Pure]
public static ZonedDateTime operator +(ZonedDateTime a, Duration b)

Parameters

a ZonedDateTime

First operand.

b Duration

Second operand.

Returns

ZonedDateTime

New ZonedDateTime instance.

operator +(ZonedDateTime, Period)

Creates a new ZonedDateTime instance by adding a and b together.

[Pure]
public static ZonedDateTime operator +(ZonedDateTime a, Period b)

Parameters

a ZonedDateTime

First operand.

b Period

Second operand.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When result is not valid in the given TimeZone.

operator ==(ZonedDateTime, ZonedDateTime)

Checks if a is equal to b.

[Pure]
public static bool operator ==(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when operands are equal, otherwise false.

explicit operator Timestamp(ZonedDateTime)

Converts the provided source to Timestamp.

[Pure]
public static explicit operator Timestamp(ZonedDateTime source)

Parameters

source ZonedDateTime

Value to convert.

Returns

Timestamp

Timestamp.

explicit operator DateTime(ZonedDateTime)

Converts the provided source to DateTime.

[Pure]
public static explicit operator DateTime(ZonedDateTime source)

Parameters

source ZonedDateTime

Value to convert.

Returns

DateTime

Value.

operator >(ZonedDateTime, ZonedDateTime)

Checks if a is greater than b.

[Pure]
public static bool operator >(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when a is greater than b, otherwise false.

operator >=(ZonedDateTime, ZonedDateTime)

Checks if a is greater than or equal to b.

[Pure]
public static bool operator >=(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(ZonedDateTime, ZonedDateTime)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when operands are not equal, otherwise false.

operator <(ZonedDateTime, ZonedDateTime)

Checks if a is less than b.

[Pure]
public static bool operator <(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when a is less than b, otherwise false.

operator <=(ZonedDateTime, ZonedDateTime)

Checks if a is less than or equal to b.

[Pure]
public static bool operator <=(ZonedDateTime a, ZonedDateTime b)

Parameters

a ZonedDateTime

First operand.

b ZonedDateTime

Second operand.

Returns

bool

true when a is less than or equal to b, otherwise false.

operator -(ZonedDateTime, Duration)

Creates a new ZonedDateTime instance by subtracting b from a.

[Pure]
public static ZonedDateTime operator -(ZonedDateTime a, Duration b)

Parameters

a ZonedDateTime

First operand.

b Duration

Second operand.

Returns

ZonedDateTime

New ZonedDateTime instance.

operator -(ZonedDateTime, Period)

Creates a new ZonedDateTime instance by subtracting b from a.

[Pure]
public static ZonedDateTime operator -(ZonedDateTime a, Period b)

Parameters

a ZonedDateTime

First operand.

b Period

Second operand.

Returns

ZonedDateTime

New ZonedDateTime instance.

Exceptions

InvalidZonedDateTimeException

When result is not valid in the given TimeZone.