Class PeriodBuilder
A mutable builder class for Period values. Each property can
be set independently, and then a Period can be created from the result
using the Build() method.
Since 1.4.x
Availability net45, netstandard1.3
Inheritance
Object
PeriodBuilder
Implements
IXmlSerializable
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public sealed class PeriodBuilder : IXmlSerializable
Constructors
PeriodBuilder()
Creates a new period builder with an initially zero period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public PeriodBuilder()
PeriodBuilder(Period)
Creates a new period builder with the values from an existing
period. Calling this constructor instead of ToBuilder()
allows object initializers to be used.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public PeriodBuilder(Period period)
Parameters
Type | Name | Description |
---|---|---|
Period | period | An existing period to copy values from. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | period is null. |
Properties
Days
Gets or sets the number of days within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public int Days { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of days within the period. |
Hours
Gets or sets the number of hours within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long Hours { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of hours within the period. |
Item[PeriodUnits]
Gets or sets the value of a single unit.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long this[PeriodUnits unit] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
PeriodUnits | unit | A single value within the PeriodUnits enumeration. |
Property Value
Type | Description |
---|---|
Int64 | The value of the given unit within this period builder, or zero if the unit is unset. |
Remarks
The type of this indexer is System.Int64 for uniformity, but any date unit (year, month, week, day) will only ever have a value in the range of System.Int32.
For the Nanoseconds unit, the value is converted to Int64
when reading from the indexer, causing it to
fail if the value is out of range (around 250 years). To access the values of very large numbers of nanoseconds, use the Nanoseconds
property directly.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | unit is not a single unit, or a value is provided for a date unit which is outside the range of System.Int32. |
Milliseconds
Gets or sets the number of milliseconds within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long Milliseconds { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of milliseconds within the period. |
Minutes
Gets or sets the number of minutes within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long Minutes { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of minutes within the period. |
Months
Gets or sets the number of months within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public int Months { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of months within the period. |
Nanoseconds
Gets or sets the number of nanoseconds within the period.
Since 3.1.x
Availability net45, netstandard1.3
Declaration
public long Nanoseconds { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of nanoseconds within the period. |
Seconds
Gets or sets the number of seconds within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long Seconds { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of seconds within the period. |
Ticks
Gets or sets the number of ticks within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public long Ticks { get; set; }
Property Value
Type | Description |
---|---|
Int64 | The number of ticks within the period. |
Weeks
Gets or sets the number of weeks within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public int Weeks { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of weeks within the period. |
Years
Gets or sets the number of years within the period.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public int Years { get; set; }
Property Value
Type | Description |
---|---|
Int32 | The number of years within the period. |
Methods
Build()
Builds a period from the properties in this builder.
Since 1.4.x
Availability net45, netstandard1.3
Declaration
public Period Build()
Returns
Type | Description |
---|---|
Period | A period containing the values from this builder. |
Explicit Interface Implementations
IXmlSerializable.GetSchema()
Since unstable
Availability net45, netstandard1.3
Declaration
XmlSchema IXmlSerializable.GetSchema()
Returns
Type | Description |
---|---|
XmlSchema |
IXmlSerializable.ReadXml(XmlReader)
Since 3.1.x
Availability net45, netstandard1.3
Declaration
void IXmlSerializable.ReadXml(XmlReader reader)
Parameters
Type | Name | Description |
---|---|---|
XmlReader | reader |
IXmlSerializable.WriteXml(XmlWriter)
Since 3.1.x
Availability net45, netstandard1.3
Declaration
void IXmlSerializable.WriteXml(XmlWriter writer)
Parameters
Type | Name | Description |
---|---|---|
XmlWriter | writer |
Implements
System.Xml.Serialization.IXmlSerializable