Struct Period
Represents a difference between two timestamps as separate date and/or time components.
public readonly struct Period : IEquatable<Period>- Implements
- Inherited Members
Constructors
Period(int, int, int, int)
Creates a new Period instance from date components.
public Period(int years, int months, int weeks, int days)Parameters
- yearsint
- Number of years. 
- monthsint
- Number of months. 
- weeksint
- Number of weeks. 
- daysint
- Number of days. 
Period(int, int, int, int, int, long, long, long, long, long)
Creates a new Period instance.
public Period(int years, int months, int weeks, int days, int hours, long minutes, long seconds, long milliseconds, long microseconds, long ticks)Parameters
- yearsint
- Number of years. 
- monthsint
- Number of months. 
- weeksint
- Number of weeks. 
- daysint
- Number of days. 
- hoursint
- Number of hours. 
- minuteslong
- Number of minutes. 
- secondslong
- Number of seconds. 
- millisecondslong
- Number of milliseconds. 
- microsecondslong
- Number of microseconds. 
- tickslong
- Number of ticks. 
Period(int, long, long, long, long, long)
Creates a new Period instance from time components.
public Period(int hours, long minutes, long seconds, long milliseconds, long microseconds, long ticks)Parameters
- hoursint
- Number of hours. 
- minuteslong
- Number of minutes. 
- secondslong
- Number of seconds. 
- millisecondslong
- Number of milliseconds. 
- microsecondslong
- Number of microseconds. 
- tickslong
- Number of ticks. 
Period(TimeSpan)
Creates a new Period instance.
public Period(TimeSpan timeSpan)Parameters
Fields
Empty
Represents an empty Period, without any ActiveUnits.
public static readonly Period EmptyField Value
Properties
ActiveUnits
Checks which date and time components have values different than 0 and returns a PeriodUnits instance.
public PeriodUnits ActiveUnits { get; }Property Value
Days
Number of days.
public int Days { get; }Property Value
Hours
Number of hours.
public int Hours { get; }Property Value
Microseconds
Number of microseconds.
public long Microseconds { get; }Property Value
Milliseconds
Number of milliseconds.
public long Milliseconds { get; }Property Value
Minutes
Number of minutes.
public long Minutes { get; }Property Value
Months
Number of months.
public int Months { get; }Property Value
Seconds
Number of seconds.
public long Seconds { get; }Property Value
Ticks
Number of ticks.
public long Ticks { get; }Property Value
Weeks
Number of weeks.
public int Weeks { get; }Property Value
Years
Number of years.
public int Years { get; }Property Value
Methods
Abs()
Creates a new Period instance by calculating an absolute value for all components of this instance.
[Pure]
public Period Abs()Returns
Add(Period)
Creates a new Period instance by adding other to this instance.
[Pure]
public Period Add(Period other)Parameters
- otherPeriod
- Other instance to add. 
Returns
AddDays(int)
Creates a new Period instance by adding the specified number of days.
[Pure]
public Period AddDays(int days)Parameters
- daysint
- Days to add. 
Returns
AddHours(int)
Creates a new Period instance by adding the specified number of hours.
[Pure]
public Period AddHours(int hours)Parameters
- hoursint
- Hours to add. 
Returns
AddMicroseconds(long)
Creates a new Period instance by adding the specified number of microseconds.
[Pure]
public Period AddMicroseconds(long microseconds)Parameters
- microsecondslong
- Microseconds to add. 
Returns
AddMilliseconds(long)
Creates a new Period instance by adding the specified number of milliseconds.
[Pure]
public Period AddMilliseconds(long milliseconds)Parameters
- millisecondslong
- Milliseconds to add. 
Returns
AddMinutes(long)
Creates a new Period instance by adding the specified number of minutes.
[Pure]
public Period AddMinutes(long minutes)Parameters
- minuteslong
- Minutes to add. 
Returns
AddMonths(int)
Creates a new Period instance by adding the specified number of months.
[Pure]
public Period AddMonths(int months)Parameters
- monthsint
- Months to add. 
Returns
AddSeconds(long)
Creates a new Period instance by adding the specified number of seconds.
[Pure]
public Period AddSeconds(long seconds)Parameters
- secondslong
- Seconds to add. 
Returns
AddTicks(long)
Creates a new Period instance by adding the specified number of ticks.
[Pure]
public Period AddTicks(long ticks)Parameters
- tickslong
- Ticks to add. 
Returns
AddWeeks(int)
Creates a new Period instance by adding the specified number of weeks.
[Pure]
public Period AddWeeks(int weeks)Parameters
- weeksint
- Weeks to add. 
Returns
AddYears(int)
Creates a new Period instance by adding the specified number of years.
[Pure]
public Period AddYears(int years)Parameters
- yearsint
- Years to add. 
Returns
Equals(Period)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(Period other)Parameters
- otherPeriod
- An object to compare with this object. 
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)Parameters
- objobject
- The object to compare with the current instance. 
Returns
- bool
- true if - objand this instance are the same type and represent the same value; otherwise, false.
FromDays(int)
Creates a new Period instance.
[Pure]
public static Period FromDays(int days)Parameters
- daysint
- Number of days. 
Returns
FromHours(int)
Creates a new Period instance.
[Pure]
public static Period FromHours(int hours)Parameters
- hoursint
- Number of hours. 
Returns
FromMicroseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMicroseconds(long microseconds)Parameters
- microsecondslong
- Number of microseconds. 
Returns
FromMilliseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMilliseconds(long milliseconds)Parameters
- millisecondslong
- Number of milliseconds. 
Returns
FromMinutes(long)
Creates a new Period instance.
[Pure]
public static Period FromMinutes(long minutes)Parameters
- minuteslong
- Number of minutes. 
Returns
FromMonths(int)
Creates a new Period instance.
[Pure]
public static Period FromMonths(int months)Parameters
- monthsint
- Number of months. 
Returns
FromSeconds(long)
Creates a new Period instance.
[Pure]
public static Period FromSeconds(long seconds)Parameters
- secondslong
- Number of seconds. 
Returns
FromTicks(long)
Creates a new Period instance.
[Pure]
public static Period FromTicks(long ticks)Parameters
- tickslong
- Number of ticks. 
Returns
FromWeeks(int)
Creates a new Period instance.
[Pure]
public static Period FromWeeks(int weeks)Parameters
- weeksint
- Number of weeks. 
Returns
FromYears(int)
Creates a new Period instance.
[Pure]
public static Period FromYears(int years)Parameters
- yearsint
- Number of years. 
Returns
GetHashCode()
Returns the hash code for this instance.
[Pure]
public override int GetHashCode()Returns
- int
- A 32-bit signed integer that is the hash code for this instance. 
Negate()
Creates a new Period instance by negating all components of this instance.
[Pure]
public Period Negate()Returns
Set(Period, PeriodUnits)
Creates a new Period instance by copying chosen components from the other instance.
[Pure]
public Period Set(Period other, PeriodUnits units)Parameters
- otherPeriod
- Other instance to copy components from. 
- unitsPeriodUnits
- PeriodUnits to copy. 
Returns
SetDate(int, int, int, int)
Creates a new Period instance by setting date components.
[Pure]
public Period SetDate(int years, int months, int weeks, int days)Parameters
- yearsint
- Number of years. 
- monthsint
- Number of months. 
- weeksint
- Number of weeks. 
- daysint
- Number of days. 
Returns
SetDays(int)
Creates a new Period instance by setting the number of days.
[Pure]
public Period SetDays(int days)Parameters
- daysint
- Number of days. 
Returns
SetHours(int)
Creates a new Period instance by setting the number of hours.
[Pure]
public Period SetHours(int hours)Parameters
- hoursint
- Number of hours. 
Returns
SetMicroseconds(long)
Creates a new Period instance by setting the number of microseconds.
[Pure]
public Period SetMicroseconds(long microseconds)Parameters
- microsecondslong
- Number of microseconds. 
Returns
SetMilliseconds(long)
Creates a new Period instance by setting the number of milliseconds.
[Pure]
public Period SetMilliseconds(long milliseconds)Parameters
- millisecondslong
- Number of milliseconds. 
Returns
SetMinutes(long)
Creates a new Period instance by setting the number of minutes.
[Pure]
public Period SetMinutes(long minutes)Parameters
- minuteslong
- Number of minutes. 
Returns
SetMonths(int)
Creates a new Period instance by setting the number of months.
[Pure]
public Period SetMonths(int months)Parameters
- monthsint
- Number of months. 
Returns
SetSeconds(long)
Creates a new Period instance by setting the number of seconds.
[Pure]
public Period SetSeconds(long seconds)Parameters
- secondslong
- Number of seconds. 
Returns
SetTicks(long)
Creates a new Period instance by setting the number of ticks.
[Pure]
public Period SetTicks(long ticks)Parameters
- tickslong
- Number of ticks. 
Returns
SetTime(int, long, long, long, long, long)
Creates a new Period instance by setting time components.
[Pure]
public Period SetTime(int hours, long minutes, long seconds, long milliseconds, long microseconds, long ticks)Parameters
- hoursint
- Number of hours. 
- minuteslong
- Number of minutes. 
- secondslong
- Number of seconds. 
- millisecondslong
- Number of milliseconds. 
- microsecondslong
- Number of microseconds. 
- tickslong
- Number of ticks. 
Returns
SetWeeks(int)
Creates a new Period instance by setting the number of weeks.
[Pure]
public Period SetWeeks(int weeks)Parameters
- weeksint
- Number of weeks. 
Returns
SetYears(int)
Creates a new Period instance by setting the number of years.
[Pure]
public Period SetYears(int years)Parameters
- yearsint
- Number of years. 
Returns
Skip(PeriodUnits)
Creates a new Period instance by setting chosen components to 0.
[Pure]
public Period Skip(PeriodUnits units)Parameters
- unitsPeriodUnits
- PeriodUnits to set to 0. 
Returns
Subtract(Period)
Creates a new Period instance by subtracting other from this instance.
[Pure]
public Period Subtract(Period other)Parameters
- otherPeriod
- Other instance to subtract. 
Returns
SubtractDays(int)
Creates a new Period instance by subtracting the specified number of days.
[Pure]
public Period SubtractDays(int days)Parameters
- daysint
- Days to subtract. 
Returns
SubtractHours(int)
Creates a new Period instance by subtracting the specified number of hours.
[Pure]
public Period SubtractHours(int hours)Parameters
- hoursint
- Hours to subtract. 
Returns
SubtractMicroseconds(long)
Creates a new Period instance by subtracting the specified number of microseconds.
[Pure]
public Period SubtractMicroseconds(long microseconds)Parameters
- microsecondslong
- Microseconds to subtract. 
Returns
SubtractMilliseconds(long)
Creates a new Period instance by subtracting the specified number of milliseconds.
[Pure]
public Period SubtractMilliseconds(long milliseconds)Parameters
- millisecondslong
- Milliseconds to subtract. 
Returns
SubtractMinutes(long)
Creates a new Period instance by subtracting the specified number of minutes.
[Pure]
public Period SubtractMinutes(long minutes)Parameters
- minuteslong
- Minutes to subtract. 
Returns
SubtractMonths(int)
Creates a new Period instance by subtracting the specified number of months.
[Pure]
public Period SubtractMonths(int months)Parameters
- monthsint
- Months to subtract. 
Returns
SubtractSeconds(long)
Creates a new Period instance by subtracting the specified number of seconds.
[Pure]
public Period SubtractSeconds(long seconds)Parameters
- secondslong
- Seconds to subtract. 
Returns
SubtractTicks(long)
Creates a new Period instance by subtracting the specified number of ticks.
[Pure]
public Period SubtractTicks(long ticks)Parameters
- tickslong
- Ticks to subtract. 
Returns
SubtractWeeks(int)
Creates a new Period instance by subtracting the specified number of weeks.
[Pure]
public Period SubtractWeeks(int weeks)Parameters
- weeksint
- Weeks to subtract. 
Returns
SubtractYears(int)
Creates a new Period instance by subtracting the specified number of years.
[Pure]
public Period SubtractYears(int years)Parameters
- yearsint
- Years to subtract. 
Returns
Take(PeriodUnits)
Creates a new Period instance by only copying the chosen components.
[Pure]
public Period Take(PeriodUnits units)Parameters
- unitsPeriodUnits
- PeriodUnits to copy. Other components will be ignored and set to 0. 
Returns
ToString()
Returns a string representation of this Period instance.
[Pure]
public override string ToString()Returns
- string
- String representation. 
Operators
operator +(Period, Period)
Creates a new Period instance by adding a and b together.
[Pure]
public static Period operator +(Period a, Period b)Parameters
Returns
operator ==(Period, Period)
Checks if a is equal to b.
[Pure]
public static bool operator ==(Period a, Period b)Parameters
Returns
- bool
- true when operands are equal, otherwise false. 
operator !=(Period, Period)
Checks if a is not equal to b.
[Pure]
public static bool operator !=(Period a, Period b)Parameters
Returns
- bool
- true when operands are not equal, otherwise false. 
operator -(Period, Period)
Creates a new Period instance by subtracting b from a.
[Pure]
public static Period operator -(Period a, Period b)Parameters
Returns
operator -(Period)
Creates a new Period instance by negating the provided a.
[Pure]
public static Period operator -(Period a)Parameters
- aPeriod
- Operand.