Struct AnnualDate
Represents an annual date (month and day) in the ISO calendar but without a specific year,
typically for recurrent events such as birthdays, anniversaries, and deadlines.
Since 2.0.x
Availability net6.0, netstandard2.0
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
[TypeConverter(typeof(AnnualDateTypeConverter))]
public readonly struct AnnualDate : IEquatable<AnnualDate>, IComparable<AnnualDate>, IComparable, IFormattable, IXmlSerializable
Remarks
Equality and comparison order are defined in the natural way. Two values are equal if they represent the same month and the same day-of-month. One value is earlier than another if it has a smaller month, or the same month but an earlier day-of-month.
In the future, this struct may be expanded to support other calendar systems, but this does not generalize terribly cleanly, particularly to the Hebrew calendar system with its leap month.
Constructors
AnnualDate(Int32, Int32)
Constructs an instance for the given month and day in the ISO calendar.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public AnnualDate(int month, int day)
Parameters
Type | Name | Description |
---|---|---|
Int32 | month | The month of year. |
Int32 | day | The day of month. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The parameters do not form a valid date. (February 29th is considered valid.) |
Properties
Day
Gets the day of month.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Day { get; }
Property Value
Type | Description |
---|---|
Int32 | The day of month. |
Month
Gets the month of year.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly int Month { get; }
Property Value
Type | Description |
---|---|
Int32 | The month of year. |
Methods
AddSchema(XmlSchemaSet)
Adds the XML schema type describing the structure of the AnnualDate XML serialization to the given
xmlSchemaSet
.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public static XmlQualifiedName AddSchema(XmlSchemaSet xmlSchemaSet)
Parameters
Type | Name | Description |
---|---|---|
XmlSchemaSet | xmlSchemaSet | The XML schema set provided by System.Xml.Serialization.XmlSchemaExporter. |
Returns
Type | Description |
---|---|
XmlQualifiedName | The qualified name of the schema type that was added to the xmlSchemaSet . |
CompareTo(AnnualDate)
Indicates whether this annual date is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly int CompareTo(AnnualDate other)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | other | The other annual date to compare this one with |
Returns
Type | Description |
---|---|
Int32 | A value less than zero if this annual date is earlier than other ;
zero if this time is the same as other ; a value greater than zero if this annual date is
later than other . |
Sample snippet
using NodaTime;
using System;
var february23rd = new AnnualDate(2, 23);
var august17th = new AnnualDate(8, 17);
var lessThan = february23rd.CompareTo(august17th);
var equal = february23rd.CompareTo(february23rd);
var greaterThan = august17th.CompareTo(february23rd);
Console.WriteLine(lessThan);
Console.WriteLine(equal);
Console.WriteLine(greaterThan);
Output:
-1
0
1
CompareTo(Object)
Implementation of System.IComparable.CompareTo(System.Object) to compare two AnnualDates.
See the type documentation for a description of ordering semantics.
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly int CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare this value with. |
Returns
Type | Description |
---|---|
Int32 | The result of comparing this AnnualDate with another one.
If obj is null, this method returns a value greater than 0.
|
Remarks
This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.
Exceptions
Type | Condition |
---|---|
ArgumentException | obj is non-null but does not refer to an instance of AnnualDate |
Equals(AnnualDate)
Compares this annual date with the specified one for equality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly bool Equals(AnnualDate other)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | other | The other annual date to compare this one with |
Returns
Type | Description |
---|---|
Boolean | True if the specified annual date is equal to this one; false otherwise |
Sample snippet
using NodaTime;
using System;
var february23rd = new AnnualDate(2, 23);
var august17th = new AnnualDate(8, 17);
var unequal = february23rd.Equals(august17th);
var equal = february23rd.Equals(february23rd);
Console.WriteLine(unequal);
Console.WriteLine(equal);
Output:
False
True
Equals(Object)
Compares this annual date with the specified reference.
See the type documentation for a description of equality semantics.
Since 2.0.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 one with |
Returns
Type | Description |
---|---|
Boolean | True if the specified value is an annual date which is equal to this one; false otherwise |
Overrides
System.ValueType.Equals(System.Object)
GetHashCode()
Returns a hash code for this annual date.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public override readonly int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this annual date. |
Overrides
System.ValueType.GetHashCode()
InYear(Int32)
Returns this annual date in a particular year, as a LocalDate.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly LocalDate InYear(int year)
Parameters
Type | Name | Description |
---|---|---|
Int32 | year | The year component of the required date. |
Returns
Type | Description |
---|---|
LocalDate | A date in the given year, suitable for this annual date. |
Remarks
If this value represents February 29th, and the specified year is not a leap year, the returned value will be February 28th of that year. To see whether the original month and day is valid without truncation in a particular year, use IsValidYear(Int32)
Sample snippet
using NodaTime;
using System;
var annualDate = new AnnualDate(3, 12);
var localDate = annualDate.InYear(2013);
Console.WriteLine(localDate);
Output:
Tuesday, 12 March 2013
IsValidYear(Int32)
Checks whether the specified year forms a valid date with the month/day in this
value, without any truncation. This will always return
true
except
for values representing February 29th, where the specified year is a non leap year.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public readonly bool IsValidYear(int year)
Parameters
Type | Name | Description |
---|---|---|
Int32 | year | The year to test for validity |
Returns
Type | Description |
---|---|
Boolean | true if the current value occurs within the given year;
false otherwise. |
Sample snippet
using NodaTime;
using System;
var leapDay = new AnnualDate(2, 29);
var leapYear = leapDay.IsValidYear(2020);
var nonLeapYear = leapDay.IsValidYear(2018);
Console.WriteLine(leapYear);
Console.WriteLine(nonLeapYear);
Output:
True
False
ToString()
Returns a System.String that represents this instance.
Since 2.0.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"). |
Overrides
System.ValueType.ToString()
ToString(String, IFormatProvider)
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 System.String specifying the pattern to use, or null to use the default format pattern ("G"). |
IFormatProvider | formatProvider | The System.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 System.String containing the value of the current instance in the specified format. |
Operators
Equality(AnnualDate, AnnualDate)
Compares two AnnualDate values for equality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator ==(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | The first value to compare |
AnnualDate | rhs | The second value to compare |
Returns
Type | Description |
---|---|
Boolean | True if the two dates are the same; false otherwise |
GreaterThan(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is strictly later than the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator>(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | First operand of the comparison |
AnnualDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
Boolean | true if the lhs is strictly later than rhs , false otherwise. |
GreaterThanOrEqual(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is later than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator >=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | First operand of the comparison |
AnnualDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
Boolean | true if the lhs is later than or equal to rhs , false otherwise. |
Inequality(AnnualDate, AnnualDate)
Compares two AnnualDate values for inequality.
See the type documentation for a description of equality semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator !=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | The first value to compare |
AnnualDate | rhs | The second value to compare |
Returns
Type | Description |
---|---|
Boolean | False if the two dates are the same and in the same calendar; true otherwise |
LessThan(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is strictly earlier than the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator <(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | First operand of the comparison |
AnnualDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
Boolean | true if the lhs is strictly earlier than rhs , false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentException | The calendar system of rhs is not the same
as the calendar of lhs . |
LessThanOrEqual(AnnualDate, AnnualDate)
Compares two annual dates to see if the left one is earlier than or equal to the right one.
See the type documentation for a description of ordering semantics.
Since 2.0.x
Availability net6.0, netstandard2.0
Declaration
public static bool operator <=(AnnualDate lhs, AnnualDate rhs)
Parameters
Type | Name | Description |
---|---|---|
AnnualDate | lhs | First operand of the comparison |
AnnualDate | rhs | Second operand of the comparison |
Returns
Type | Description |
---|---|
Boolean | true if the lhs is earlier than or equal to rhs , false otherwise. |
Explicit Interface Implementations
IXmlSerializable.ReadXml(XmlReader)
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
IXmlSerializable.WriteXml(XmlWriter)
Since 3.0.x
Availability net6.0, netstandard2.0
Declaration
readonly void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Implements
System.IEquatable<T>
System.IComparable<T>
System.IComparable
System.IFormattable
System.Xml.Serialization.IXmlSerializable