Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
struct NodaTime.​LocalDate
Assembly: NodaTime
Implemented Interfaces
- System.​IEquatable`1
- System.​IComparable`1
- System.​IComparable
- System.​IFormattable
- System.​Xml.​Serialization.​IXmlSerializable
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​IAdditionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​ISubtractionOperators`3
- System.​Numerics.​IComparisonOperators`3 (Inherits: IEqualityOperators<​NodaTime.​LocalDate, NodaTime.​LocalDate, bool>)
LocalDate is an immutable struct representing a date within the calendar, with no reference to a particular time zone or time of day.
Remarks
<para>
Values can freely be compared for equality: a value in a different calendar system is not equal to
a value in a different calendar system. However, ordering comparisons (either via the <see cref="M:NodaTime.LocalDate.CompareTo(NodaTime.LocalDate)" /> method
or via operators) fail with <see cref="T:System.ArgumentException" />; attempting to compare values in different calendars
almost always indicates a bug in the calling code.
</para> <para>The default value of this type is 0001-01-01 (January 1st, 1 C.E.) in the ISO calendar.</para>
Properties
public static
LocalDate
MaxIsoValue
The maximum (latest) date representable in the ISO calendar system.
public static
LocalDate
MinIsoValue
The minimum (earliest) date representable in the ISO calendar system.
public
CalendarSystem
Calendar
Gets the calendar system associated with this local date.
public
int
Year
Gets the year of this local date.
Remarks This returns the "absolute year", so, for the ISO calendar,
a value of 0 means 1 BC, for example.
public
int
Month
Gets the month of this local date within the year.
public
int
Day
Gets the day of this local date within the month.
public
IsoDayOfWeek
DayOfWeek
Gets the week day of this local date expressed as an <see cref="T:NodaTime.IsoDayOfWeek" /> value.
public
int
YearOfEra
Gets the year of this local date within the era.
public
Era
Era
Gets the era of this local date.
public
int
DayOfYear
Gets the day of this local date within the year.
Methods
public
LocalDateTime
AtMidnight​()
Gets a <see cref="T:NodaTime.LocalDateTime" /> at midnight on the date represented by this local date.
Returns The <see cref="T:NodaTime.LocalDateTime" /> representing midnight on this local date, in the same calendar
system.
ToDateTimeUnspecified​()
Constructs a <see cref="T:System.DateTime" /> from this value which has a <see cref="P:System.DateTime.Kind" />
of <see cref="F:System.DateTimeKind.Unspecified" /> . The result is midnight on the day represented
by this value.
Returns A <see cref="T:System.DateTime" /> value for the same date and time as this value.
Remarks
<para>
<see cref="F:System.DateTimeKind.Unspecified" /> is slightly odd - it can be treated as UTC if you use <see cref="M:System.DateTime.ToLocalTime" />
or as system local time if you use <see cref="M:System.DateTime.ToUniversalTime" />, but it's the only kind which allows
you to construct a <see cref="T:System.DateTimeOffset" /> with an arbitrary offset, which makes it as close to
the Noda Time non-system-specific "local" concept as exists in .NET.
</para> <para>
<see cref="T:System.DateTime" /> uses the Gregorian calendar by definition, so the value is implicitly converted
to the Gregorian calendar first. The result will be on the same physical day,
but the values returned by the Year/Month/Day properties of the <see cref="T:System.DateTime" /> may not
match the Year/Month/Day properties of this value.
</para>
public static
LocalDate
FromDateTime​(System.​DateTime dateTime)
Converts a <see cref="T:System.DateTime" /> of any kind to a LocalDate in the ISO calendar, ignoring the time of day.
This does not perform any time zone conversions, so a DateTime with a <see cref="P:System.DateTime.Kind" /> of
<see cref="F:System.DateTimeKind.Utc" /> will still represent the same year/month/day - it won't be converted into the local system time.
Returns A new <see cref="T:NodaTime.LocalDate" /> with the same values as the specified <c>DateTime</c> .
dateTime
Value to convert into a Noda Time local date
public static
LocalDate
FromDateTime​(System.​DateTime dateTime,
CalendarSystem calendar)
Converts a <see cref="T:System.DateTime" /> of any kind to a LocalDate in the specified calendar, ignoring the time of day.
This does not perform any time zone conversions, so a DateTime with a <see cref="P:System.DateTime.Kind" /> of
<see cref="F:System.DateTimeKind.Utc" /> will still represent the same year/month/day - it won't be converted into the local system time.
Returns A new <see cref="T:NodaTime.LocalDate" /> with the same values as the specified <c>DateTime</c> .
dateTime
Value to convert into a Noda Time local date
calendar
The calendar system to convert into
public static
LocalDate
FromWeekYearWeekAndDay​(int weekYear,
int weekOfWeekYear,
IsoDayOfWeek dayOfWeek)
Returns the local date corresponding to the given "week year", "week of week year", and "day of week"
in the ISO calendar system, using the ISO week-year rules.
Returns The date corresponding to the given week year / week of week year / day of week.
weekYear
ISO-8601 week year of value to return
weekOfWeekYear
ISO-8601 week of week year of value to return
dayOfWeek
ISO-8601 day of week to return
public static
LocalDate
FromYearMonthWeekAndDay​(int year,
int month,
int occurrence,
IsoDayOfWeek dayOfWeek)
Returns the local date corresponding to a particular occurrence of a day-of-week
within a year and month. For example, this method can be used to ask for "the third Monday in April 2012".
Returns The date corresponding to the given year and month, on the given occurrence of the
given day of week.
year
The year of the value to return.
month
The month of the value to return.
occurrence
The occurrence of the value to return, which must be in the range [1, 5]. The value 5 can
be used to always return the last occurrence of the specified day-of-week, even if there are only 4
occurrences of that day-of-week in the month.
dayOfWeek
The day-of-week of the value to return.
Remarks
The returned date is always in the ISO calendar. This method is unrelated to week-years and any rules for
"business weeks" and the like - if a month begins on a Friday, then asking for the first Friday will give
that day, for example.
public
YearMonth
ToYearMonth​()
Creates a <see cref="T:NodaTime.YearMonth" /> value for the month containing this date.
Returns A year/month value containing this date.
public static
LocalDate
Add​(LocalDate date,
Period period)
Adds the specified period to the date.
Fields are added in descending order of significance (years first, then months, and so on).
Friendly alternative to <c>operator+()</c> .
Returns The sum of the given date and period
date
The date to add the period to
period
The period to add. Must not contain any (non-zero) time units.
public
LocalDate
Plus​(Period period)
Adds the specified period to this date.
Fields are added in descending order of significance (years first, then months, and so on).
Fluent alternative to <c>operator+()</c> .
Returns The sum of this date and the given period
period
The period to add. Must not contain any (non-zero) time units.
public static
LocalDate
Subtract​(LocalDate date,
Period period)
Subtracts the specified period from the date.
Fields are subtracted in descending order of significance (years first, then months, and so on).
Friendly alternative to <c>operator-()</c> .
Returns The result of subtracting the given period from the date.
date
The date to subtract the period from
period
The period to subtract. Must not contain any (non-zero) time units.
public
LocalDate
Minus​(Period period)
Subtracts the specified period from this date.
Fields are subtracted in descending order of significance (years first, then months, and so on).
Fluent alternative to <c>operator-()</c> .
Returns The result of subtracting the given period from this date.
period
The period to subtract. Must not contain any (non-zero) time units.
public static
Period
Subtract​(LocalDate lhs,
LocalDate rhs)
Subtracts one date from another, returning the result as a <see cref="T:NodaTime.Period" /> with units of years, months and days.
Returns The result of subtracting one date from another.
lhs
The date to subtract from
rhs
The date to subtract
Remarks
This is simply a convenience method for calling <see cref="M:NodaTime.Period.Between(NodaTime.LocalDate,NodaTime.LocalDate)" /> .
The calendar systems of the two dates must be the same.
public
Period
Minus​(LocalDate date)
Subtracts the specified date from this date, returning the result as a <see cref="T:NodaTime.Period" /> with units of years, months and days.
Fluent alternative to <c>operator-()</c> .
Returns The difference between the specified date and this one
date
The date to subtract from this
Remarks
The specified date must be in the same calendar system as this.
public
int
CompareTo​(LocalDate other)
Indicates whether this date is earlier, later or the same as another one.
See the type documentation for a description of ordering semantics.
Returns A value less than zero if this date is earlier than <paramref name="other" /> ;
zero if this date is the same as <paramref name="other" /> ; a value greater than zero if this date is
later than <paramref name="other" /> .
other
The other date to compare this one with
public static
LocalDate
Max​(LocalDate x,
LocalDate y)
Returns the later date of the given two.
Returns The later date of <paramref name="x" /> or <paramref name="y" /> .
x
The first date to compare.
y
The second date to compare.
public static
LocalDate
Min​(LocalDate x,
LocalDate y)
Returns the earlier date of the given two.
Returns The earlier date of <paramref name="x" /> or <paramref name="y" /> .
x
The first date to compare.
y
The second date to compare.
public
int
GetHashCode​()
Returns a hash code for this local date.
See the type documentation for a description of equality semantics.
Returns A hash code for this local date.
public
bool
Equals​(object obj)
Compares two <see cref="T:NodaTime.LocalDate" /> values for equality.
See the type documentation for a description of equality semantics.
Returns True if the given value is another local date equal to this one; false otherwise.
obj
The object to compare this date with.
public
bool
Equals​(LocalDate other)
Compares two <see cref="T:NodaTime.LocalDate" /> values for equality.
See the type documentation for a description of ordering semantics.
Returns True if the given value is another local date equal to this one; false otherwise.
other
The value to compare this date with.
public
ZonedDateTime
AtStartOfDayInZone​(DateTimeZone zone)
Resolves this local date into a <see cref="T:NodaTime.ZonedDateTime" /> in the given time zone representing the
start of this date in the given zone.
Returns The <see cref="T:NodaTime.ZonedDateTime" /> representing the earliest time on this date, in the given time zone.
zone
The time zone to map this local date into
Remarks
This is a convenience method for calling <see cref="M:NodaTime.DateTimeZone.AtStartOfDay(NodaTime.LocalDate)" /> .
public
LocalDate
WithCalendar​(CalendarSystem calendar)
Creates a new LocalDate representing the same physical date, but in a different calendar.
The returned LocalDate is likely to have different field values to this one.
For example, January 1st 1970 in the Gregorian calendar was December 19th 1969 in the Julian calendar.
Returns The converted LocalDate
calendar
The calendar system to convert this local date to.
public
LocalDate
PlusYears​(int years)
Returns a new LocalDate representing the current value with the given number of years added.
Returns The current value plus the given number of years.
years
The number of years to add
Remarks
If the resulting date is invalid, lower fields (typically the day of month) are reduced to find a valid value.
For example, adding one year to February 29th 2012 will return February 28th 2013; subtracting one year from
February 29th 2012 will return February 28th 2011.
public
LocalDate
PlusMonths​(int months)
Returns a new LocalDate representing the current value with the given number of months added.
Returns The current date plus the given number of months
months
The number of months to add
Remarks
<para>
This method does not try to maintain the year of the current value, so adding four months to a value in
October will result in a value in the following February.
</para> <para>
If the resulting date is invalid, the day of month is reduced to find a valid value.
For example, adding one month to January 30th 2011 will return February 28th 2011; subtracting one month from
March 30th 2011 will return February 28th 2011.
</para>
public
LocalDate
PlusDays​(int days)
Returns a new LocalDate representing the current value with the given number of days added.
Returns The current value plus the given number of days.
days
The number of days to add
Remarks
<para>
This method does not try to maintain the month or year of the current value, so adding 3 days to a value of January 30th
will result in a value of February 2nd.
</para>
public
LocalDate
PlusWeeks​(int weeks)
Returns a new LocalDate representing the current value with the given number of weeks added.
Returns The current value plus the given number of weeks.
weeks
The number of weeks to add
public
LocalDate
Next​(IsoDayOfWeek targetDayOfWeek)
Returns the next <see cref="T:NodaTime.LocalDate" /> falling on the specified <see cref="T:NodaTime.IsoDayOfWeek" /> .
This is a strict "next" - if this date on already falls on the target
day of the week, the returned value will be a week later.
Returns The next <see cref="T:NodaTime.LocalDate" /> falling on the specified day of the week.
targetDayOfWeek
The ISO day of the week to return the next date of.
public
LocalDate
Previous​(IsoDayOfWeek targetDayOfWeek)
Returns the previous <see cref="T:NodaTime.LocalDate" /> falling on the specified <see cref="T:NodaTime.IsoDayOfWeek" /> .
This is a strict "previous" - if this date on already falls on the target
day of the week, the returned value will be a week earlier.
Returns The previous <see cref="T:NodaTime.LocalDate" /> falling on the specified day of the week.
targetDayOfWeek
The ISO day of the week to return the previous date of.
public
OffsetDate
WithOffset​(Offset offset)
Returns an <see cref="T:NodaTime.OffsetDate" /> for this local date with the given offset.
Returns The result of this date offset by the given amount.
offset
The offset to apply.
Remarks
This method is purely a convenient alternative to calling the <see cref="T:NodaTime.OffsetDate" /> constructor directly.
public
LocalDateTime
At​(LocalTime time)
Combines this <see cref="T:NodaTime.LocalDate" /> with the given <see cref="T:NodaTime.LocalTime" />
into a single <see cref="T:NodaTime.LocalDateTime" /> .
Fluent alternative to <c>operator+()</c> .
Returns The <see cref="T:NodaTime.LocalDateTime" /> representation of the given time on this date
time
The time to combine with this date.
public
LocalDate
With​(System.​Func<​LocalDate, LocalDate> adjuster)
Returns this date, with the given adjuster applied to it.
Returns The adjusted date.
adjuster
The adjuster to apply.
Remarks
If the adjuster attempts to construct an invalid date (such as by trying
to set a day-of-month of 30 in February), any exception thrown by
that construction attempt will be propagated through this method.
public
void
Deconstruct​(System.​Int32& year,
System.​Int32& month,
System.​Int32& day)
public
void
Deconstruct​(System.​Int32& year,
System.​Int32& month,
System.​Int32& day,
CalendarSystem& calendar)
public
string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("D"), using the current thread's
culture to obtain a format provider.
public
string
ToString​(string patternText,
System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText
The <see cref="T:System.String" /> specifying the pattern to use,
or null to use the default format pattern ("D").
formatProvider
The <see cref="T:System.IFormatProvider" /> to use when formatting the value,
or null to use the current thread's culture to obtain a format provider.
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.LocalTime" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
the <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet
The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
ToDateOnly​()
Converts this value to an equivalent <see cref="T:System.DateOnly" /> .
Returns A <see cref="T:System.DateOnly" /> value equivalent to this one.
Remarks
<see cref="T:System.DateOnly" /> uses the Gregorian calendar by definition, so the value is implicitly converted
to the Gregorian calendar first. The result will be on the same physical day,
but the values returned by the Year/Month/Day properties of the <see cref="T:System.DateTime" /> may not
match the Year/Month/Day properties of this value.
public static
LocalDate
FromDateOnly​(System.​DateOnly date)
Constructs a <see cref="T:NodaTime.LocalDate" /> from a <see cref="T:System.DateOnly" /> .
Returns The <see cref="T:NodaTime.LocalDate" /> equivalent, which is always in the ISO calendar system.
date
The date to convert.
protected
void
Finalize​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object