Class Period
Implements
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public sealed class Period : IEquatable<Period>
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Fields
Zero
Declaration
public static readonly Period Zero
Field Value
Type | Description |
---|---|
Period |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Properties
Days
Declaration
public long Days { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
HasDateComponent
Declaration
public bool HasDateComponent { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
HasTimeComponent
Declaration
public bool HasTimeComponent { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Hours
Declaration
public long Hours { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Milliseconds
Declaration
public long Milliseconds { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Minutes
Declaration
public long Minutes { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Months
Declaration
public long Months { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
NormalizingEqualityComparer
Declaration
public static IEqualityComparer<Period> NormalizingEqualityComparer { get; }
Property Value
Type | Description |
---|---|
IEqualityComparer<Period> |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Seconds
Declaration
public long Seconds { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Ticks
Declaration
public long Ticks { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Weeks
Declaration
public long Weeks { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Years
Declaration
public long Years { get; }
Property Value
Type | Description |
---|---|
Int64 |
Remarks
Methods
Between(LocalDate, LocalDate)
Declaration
public static Period Between(LocalDate start, LocalDate end)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | start | Start date |
LocalDate | end | End date |
Returns
Type | Description |
---|---|
Period | The period between the two dates, using year, month and day units. |
Remarks
end
is before start
, each property in the returned period
will be negative.
Between(LocalDate, LocalDate, PeriodUnits)
Declaration
public static Period Between(LocalDate start, LocalDate end, PeriodUnits units)
Parameters
Type | Name | Description |
---|---|---|
LocalDate | start | Start date |
LocalDate | end | End date |
PeriodUnits | units | Units to use for calculations |
Returns
Type | Description |
---|---|
Period | The period between the given dates, using the given units. |
Remarks
end
is before start
, each property in the returned period
will be negative. If the given set of units cannot exactly reach the end point (e.g. finding
the difference between 12th February and 15th March in months) the result will be such that adding it to start
will give a value between start
and end
. In other words,
any rounding is "towards start"; this is true whether the resulting period is negative or positive.
Exceptions
Type | Condition |
---|---|
ArgumentException | units contains time units, is empty or contains unknown values |
ArgumentException | start and end use different calendars |
Between(LocalDateTime, LocalDateTime)
Declaration
public static Period Between(LocalDateTime start, LocalDateTime end)
Parameters
Type | Name | Description |
---|---|---|
LocalDateTime | start | Start date/time |
LocalDateTime | end | End date/time |
Returns
Type | Description |
---|---|
Period | The period between the two date and time values, using all units. |
Remarks
end
is before start
, each property in the returned period
will be negative.
Between(LocalDateTime, LocalDateTime, PeriodUnits)
Declaration
public static Period Between(LocalDateTime start, LocalDateTime end, PeriodUnits units)
Parameters
Type | Name | Description |
---|---|---|
LocalDateTime | start | Start date/time |
LocalDateTime | end | End date/time |
PeriodUnits | units | Units to use for calculations |
Returns
Type | Description |
---|---|
Period | The period between the given date/times, using the given units. |
Remarks
end
is before start
, each property in the returned period
will be negative. If the given set of units cannot exactly reach the end point (e.g. finding
the difference between 1am and 3:15am in hours) the result will be such that adding it to start
will give a value between start
and end
. In other words,
any rounding is "towards start"; this is true whether the resulting period is negative or positive.
Exceptions
Type | Condition |
---|---|
ArgumentException | units is empty or contained unknown values |
ArgumentException | start and end use different calendars |
Between(LocalTime, LocalTime)
Declaration
public static Period Between(LocalTime start, LocalTime end)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | start | Start time |
LocalTime | end | End time |
Returns
Type | Description |
---|---|
Period | The period between the two times, using the time period units. |
Remarks
end
is before start
, each property in the returned period
will be negative.
Between(LocalTime, LocalTime, PeriodUnits)
Declaration
public static Period Between(LocalTime start, LocalTime end, PeriodUnits units)
Parameters
Type | Name | Description |
---|---|---|
LocalTime | start | Start time |
LocalTime | end | End time |
PeriodUnits | units | Units to use for calculations |
Returns
Type | Description |
---|---|
Period | The period between the given times, using the given units. |
Remarks
end
is before start
, each property in the returned period
will be negative. If the given set of units cannot exactly reach the end point (e.g. finding
the difference between 3am and 4.30am in hours) the result will be such that adding it to start
will give a value between start
and end
. In other words,
any rounding is "towards start"; this is true whether the resulting period is negative or positive.
Exceptions
Type | Condition |
---|---|
ArgumentException | units contains date units, is empty or contains unknown values |
ArgumentException | start and end use different calendars |
CreateComparer(LocalDateTime)
Declaration
public static IComparer<Period> CreateComparer(LocalDateTime baseDateTime)
Parameters
Type | Name | Description |
---|---|---|
LocalDateTime | baseDateTime | The base local date/time to use for comparisons. |
Returns
Type | Description |
---|---|
IComparer<Period> | The new comparer. |
Remarks
baseDateTime
and compares
the results. In some cases this arithmetic isn't actually required - when two periods can be
converted to durations, the comparer uses that conversion for efficiency.
Equals(Period)
Declaration
public bool Equals(Period other)
Parameters
Type | Name | Description |
---|---|---|
Period | other | The period to compare this one with. |
Returns
Type | Description |
---|---|
Boolean | True if this period has the same values for the same properties as the one specified. |
Remarks
Equals(Object)
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
Object | other | The value to compare this one with. |
Returns
Type | Description |
---|---|
Boolean | true if the other object is a period equal to this one, consistent with Equals(Period) |
Overrides
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromDays(Int64)
Declaration
public static Period FromDays(long days)
Parameters
Type | Name | Description |
---|---|---|
Int64 | days | The number of days in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of days. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromHours(Int64)
Declaration
public static Period FromHours(long hours)
Parameters
Type | Name | Description |
---|---|---|
Int64 | hours | The number of hours in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of hours. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromMilliseconds(Int64)
Declaration
public static Period FromMilliseconds(long milliseconds)
Parameters
Type | Name | Description |
---|---|---|
Int64 | milliseconds | The number of milliseconds in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of milliseconds. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromMillseconds(Int64)
Declaration
[Obsolete("Use FromMilliseconds instead. This method's name was a typo, and it will be removed in a future release.")]
public static Period FromMillseconds(long milliseconds)
Parameters
Type | Name | Description |
---|---|---|
Int64 | milliseconds | The number of milliseconds in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of milliseconds. |
Remarks
FromMinutes(Int64)
Declaration
public static Period FromMinutes(long minutes)
Parameters
Type | Name | Description |
---|---|---|
Int64 | minutes | The number of minutes in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of minutes. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromMonths(Int64)
Declaration
public static Period FromMonths(long months)
Parameters
Type | Name | Description |
---|---|---|
Int64 | months | The number of months in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of months. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromSeconds(Int64)
Declaration
public static Period FromSeconds(long seconds)
Parameters
Type | Name | Description |
---|---|---|
Int64 | seconds | The number of seconds in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of seconds. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromTicks(Int64)
Declaration
public static Period FromTicks(long ticks)
Parameters
Type | Name | Description |
---|---|---|
Int64 | ticks | The number of ticks in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of ticks. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromWeeks(Int64)
Declaration
public static Period FromWeeks(long weeks)
Parameters
Type | Name | Description |
---|---|---|
Int64 | weeks | The number of weeks in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of weeks. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
FromYears(Int64)
Declaration
public static Period FromYears(long years)
Parameters
Type | Name | Description |
---|---|---|
Int64 | years | The number of years in the new period |
Returns
Type | Description |
---|---|
Period | A period consisting of the given number of years. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
GetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code for this period. |
Overrides
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Normalize()
Declaration
public Period Normalize()
Returns
Type | Description |
---|---|
Period | The normalized period. |
Remarks
Exceptions
Type | Condition |
---|---|
OverflowException | The period doesn't have years or months, but it contains more than MaxValue ticks when the combined weeks/days/time portions are considered. Such a period could never be useful anyway, however. In some cases this may occur even though the theoretical result would be valid due to balancing positive and negative values, but for simplicity there is no attempt to work around this - in realistic periods, it shouldn't be a problem. |
See Also
ToBuilder()
Declaration
public PeriodBuilder ToBuilder()
Returns
Type | Description |
---|---|
PeriodBuilder | A builder with the same values and units as this period. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
ToDuration()
Declaration
public Duration ToDuration()
Returns
Type | Description |
---|---|
Duration | The duration of the period. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The month or year property in the period is non-zero. |
OverflowException | The period doesn't have years or months, but the calculation overflows the bounds of Duration. In some cases this may occur even though the theoretical result would be valid due to balancing positive and negative values, but for simplicity there is no attempt to work around this - in realistic periods, it shouldn't be a problem. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A formatted representation of this period. |
Overrides
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Operators
Addition(Period, Period)
Declaration
public static Period operator +(Period left, Period right)
Parameters
Type | Name | Description |
---|---|---|
Period | left | The first period to add |
Period | right | The second period to add |
Returns
Type | Description |
---|---|
Period | The sum of the two periods. The units of the result will be the union of those in both periods. |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)
Subtraction(Period, Period)
Declaration
public static Period operator -(Period minuend, Period subtrahend)
Parameters
Type | Name | Description |
---|---|---|
Period | minuend | The period to subtract the second operand from |
Period | subtrahend | The period to subtract the first operand from |
Returns
Type | Description |
---|---|
Period | The result of subtracting all the values in the second operand from the values in the first. The units of the result will be the union of both periods, even if the subtraction caused some properties to become zero (so "2 weeks, 1 days" minus "2 weeks" is "zero weeks, 1 days", not "1 days"). |
Remarks
A Period contains a set of properties such as Years, Months, and so on that return the number of each unit contained within this period. Note that these properties are not normalized in any way by default, and so a Period may contain values such as "2 hours and 90 minutes". The Normalize() method will convert equivalent periods into a standard representation.
Periods can contain negative units as well as positive units ("+2 hours, -43 minutes, +10 seconds"), but do not differentiate between properties that are zero and those that are absent (i.e. a period created as "10 years" and one created as "10 years, zero months" are equal periods; the Months property returns zero in both cases).
Period equality is implemented by comparing each property's values individually.
Periods operate on calendar-related types such as LocalDateTime whereas Duration operates on instants on the time line. (Note that although ZonedDateTime includes both concepts, it only supports duration-based arithmetic.)