Class Interval
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
Interval(DateTimeOffset, string, string)
public Interval(DateTimeOffset effective, string length, string weekdays = null)
Parameters
effectiveDateTimeOffsetlengthstringweekdaysstring
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
Properties
Date
Date the interval opens for the first time. (Year/Month/Date Format = yyyy-MM-dd)
public string Date { get; set; }
Property Value
Length
Length of time the interval is open. (e.g. 1h, 30m, 2d)
public string Length { get; set; }
Property Value
Recurrences
Days of the week when the interval is open. (e.g. Sun, Mon, Tue)
public List<string> Recurrences { get; set; }
Property Value
Time
Time of day the interval opens. (24-Hour Format = HH:mm)
public string Time { get; set; }
Property Value
Zone
Time zone identifier.
public string Zone { get; set; }
Property Value
Methods
Contains(DateTimeOffset)
Determines if the interval contains a specific point in time.
public bool Contains(DateTimeOffset current)
Parameters
currentDateTimeOffset
Returns
GetDuration()
Parses the interval length into a TimeSpan.
public TimeSpan GetDuration()
Returns
GetEffective()
Date and time the interval opens for the first time.
public DateTimeOffset GetEffective()
Returns
GetEnd(DateTimeOffset)
Calculates when the interval potentially ends on a specific date.
public DateTimeOffset GetEnd(DateTimeOffset current)
Parameters
currentDateTimeOffset
Returns
GetStart(DateTimeOffset)
Calculates when the interval potentially starts on a specific date.
public DateTimeOffset GetStart(DateTimeOffset current)
Parameters
currentDateTimeOffset
Returns
IncludesRecurrence(string)
Determines if the interval includes a recurrence for a specific day of the week.
public bool IncludesRecurrence(string day)
Parameters
daystring
Returns
IsRecurring()
Determines if the interval recurs throughout the week.
public bool IsRecurring()
Returns
IsValid()
Determines if the interval is valid.
public bool IsValid()
Returns
MinutesBeforeOpenTime(DateTimeOffset)
Calculates exactly when the interval opens next, following a specific date and time.
public int? MinutesBeforeOpenTime(DateTimeOffset current)
Parameters
currentDateTimeOffset
Returns
- int?
NextOpenTime(DateTimeOffset)
Calculates exactly when the interval opens next, following a specific date and time.
public DateTimeOffset? NextOpenTime(DateTimeOffset current)
Parameters
currentDateTimeOffset
Returns
RecurrencesAsDays()
Parses the list of recurrences into an enumeration of weekdays.
public List<DayOfWeek> RecurrencesAsDays()
Returns
Validate()
Determines validation errors in the interval.
public List<ValidationError> Validate()