Table of Contents

Class Interval

Namespace
Shift.Common
Assembly
Shift.Common.dll

Implements a half-open interval of date/time values.

public class Interval
Inheritance
Interval
Inherited Members
Extension Methods

Examples

A 10-minute interval starting at 9:00 contains values in the range [9:00 AM .. 9:10 PM). In other words, between 9:00 AM (inclusive) and 9:10 AM (exclusive).

Remarks

An interval contains a date/time value x if x occurs in this range: (Effective) ≤ x < (Effective + Duration) Please note this class uses DateTimeOffset values rather than DateTime values to guard against ambiguities that arise when the time zone offset is unspecified. In addition, it uses the MST/MDT time zone to ensure daylight savings is taken into account. For reference, Calgary Time Zone.

Constructors

Interval()

Constructs a default interval.

public Interval()

Remarks

The default is a non-recurring 60-minute interval that opens Jan 1, 2100 at 00:00 UTC. This ensures it is in the distant future and is therefore closed by default for all date/time values in the current century.

Interval(DateTime, string, string, string)

public Interval(DateTime effective, string zone, string length, string weekdays = null)

Parameters

effective DateTime
zone string
length string
weekdays string

Interval(DateTimeOffset, string, string)

public Interval(DateTimeOffset effective, string length, string weekdays = null)

Parameters

effective DateTimeOffset
length string
weekdays string

Interval(string, string, string, string, string)

Constructs an interval that opens on a specific date, at a specific time, within a specific time zone, for a specific period of time.

public Interval(string date, string time, string zone, string length, string weekdays = null)

Parameters

date string
time string
zone string
length string
weekdays string

Properties

Date

Date the interval opens for the first time. (Year/Month/Date Format = yyyy-MM-dd)

public string Date { get; set; }

Property Value

string

Length

Length of time the interval is open. (e.g. 1h, 30m, 2d)

public string Length { get; set; }

Property Value

string

Recurrences

Days of the week when the interval is open. (e.g. Sun, Mon, Tue)

public List<string> Recurrences { get; set; }

Property Value

List<string>

Time

Time of day the interval opens. (24-Hour Format = HH:mm)

public string Time { get; set; }

Property Value

string

Zone

Time zone identifier.

public string Zone { get; set; }

Property Value

string

Methods

Contains(DateTimeOffset)

Determines if the interval contains a specific point in time.

public bool Contains(DateTimeOffset current)

Parameters

current DateTimeOffset

Returns

bool

GetDuration()

Parses the interval length into a TimeSpan.

public TimeSpan GetDuration()

Returns

TimeSpan

GetEffective()

Date and time the interval opens for the first time.

public DateTimeOffset GetEffective()

Returns

DateTimeOffset

GetEnd(DateTimeOffset)

Calculates when the interval potentially ends on a specific date.

public DateTimeOffset GetEnd(DateTimeOffset current)

Parameters

current DateTimeOffset

Returns

DateTimeOffset

GetStart(DateTimeOffset)

Calculates when the interval potentially starts on a specific date.

public DateTimeOffset GetStart(DateTimeOffset current)

Parameters

current DateTimeOffset

Returns

DateTimeOffset

IncludesRecurrence(string)

Determines if the interval includes a recurrence for a specific day of the week.

public bool IncludesRecurrence(string day)

Parameters

day string

Returns

bool

IsRecurring()

Determines if the interval recurs throughout the week.

public bool IsRecurring()

Returns

bool

IsValid()

Determines if the interval is valid.

public bool IsValid()

Returns

bool

MinutesBeforeOpenTime(DateTimeOffset)

Calculates exactly when the interval opens next, following a specific date and time.

public int? MinutesBeforeOpenTime(DateTimeOffset current)

Parameters

current DateTimeOffset

Returns

int?

NextOpenTime(DateTimeOffset)

Calculates exactly when the interval opens next, following a specific date and time.

public DateTimeOffset? NextOpenTime(DateTimeOffset current)

Parameters

current DateTimeOffset

Returns

DateTimeOffset?

RecurrencesAsDays()

Parses the list of recurrences into an enumeration of weekdays.

public List<DayOfWeek> RecurrencesAsDays()

Returns

List<DayOfWeek>

Validate()

Determines validation errors in the interval.

public List<ValidationError> Validate()

Returns

List<ValidationError>