Noda Time
Period Class
NamespacesNodaTimePeriod

[This is preliminary documentation and is subject to change.]

Represents a period of time expressed in human chronological terms: hours, days, weeks, months and so on.
Declaration Syntax
C#Visual BasicVisual C++
public sealed class Period : IEquatable<Period>
Public NotInheritable Class Period _
	Implements IEquatable(Of Period)
public ref class Period sealed : IEquatable<Period^>
Members
All MembersMethodsPropertiesFields



IconMemberDescription
Addition(Period, Period)
Adds two periods together, by simply adding the values for each property.

Between(LocalDateTime, LocalDateTime, PeriodUnits)
Returns the period between a start and an end date/time, using only the given units.

Between(LocalDateTime, LocalDateTime)
Returns the exact difference between two date/times.

Between(LocalDate, LocalDate, PeriodUnits)
Returns the period between a start and an end date, using only the given units.

Between(LocalDate, LocalDate)
Returns the exact difference between two dates.

Between(LocalTime, LocalTime, PeriodUnits)
Returns the period between a start and an end time, using only the given units.

Between(LocalTime, LocalTime)
Returns the exact difference between two times.

CreateComparer(LocalDateTime)
Creates an IComparer<(Of <(<'T>)>)> for periods, using the given "base" local date/time.

Days
Gets the number of days within this period.

Equals(Object)
Compares the given object for equality with this one, as per Equals(Period).
(Overrides Object.Equals(Object).)
Equals(Period)
Compares the given period for equality with this one.

FromDays(Int64)
Creates a period representing the specified number of days.

FromHours(Int64)
Creates a period representing the specified number of hours.

FromMilliseconds(Int64)
Creates a period representing the specified number of miliseconds.

FromMillseconds(Int64) Obsolete.
Creates a period representing the specified number of miliseconds.

FromMinutes(Int64)
Creates a period representing the specified number of minutes.

FromMonths(Int64)
Creates a period representing the specified number of months.

FromSeconds(Int64)
Creates a period representing the specified number of seconds.

FromTicks(Int64)
Creates a period representing the specified number of ticks.

FromWeeks(Int64)
Creates a period representing the specified number of weeks.

FromYears(Int64)
Creates a period representing the specified number of years.

GetHashCode()()()()
Returns the hash code for this period, consistent with Equals(Period).
(Overrides Object.GetHashCode()()()().)
HasDateComponent
Returns whether or not this period contains any non-zero date-based properties (days or higher).

HasTimeComponent
Returns whether or not this period contains any non-zero-valued time-based properties (hours or lower).

Hours
Gets the number of hours within this period.

Milliseconds
Gets the number of milliseconds within this period.

Minutes
Gets the number of minutes within this period.

Months
Gets the number of months within this period.

Normalize()()()()
Returns a normalized version of this period, such that equivalent (but potentially non-equal) periods are changed to the same representation.

NormalizingEqualityComparer
Returns an equality comparer which compares periods by first normalizing them - so 24 hours is deemed equal to 1 day, and so on. Note that as per the Normalize()()()() method, years and months are unchanged by normalization - so 12 months does not equal 1 year.

Seconds
Gets the number of seconds within this period.

Subtraction(Period, Period)
Subtracts one period from another, by simply subtracting each property value.

Ticks
Gets the number of ticks within this period.

ToBuilder()()()()
Creates a PeriodBuilder from this instance. The new builder is populated with the values from this period, but is then detached from it: changes made to the builder are not reflected in this period.

ToDuration()()()()
For periods that do not contain a non-zero number of years or months, returns a duration for this period assuming a standard 7-day week, 24-hour day, 60-minute hour etc.

ToString()()()()
Returns this string formatted according to the RoundtripPattern.
(Overrides Object.ToString()()()().)
Weeks
Gets the number of weeks within this period.

Years
Gets the number of years within this period.

Zero
A period containing only zero-valued properties.

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.)

Thread Safety
This type is immutable reference type. See the thread safety section of the user guide for more information.
Inheritance Hierarchy
Object
Period

Assembly: NodaTime (Module: NodaTime.dll) Version: 1.2.0.0 (1.2.0)