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
yearsintNumber of years.
monthsintNumber of months.
weeksintNumber of weeks.
daysintNumber 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
yearsintNumber of years.
monthsintNumber of months.
weeksintNumber of weeks.
daysintNumber of days.
hoursintNumber of hours.
minuteslongNumber of minutes.
secondslongNumber of seconds.
millisecondslongNumber of milliseconds.
microsecondslongNumber of microseconds.
tickslongNumber 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
hoursintNumber of hours.
minuteslongNumber of minutes.
secondslongNumber of seconds.
millisecondslongNumber of milliseconds.
microsecondslongNumber of microseconds.
tickslongNumber 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 Empty
Field 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
otherPeriodOther 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
daysintDays to add.
Returns
AddHours(int)
Creates a new Period instance by adding the specified number of hours.
[Pure]
public Period AddHours(int hours)
Parameters
hoursintHours to add.
Returns
AddMicroseconds(long)
Creates a new Period instance by adding the specified number of microseconds.
[Pure]
public Period AddMicroseconds(long microseconds)
Parameters
microsecondslongMicroseconds to add.
Returns
AddMilliseconds(long)
Creates a new Period instance by adding the specified number of milliseconds.
[Pure]
public Period AddMilliseconds(long milliseconds)
Parameters
millisecondslongMilliseconds to add.
Returns
AddMinutes(long)
Creates a new Period instance by adding the specified number of minutes.
[Pure]
public Period AddMinutes(long minutes)
Parameters
minuteslongMinutes to add.
Returns
AddMonths(int)
Creates a new Period instance by adding the specified number of months.
[Pure]
public Period AddMonths(int months)
Parameters
monthsintMonths to add.
Returns
AddSeconds(long)
Creates a new Period instance by adding the specified number of seconds.
[Pure]
public Period AddSeconds(long seconds)
Parameters
secondslongSeconds to add.
Returns
AddTicks(long)
Creates a new Period instance by adding the specified number of ticks.
[Pure]
public Period AddTicks(long ticks)
Parameters
tickslongTicks to add.
Returns
AddWeeks(int)
Creates a new Period instance by adding the specified number of weeks.
[Pure]
public Period AddWeeks(int weeks)
Parameters
weeksintWeeks to add.
Returns
AddYears(int)
Creates a new Period instance by adding the specified number of years.
[Pure]
public Period AddYears(int years)
Parameters
yearsintYears 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
otherPeriodAn 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
objobjectThe 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
daysintNumber of days.
Returns
FromHours(int)
Creates a new Period instance.
[Pure]
public static Period FromHours(int hours)
Parameters
hoursintNumber of hours.
Returns
FromMicroseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMicroseconds(long microseconds)
Parameters
microsecondslongNumber of microseconds.
Returns
FromMilliseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMilliseconds(long milliseconds)
Parameters
millisecondslongNumber of milliseconds.
Returns
FromMinutes(long)
Creates a new Period instance.
[Pure]
public static Period FromMinutes(long minutes)
Parameters
minuteslongNumber of minutes.
Returns
FromMonths(int)
Creates a new Period instance.
[Pure]
public static Period FromMonths(int months)
Parameters
monthsintNumber of months.
Returns
FromSeconds(long)
Creates a new Period instance.
[Pure]
public static Period FromSeconds(long seconds)
Parameters
secondslongNumber of seconds.
Returns
FromTicks(long)
Creates a new Period instance.
[Pure]
public static Period FromTicks(long ticks)
Parameters
tickslongNumber of ticks.
Returns
FromWeeks(int)
Creates a new Period instance.
[Pure]
public static Period FromWeeks(int weeks)
Parameters
weeksintNumber of weeks.
Returns
FromYears(int)
Creates a new Period instance.
[Pure]
public static Period FromYears(int years)
Parameters
yearsintNumber 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
otherPeriodOther instance to copy components from.
unitsPeriodUnitsPeriodUnits 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
yearsintNumber of years.
monthsintNumber of months.
weeksintNumber of weeks.
daysintNumber of days.
Returns
SetDays(int)
Creates a new Period instance by setting the number of days.
[Pure]
public Period SetDays(int days)
Parameters
daysintNumber of days.
Returns
SetHours(int)
Creates a new Period instance by setting the number of hours.
[Pure]
public Period SetHours(int hours)
Parameters
hoursintNumber of hours.
Returns
SetMicroseconds(long)
Creates a new Period instance by setting the number of microseconds.
[Pure]
public Period SetMicroseconds(long microseconds)
Parameters
microsecondslongNumber of microseconds.
Returns
SetMilliseconds(long)
Creates a new Period instance by setting the number of milliseconds.
[Pure]
public Period SetMilliseconds(long milliseconds)
Parameters
millisecondslongNumber of milliseconds.
Returns
SetMinutes(long)
Creates a new Period instance by setting the number of minutes.
[Pure]
public Period SetMinutes(long minutes)
Parameters
minuteslongNumber of minutes.
Returns
SetMonths(int)
Creates a new Period instance by setting the number of months.
[Pure]
public Period SetMonths(int months)
Parameters
monthsintNumber of months.
Returns
SetSeconds(long)
Creates a new Period instance by setting the number of seconds.
[Pure]
public Period SetSeconds(long seconds)
Parameters
secondslongNumber of seconds.
Returns
SetTicks(long)
Creates a new Period instance by setting the number of ticks.
[Pure]
public Period SetTicks(long ticks)
Parameters
tickslongNumber 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
hoursintNumber of hours.
minuteslongNumber of minutes.
secondslongNumber of seconds.
millisecondslongNumber of milliseconds.
microsecondslongNumber of microseconds.
tickslongNumber of ticks.
Returns
SetWeeks(int)
Creates a new Period instance by setting the number of weeks.
[Pure]
public Period SetWeeks(int weeks)
Parameters
weeksintNumber of weeks.
Returns
SetYears(int)
Creates a new Period instance by setting the number of years.
[Pure]
public Period SetYears(int years)
Parameters
yearsintNumber of years.
Returns
Skip(PeriodUnits)
Creates a new Period instance by setting chosen components to 0.
[Pure]
public Period Skip(PeriodUnits units)
Parameters
unitsPeriodUnitsPeriodUnits 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
otherPeriodOther 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
daysintDays to subtract.
Returns
SubtractHours(int)
Creates a new Period instance by subtracting the specified number of hours.
[Pure]
public Period SubtractHours(int hours)
Parameters
hoursintHours to subtract.
Returns
SubtractMicroseconds(long)
Creates a new Period instance by subtracting the specified number of microseconds.
[Pure]
public Period SubtractMicroseconds(long microseconds)
Parameters
microsecondslongMicroseconds to subtract.
Returns
SubtractMilliseconds(long)
Creates a new Period instance by subtracting the specified number of milliseconds.
[Pure]
public Period SubtractMilliseconds(long milliseconds)
Parameters
millisecondslongMilliseconds to subtract.
Returns
SubtractMinutes(long)
Creates a new Period instance by subtracting the specified number of minutes.
[Pure]
public Period SubtractMinutes(long minutes)
Parameters
minuteslongMinutes to subtract.
Returns
SubtractMonths(int)
Creates a new Period instance by subtracting the specified number of months.
[Pure]
public Period SubtractMonths(int months)
Parameters
monthsintMonths to subtract.
Returns
SubtractSeconds(long)
Creates a new Period instance by subtracting the specified number of seconds.
[Pure]
public Period SubtractSeconds(long seconds)
Parameters
secondslongSeconds to subtract.
Returns
SubtractTicks(long)
Creates a new Period instance by subtracting the specified number of ticks.
[Pure]
public Period SubtractTicks(long ticks)
Parameters
tickslongTicks to subtract.
Returns
SubtractWeeks(int)
Creates a new Period instance by subtracting the specified number of weeks.
[Pure]
public Period SubtractWeeks(int weeks)
Parameters
weeksintWeeks to subtract.
Returns
SubtractYears(int)
Creates a new Period instance by subtracting the specified number of years.
[Pure]
public Period SubtractYears(int years)
Parameters
yearsintYears to subtract.
Returns
Take(PeriodUnits)
Creates a new Period instance by only copying the chosen components.
[Pure]
public Period Take(PeriodUnits units)
Parameters
unitsPeriodUnitsPeriodUnits 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
aPeriodOperand.