Table of Contents

Struct Period

Namespace
LfrlAnvil.Chrono
Assembly
LfrlAnvil.Chrono.dll

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 int

Number of years.

months int

Number of months.

weeks int

Number of weeks.

days int

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

years int

Number of years.

months int

Number of months.

weeks int

Number of weeks.

days int

Number of days.

hours int

Number of hours.

minutes long

Number of minutes.

seconds long

Number of seconds.

milliseconds long

Number of milliseconds.

microseconds long

Number of microseconds.

ticks long

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

hours int

Number of hours.

minutes long

Number of minutes.

seconds long

Number of seconds.

milliseconds long

Number of milliseconds.

microseconds long

Number of microseconds.

ticks long

Number of ticks.

Period(TimeSpan)

Creates a new Period instance.

public Period(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

Source TimeSpan.

Fields

Empty

Represents an empty Period, without any ActiveUnits.

public static readonly Period Empty

Field Value

Period

Properties

ActiveUnits

Checks which date and time components have values different than 0 and returns a PeriodUnits instance.

public PeriodUnits ActiveUnits { get; }

Property Value

PeriodUnits

Days

Number of days.

public int Days { get; }

Property Value

int

Hours

Number of hours.

public int Hours { get; }

Property Value

int

Microseconds

Number of microseconds.

public long Microseconds { get; }

Property Value

long

Milliseconds

Number of milliseconds.

public long Milliseconds { get; }

Property Value

long

Minutes

Number of minutes.

public long Minutes { get; }

Property Value

long

Months

Number of months.

public int Months { get; }

Property Value

int

Seconds

Number of seconds.

public long Seconds { get; }

Property Value

long

Ticks

Number of ticks.

public long Ticks { get; }

Property Value

long

Weeks

Number of weeks.

public int Weeks { get; }

Property Value

int

Years

Number of years.

public int Years { get; }

Property Value

int

Methods

Abs()

Creates a new Period instance by calculating an absolute value for all components of this instance.

[Pure]
public Period Abs()

Returns

Period

New Period instance.

Add(Period)

Creates a new Period instance by adding other to this instance.

[Pure]
public Period Add(Period other)

Parameters

other Period

Other instance to add.

Returns

Period

New Period instance.

AddDays(int)

Creates a new Period instance by adding the specified number of days.

[Pure]
public Period AddDays(int days)

Parameters

days int

Days to add.

Returns

Period

New Period instance.

AddHours(int)

Creates a new Period instance by adding the specified number of hours.

[Pure]
public Period AddHours(int hours)

Parameters

hours int

Hours to add.

Returns

Period

New Period instance.

AddMicroseconds(long)

Creates a new Period instance by adding the specified number of microseconds.

[Pure]
public Period AddMicroseconds(long microseconds)

Parameters

microseconds long

Microseconds to add.

Returns

Period

New Period instance.

AddMilliseconds(long)

Creates a new Period instance by adding the specified number of milliseconds.

[Pure]
public Period AddMilliseconds(long milliseconds)

Parameters

milliseconds long

Milliseconds to add.

Returns

Period

New Period instance.

AddMinutes(long)

Creates a new Period instance by adding the specified number of minutes.

[Pure]
public Period AddMinutes(long minutes)

Parameters

minutes long

Minutes to add.

Returns

Period

New Period instance.

AddMonths(int)

Creates a new Period instance by adding the specified number of months.

[Pure]
public Period AddMonths(int months)

Parameters

months int

Months to add.

Returns

Period

New Period instance.

AddSeconds(long)

Creates a new Period instance by adding the specified number of seconds.

[Pure]
public Period AddSeconds(long seconds)

Parameters

seconds long

Seconds to add.

Returns

Period

New Period instance.

AddTicks(long)

Creates a new Period instance by adding the specified number of ticks.

[Pure]
public Period AddTicks(long ticks)

Parameters

ticks long

Ticks to add.

Returns

Period

New Period instance.

AddWeeks(int)

Creates a new Period instance by adding the specified number of weeks.

[Pure]
public Period AddWeeks(int weeks)

Parameters

weeks int

Weeks to add.

Returns

Period

New Period instance.

AddYears(int)

Creates a new Period instance by adding the specified number of years.

[Pure]
public Period AddYears(int years)

Parameters

years int

Years to add.

Returns

Period

New Period instance.

Equals(Period)

Indicates whether the current object is equal to another object of the same type.

[Pure]
public bool Equals(Period other)

Parameters

other Period

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The 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 int

Number of days.

Returns

Period

New Period instance.

FromHours(int)

Creates a new Period instance.

[Pure]
public static Period FromHours(int hours)

Parameters

hours int

Number of hours.

Returns

Period

New Period instance.

FromMicroseconds(long)

Creates a new Period instance.

[Pure]
public static Period FromMicroseconds(long microseconds)

Parameters

microseconds long

Number of microseconds.

Returns

Period

New Period instance.

FromMilliseconds(long)

Creates a new Period instance.

[Pure]
public static Period FromMilliseconds(long milliseconds)

Parameters

milliseconds long

Number of milliseconds.

Returns

Period

New Period instance.

FromMinutes(long)

Creates a new Period instance.

[Pure]
public static Period FromMinutes(long minutes)

Parameters

minutes long

Number of minutes.

Returns

Period

New Period instance.

FromMonths(int)

Creates a new Period instance.

[Pure]
public static Period FromMonths(int months)

Parameters

months int

Number of months.

Returns

Period

New Period instance.

FromSeconds(long)

Creates a new Period instance.

[Pure]
public static Period FromSeconds(long seconds)

Parameters

seconds long

Number of seconds.

Returns

Period

New Period instance.

FromTicks(long)

Creates a new Period instance.

[Pure]
public static Period FromTicks(long ticks)

Parameters

ticks long

Number of ticks.

Returns

Period

New Period instance.

FromWeeks(int)

Creates a new Period instance.

[Pure]
public static Period FromWeeks(int weeks)

Parameters

weeks int

Number of weeks.

Returns

Period

New Period instance.

FromYears(int)

Creates a new Period instance.

[Pure]
public static Period FromYears(int years)

Parameters

years int

Number of years.

Returns

Period

New Period instance.

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

Period

New Period instance.

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 Period

Other instance to copy components from.

units PeriodUnits

PeriodUnits to copy.

Returns

Period

New Period instance.

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 int

Number of years.

months int

Number of months.

weeks int

Number of weeks.

days int

Number of days.

Returns

Period

New Period instance.

SetDays(int)

Creates a new Period instance by setting the number of days.

[Pure]
public Period SetDays(int days)

Parameters

days int

Number of days.

Returns

Period

New Period instance.

SetHours(int)

Creates a new Period instance by setting the number of hours.

[Pure]
public Period SetHours(int hours)

Parameters

hours int

Number of hours.

Returns

Period

New Period instance.

SetMicroseconds(long)

Creates a new Period instance by setting the number of microseconds.

[Pure]
public Period SetMicroseconds(long microseconds)

Parameters

microseconds long

Number of microseconds.

Returns

Period

New Period instance.

SetMilliseconds(long)

Creates a new Period instance by setting the number of milliseconds.

[Pure]
public Period SetMilliseconds(long milliseconds)

Parameters

milliseconds long

Number of milliseconds.

Returns

Period

New Period instance.

SetMinutes(long)

Creates a new Period instance by setting the number of minutes.

[Pure]
public Period SetMinutes(long minutes)

Parameters

minutes long

Number of minutes.

Returns

Period

New Period instance.

SetMonths(int)

Creates a new Period instance by setting the number of months.

[Pure]
public Period SetMonths(int months)

Parameters

months int

Number of months.

Returns

Period

New Period instance.

SetSeconds(long)

Creates a new Period instance by setting the number of seconds.

[Pure]
public Period SetSeconds(long seconds)

Parameters

seconds long

Number of seconds.

Returns

Period

New Period instance.

SetTicks(long)

Creates a new Period instance by setting the number of ticks.

[Pure]
public Period SetTicks(long ticks)

Parameters

ticks long

Number of ticks.

Returns

Period

New Period instance.

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 int

Number of hours.

minutes long

Number of minutes.

seconds long

Number of seconds.

milliseconds long

Number of milliseconds.

microseconds long

Number of microseconds.

ticks long

Number of ticks.

Returns

Period

New Period instance.

SetWeeks(int)

Creates a new Period instance by setting the number of weeks.

[Pure]
public Period SetWeeks(int weeks)

Parameters

weeks int

Number of weeks.

Returns

Period

New Period instance.

SetYears(int)

Creates a new Period instance by setting the number of years.

[Pure]
public Period SetYears(int years)

Parameters

years int

Number of years.

Returns

Period

New Period instance.

Skip(PeriodUnits)

Creates a new Period instance by setting chosen components to 0.

[Pure]
public Period Skip(PeriodUnits units)

Parameters

units PeriodUnits

PeriodUnits to set to 0.

Returns

Period

New Period instance.

Subtract(Period)

Creates a new Period instance by subtracting other from this instance.

[Pure]
public Period Subtract(Period other)

Parameters

other Period

Other instance to subtract.

Returns

Period

New Period instance.

SubtractDays(int)

Creates a new Period instance by subtracting the specified number of days.

[Pure]
public Period SubtractDays(int days)

Parameters

days int

Days to subtract.

Returns

Period

New Period instance.

SubtractHours(int)

Creates a new Period instance by subtracting the specified number of hours.

[Pure]
public Period SubtractHours(int hours)

Parameters

hours int

Hours to subtract.

Returns

Period

New Period instance.

SubtractMicroseconds(long)

Creates a new Period instance by subtracting the specified number of microseconds.

[Pure]
public Period SubtractMicroseconds(long microseconds)

Parameters

microseconds long

Microseconds to subtract.

Returns

Period

New Period instance.

SubtractMilliseconds(long)

Creates a new Period instance by subtracting the specified number of milliseconds.

[Pure]
public Period SubtractMilliseconds(long milliseconds)

Parameters

milliseconds long

Milliseconds to subtract.

Returns

Period

New Period instance.

SubtractMinutes(long)

Creates a new Period instance by subtracting the specified number of minutes.

[Pure]
public Period SubtractMinutes(long minutes)

Parameters

minutes long

Minutes to subtract.

Returns

Period

New Period instance.

SubtractMonths(int)

Creates a new Period instance by subtracting the specified number of months.

[Pure]
public Period SubtractMonths(int months)

Parameters

months int

Months to subtract.

Returns

Period

New Period instance.

SubtractSeconds(long)

Creates a new Period instance by subtracting the specified number of seconds.

[Pure]
public Period SubtractSeconds(long seconds)

Parameters

seconds long

Seconds to subtract.

Returns

Period

New Period instance.

SubtractTicks(long)

Creates a new Period instance by subtracting the specified number of ticks.

[Pure]
public Period SubtractTicks(long ticks)

Parameters

ticks long

Ticks to subtract.

Returns

Period

New Period instance.

SubtractWeeks(int)

Creates a new Period instance by subtracting the specified number of weeks.

[Pure]
public Period SubtractWeeks(int weeks)

Parameters

weeks int

Weeks to subtract.

Returns

Period

New Period instance.

SubtractYears(int)

Creates a new Period instance by subtracting the specified number of years.

[Pure]
public Period SubtractYears(int years)

Parameters

years int

Years to subtract.

Returns

Period

New Period instance.

Take(PeriodUnits)

Creates a new Period instance by only copying the chosen components.

[Pure]
public Period Take(PeriodUnits units)

Parameters

units PeriodUnits

PeriodUnits to copy. Other components will be ignored and set to 0.

Returns

Period

New Period instance.

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

a Period

First operand.

b Period

Second operand.

Returns

Period

New Period instance.

operator ==(Period, Period)

Checks if a is equal to b.

[Pure]
public static bool operator ==(Period a, Period b)

Parameters

a Period

First operand.

b Period

Second operand.

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

a Period

First operand.

b Period

Second operand.

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

a Period

First operand.

b Period

Second operand.

Returns

Period

New Period instance.

operator -(Period)

Creates a new Period instance by negating the provided a.

[Pure]
public static Period operator -(Period a)

Parameters

a Period

Operand.

Returns

Period

New Period instance.