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
years
intNumber of years.
months
intNumber of months.
weeks
intNumber of weeks.
days
intNumber 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
years
intNumber of years.
months
intNumber of months.
weeks
intNumber of weeks.
days
intNumber of days.
hours
intNumber of hours.
minutes
longNumber of minutes.
seconds
longNumber of seconds.
milliseconds
longNumber of milliseconds.
microseconds
longNumber of microseconds.
ticks
longNumber 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
hours
intNumber of hours.
minutes
longNumber of minutes.
seconds
longNumber of seconds.
milliseconds
longNumber of milliseconds.
microseconds
longNumber of microseconds.
ticks
longNumber 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
other
PeriodOther 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
days
intDays to add.
Returns
AddHours(int)
Creates a new Period instance by adding the specified number of hours
.
[Pure]
public Period AddHours(int hours)
Parameters
hours
intHours to add.
Returns
AddMicroseconds(long)
Creates a new Period instance by adding the specified number of microseconds
.
[Pure]
public Period AddMicroseconds(long microseconds)
Parameters
microseconds
longMicroseconds to add.
Returns
AddMilliseconds(long)
Creates a new Period instance by adding the specified number of milliseconds
.
[Pure]
public Period AddMilliseconds(long milliseconds)
Parameters
milliseconds
longMilliseconds to add.
Returns
AddMinutes(long)
Creates a new Period instance by adding the specified number of minutes
.
[Pure]
public Period AddMinutes(long minutes)
Parameters
minutes
longMinutes to add.
Returns
AddMonths(int)
Creates a new Period instance by adding the specified number of months
.
[Pure]
public Period AddMonths(int months)
Parameters
months
intMonths to add.
Returns
AddSeconds(long)
Creates a new Period instance by adding the specified number of seconds
.
[Pure]
public Period AddSeconds(long seconds)
Parameters
seconds
longSeconds to add.
Returns
AddTicks(long)
Creates a new Period instance by adding the specified number of ticks
.
[Pure]
public Period AddTicks(long ticks)
Parameters
ticks
longTicks to add.
Returns
AddWeeks(int)
Creates a new Period instance by adding the specified number of weeks
.
[Pure]
public Period AddWeeks(int weeks)
Parameters
weeks
intWeeks to add.
Returns
AddYears(int)
Creates a new Period instance by adding the specified number of years
.
[Pure]
public Period AddYears(int years)
Parameters
years
intYears 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
other
PeriodAn 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
obj
objectThe object to compare with the current instance.
Returns
- bool
true if
obj
and 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
days
intNumber of days.
Returns
FromHours(int)
Creates a new Period instance.
[Pure]
public static Period FromHours(int hours)
Parameters
hours
intNumber of hours.
Returns
FromMicroseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMicroseconds(long microseconds)
Parameters
microseconds
longNumber of microseconds.
Returns
FromMilliseconds(long)
Creates a new Period instance.
[Pure]
public static Period FromMilliseconds(long milliseconds)
Parameters
milliseconds
longNumber of milliseconds.
Returns
FromMinutes(long)
Creates a new Period instance.
[Pure]
public static Period FromMinutes(long minutes)
Parameters
minutes
longNumber of minutes.
Returns
FromMonths(int)
Creates a new Period instance.
[Pure]
public static Period FromMonths(int months)
Parameters
months
intNumber of months.
Returns
FromSeconds(long)
Creates a new Period instance.
[Pure]
public static Period FromSeconds(long seconds)
Parameters
seconds
longNumber of seconds.
Returns
FromTicks(long)
Creates a new Period instance.
[Pure]
public static Period FromTicks(long ticks)
Parameters
ticks
longNumber of ticks.
Returns
FromWeeks(int)
Creates a new Period instance.
[Pure]
public static Period FromWeeks(int weeks)
Parameters
weeks
intNumber of weeks.
Returns
FromYears(int)
Creates a new Period instance.
[Pure]
public static Period FromYears(int years)
Parameters
years
intNumber 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
other
PeriodOther instance to copy components from.
units
PeriodUnitsPeriodUnits 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
years
intNumber of years.
months
intNumber of months.
weeks
intNumber of weeks.
days
intNumber of days.
Returns
SetDays(int)
Creates a new Period instance by setting the number of days.
[Pure]
public Period SetDays(int days)
Parameters
days
intNumber of days.
Returns
SetHours(int)
Creates a new Period instance by setting the number of hours.
[Pure]
public Period SetHours(int hours)
Parameters
hours
intNumber of hours.
Returns
SetMicroseconds(long)
Creates a new Period instance by setting the number of microseconds.
[Pure]
public Period SetMicroseconds(long microseconds)
Parameters
microseconds
longNumber of microseconds.
Returns
SetMilliseconds(long)
Creates a new Period instance by setting the number of milliseconds.
[Pure]
public Period SetMilliseconds(long milliseconds)
Parameters
milliseconds
longNumber of milliseconds.
Returns
SetMinutes(long)
Creates a new Period instance by setting the number of minutes.
[Pure]
public Period SetMinutes(long minutes)
Parameters
minutes
longNumber of minutes.
Returns
SetMonths(int)
Creates a new Period instance by setting the number of months.
[Pure]
public Period SetMonths(int months)
Parameters
months
intNumber of months.
Returns
SetSeconds(long)
Creates a new Period instance by setting the number of seconds.
[Pure]
public Period SetSeconds(long seconds)
Parameters
seconds
longNumber of seconds.
Returns
SetTicks(long)
Creates a new Period instance by setting the number of ticks.
[Pure]
public Period SetTicks(long ticks)
Parameters
ticks
longNumber 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
hours
intNumber of hours.
minutes
longNumber of minutes.
seconds
longNumber of seconds.
milliseconds
longNumber of milliseconds.
microseconds
longNumber of microseconds.
ticks
longNumber of ticks.
Returns
SetWeeks(int)
Creates a new Period instance by setting the number of weeks.
[Pure]
public Period SetWeeks(int weeks)
Parameters
weeks
intNumber of weeks.
Returns
SetYears(int)
Creates a new Period instance by setting the number of years.
[Pure]
public Period SetYears(int years)
Parameters
years
intNumber of years.
Returns
Skip(PeriodUnits)
Creates a new Period instance by setting chosen components to 0.
[Pure]
public Period Skip(PeriodUnits units)
Parameters
units
PeriodUnitsPeriodUnits 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
other
PeriodOther 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
days
intDays to subtract.
Returns
SubtractHours(int)
Creates a new Period instance by subtracting the specified number of hours
.
[Pure]
public Period SubtractHours(int hours)
Parameters
hours
intHours to subtract.
Returns
SubtractMicroseconds(long)
Creates a new Period instance by subtracting the specified number of microseconds
.
[Pure]
public Period SubtractMicroseconds(long microseconds)
Parameters
microseconds
longMicroseconds to subtract.
Returns
SubtractMilliseconds(long)
Creates a new Period instance by subtracting the specified number of milliseconds
.
[Pure]
public Period SubtractMilliseconds(long milliseconds)
Parameters
milliseconds
longMilliseconds to subtract.
Returns
SubtractMinutes(long)
Creates a new Period instance by subtracting the specified number of minutes
.
[Pure]
public Period SubtractMinutes(long minutes)
Parameters
minutes
longMinutes to subtract.
Returns
SubtractMonths(int)
Creates a new Period instance by subtracting the specified number of months
.
[Pure]
public Period SubtractMonths(int months)
Parameters
months
intMonths to subtract.
Returns
SubtractSeconds(long)
Creates a new Period instance by subtracting the specified number of seconds
.
[Pure]
public Period SubtractSeconds(long seconds)
Parameters
seconds
longSeconds to subtract.
Returns
SubtractTicks(long)
Creates a new Period instance by subtracting the specified number of ticks
.
[Pure]
public Period SubtractTicks(long ticks)
Parameters
ticks
longTicks to subtract.
Returns
SubtractWeeks(int)
Creates a new Period instance by subtracting the specified number of weeks
.
[Pure]
public Period SubtractWeeks(int weeks)
Parameters
weeks
intWeeks to subtract.
Returns
SubtractYears(int)
Creates a new Period instance by subtracting the specified number of years
.
[Pure]
public Period SubtractYears(int years)
Parameters
years
intYears to subtract.
Returns
Take(PeriodUnits)
Creates a new Period instance by only copying the chosen components.
[Pure]
public Period Take(PeriodUnits units)
Parameters
units
PeriodUnitsPeriodUnits 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
a
PeriodOperand.