Struct OffsetDate
A combination of a
LocalDate and an
Offset, to represent
a date at a specific offset from UTC but without any time-of-day information.
Since 2.3.x
Availability net6.0, netstandard2.0
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(OffsetDateTypeConverter))]
public readonly struct OffsetDate : IEquatable<OffsetDate>, IXmlSerializable, IFormattable
Constructors
OffsetDate(LocalDate, Offset)
Constructs an instance of the specified date and offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public OffsetDate(LocalDate date, Offset offset)
Parameters
Type |
Name |
Description |
LocalDate |
date |
The date part of the value. |
Offset |
offset |
The offset part of the value. |
Sample snippet
using NodaTime;
using System;
OffsetDate offsetDate = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
Console.WriteLine(offsetDate.Offset);
Console.WriteLine(offsetDate.Date);
Output:
+03
Friday, 03 May 2019
Properties
Calendar
Gets the calendar system associated with this offset date.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly CalendarSystem Calendar { get; }
Property Value
Type |
Description |
CalendarSystem |
The calendar system associated with this offset date. |
Date
Gets the local date represented by this value.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly LocalDate Date { get; }
Property Value
Type |
Description |
LocalDate |
The local date represented by this value. |
Day
Gets the day of this offset date within the month.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Day { get; }
Property Value
Type |
Description |
Int32 |
The day of this offset date within the month. |
DayOfWeek
Gets the week day of this offset date expressed as an
IsoDayOfWeek value.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly IsoDayOfWeek DayOfWeek { get; }
Property Value
Type |
Description |
IsoDayOfWeek |
The week day of this offset date expressed as an IsoDayOfWeek . |
DayOfYear
Gets the day of this offset date within the year.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int DayOfYear { get; }
Property Value
Type |
Description |
Int32 |
The day of this offset date within the year. |
Era
Gets the era of this offset date.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly Era Era { get; }
Property Value
Type |
Description |
Era |
The era of this offset date. |
Month
Gets the month of this offset date within the year.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Month { get; }
Property Value
Type |
Description |
Int32 |
The month of this offset date within the year. |
Offset
Gets the offset from UTC of this value.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly Offset Offset { get; }
Property Value
Type |
Description |
Offset |
The offset from UTC of this value. |
Year
Gets the year of this offset date.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Year { get; }
Property Value
Type |
Description |
Int32 |
The year of this offset date. |
YearOfEra
Gets the year of this offset date within the era.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly int YearOfEra { get; }
Property Value
Type |
Description |
Int32 |
The year of this offset date within the era. |
Methods
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the
OffsetDate XML serialization to the given
xmlSchemaSet
.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Returns
Type |
Description |
XmlQualifiedName |
The qualified name of the schema type that was added to the xmlSchemaSet . |
At(LocalTime)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetDateTime At(LocalTime time)
Parameters
Type |
Name |
Description |
LocalTime |
time |
The time to combine with this date. |
Returns
Deconstruct(out LocalDate, out Offset)
Deconstruct this value into its components.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly void Deconstruct(out LocalDate localDate, out Offset offset)
Parameters
Equals(OffsetDate)
Compares two
OffsetDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly bool Equals(OffsetDate other)
Parameters
Type |
Name |
Description |
OffsetDate |
other |
The value to compare this offset date with. |
Returns
Type |
Description |
Boolean |
True if the given value is another offset date equal to this one; false otherwise. |
Equals(Object)
Compares two
OffsetDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
The object to compare this offset date with. |
Returns
Type |
Description |
Boolean |
True if the given value is another offset date equal to this one; false otherwise. |
Overrides
GetHashCode()
Returns a hash code for this offset date.
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly int GetHashCode()
Returns
Type |
Description |
Int32 |
A hash code for this offset date. |
Overrides
ToString()
Returns a
String that represents this instance.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public override readonly string ToString()
Returns
Type |
Description |
String |
The value of the current instance in the default format pattern ("G"), using the current thread's
culture to obtain a format provider.
|
Overrides
Formats the value of the current instance using the specified pattern.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type |
Name |
Description |
String |
patternText |
The String specifying the pattern to use,
or null to use the default format pattern ("G").
|
IFormatProvider |
formatProvider |
The IFormatProvider to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
|
Returns
Type |
Description |
String |
A String containing the value of the current instance in the specified format.
|
With(Func<LocalDate, LocalDate>)
Returns this offset date, with the given date adjuster applied to it, maintaining the existing offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetDate With(Func<LocalDate, LocalDate> adjuster)
Parameters
Returns
Type |
Description |
OffsetDate |
The adjusted offset date. |
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
Func<LocalDate, LocalDate> tomorrowAdjuster = x => x + Period.FromDays(1);
OffsetDate updated = original.With(tomorrowAdjuster);
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Date);
Output:
+03
Saturday, 04 May 2019
WithCalendar(CalendarSystem)
Creates a new
OffsetDate representing the same physical date and offset, but in a different calendar.
The returned value is likely to have different date field values to this one.
For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetDate WithCalendar(CalendarSystem calendar)
Parameters
Type |
Name |
Description |
CalendarSystem |
calendar |
The calendar system to convert this offset date to. |
Returns
Type |
Description |
OffsetDate |
The converted OffsetDate . |
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3, CalendarSystem.Iso),
Offset.FromHours(3));
OffsetDate updated = original.WithCalendar(CalendarSystem.Gregorian);
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Calendar);
Output:
+03
Gregorian
WithOffset(Offset)
Creates a new
OffsetDate for the same date, but with the specified UTC offset.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public readonly OffsetDate WithOffset(Offset offset)
Parameters
Type |
Name |
Description |
Offset |
offset |
The new UTC offset. |
Returns
Type |
Description |
OffsetDate |
A new OffsetDate for the same date, but with the specified UTC offset. |
Sample snippet
using NodaTime;
using System;
var original = new OffsetDate(
new LocalDate(2019, 5, 3),
Offset.FromHours(3));
OffsetDate updated = original.WithOffset(Offset.FromHours(-3));
Console.WriteLine(updated.Offset);
Console.WriteLine(updated.Date);
Output:
-03
Friday, 03 May 2019
Operators
Equality(OffsetDate, OffsetDate)
Implements the operator == (equality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator ==(OffsetDate left, OffsetDate right)
Parameters
Type |
Name |
Description |
OffsetDate |
left |
The left hand side of the operator. |
OffsetDate |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if values are equal to each other, otherwise false . |
Inequality(OffsetDate, OffsetDate)
Implements the operator != (inequality).
See the type documentation for a description of equality semantics.
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator !=(OffsetDate left, OffsetDate right)
Parameters
Type |
Name |
Description |
OffsetDate |
left |
The left hand side of the operator. |
OffsetDate |
right |
The right hand side of the operator. |
Returns
Type |
Description |
Boolean |
true if values are not equal to each other, otherwise false . |
Explicit Interface Implementations
IXmlSerializable.ReadXml(XmlReader)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
IXmlSerializable.WriteXml(XmlWriter)
Since 2.3.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Implements