Show / Hide Table of Contents

    Class CalendarDateTime

    Abstract classes.

    Inheritance
    System.Object
    CalendarDateTime
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: ThisDate
    Assembly: ThisDate.dll
    Syntax
    [PublicAPI]
    public static class CalendarDateTime

    Properties

    | Improve this Doc View Source

    CountDateEvents

    Gets the total number of date events.

    Declaration
    public static int CountDateEvents { get; }
    Property Value
    Type Description
    System.Int32

    The total number of date events.

    | Improve this Doc View Source

    CountEvents

    Gets the total number of events.

    Declaration
    public static int CountEvents { get; }
    Property Value
    Type Description
    System.Int32

    The total number of events.

    | Improve this Doc View Source

    CountMonthlyEvents

    Gets the total number of monthly events.

    Declaration
    public static int CountMonthlyEvents { get; }
    Property Value
    Type Description
    System.Int32

    The total number of monthly events.

    | Improve this Doc View Source

    CountWeeklyEvents

    Gets the total number of weekly events.

    Declaration
    public static int CountWeeklyEvents { get; }
    Property Value
    Type Description
    System.Int32

    The total number of weekly events.

    | Improve this Doc View Source

    CountYearlyEvents

    Gets the total number of yearly events.

    Declaration
    public static int CountYearlyEvents { get; }
    Property Value
    Type Description
    System.Int32

    The total number of yearly events.

    | Improve this Doc View Source

    KeysDateEvents

    Gets the keys date events.

    Declaration
    public static ImmutableArray<string> KeysDateEvents { get; }
    Property Value
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    The keys date events.

    | Improve this Doc View Source

    KeysEvents

    Gets the keys events.

    Declaration
    public static ImmutableArray<string> KeysEvents { get; }
    Property Value
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    The keys events.

    | Improve this Doc View Source

    KeysMonthlyEvents

    Gets the keys monthly events.

    Declaration
    public static ImmutableArray<string> KeysMonthlyEvents { get; }
    Property Value
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    The keys monthly events.

    | Improve this Doc View Source

    KeysWeeklyEvents

    Gets the keys weekly events.

    Declaration
    public static ImmutableArray<string> KeysWeeklyEvents { get; }
    Property Value
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    The keys weekly events.

    | Improve this Doc View Source

    KeysYearlyEvents

    Gets the keys yearly events.

    Declaration
    public static ImmutableArray<string> KeysYearlyEvents { get; }
    Property Value
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    The keys yearly events.

    Methods

    | Improve this Doc View Source

    AddDateEvent(String, Boolean, DateTime)

    Adds an explicit single date event.

    Declaration
    public static void AddDateEvent([CanBeNull] string eventName, bool dayOff, DateTime date)
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.DateTime date

    The date Date.

    Remarks

    Adds an explicit single date such as July 18th, 2018 to the calendar.

    Examples
    CalendarDateTime.AddDateEvent("Party Day", true, new DateTime(2018, 18, 5);
    // Sets July 18, 2018 as a day off.
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique.

    | Improve this Doc View Source

    AddMonthlyDateEvent(String, Boolean, Int32, Nullable<DateTime>, Nullable<DateTime>)

    Adds a monthly date event.

    Declaration
    public static void AddMonthlyDateEvent([CanBeNull] string eventName, bool dayOff, int monthDay, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Int32 monthDay

    The month day, assumes [1...31] range. Caution, 29, 30, and 31 days may be problematic.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Adds a recurring monthly day of each month. Example: The 8th of each month.

    Examples
    var start = new DateTime(2018, 2, 1);
    // Electric bill due, starts Feb 1, 2018 and never ends.
    CalendarDateTime.AddMonthlyDateEvent("Electric Bill Due", false, 8, start);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when month day is out of range, assumes [1...31] range for unknown month.

    | Improve this Doc View Source

    AddMonthlyDayOfWeekForwardEvent(String, Boolean, DayOfWeek, Int32, Nullable<DateTime>, Nullable<DateTime>)

    Adds a monthly day of week forward (from start of month) event.

    Declaration
    public static void AddMonthlyDayOfWeekForwardEvent([CanBeNull] string eventName, bool dayOff, DayOfWeek dayOfWeek, int weeksForward, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.DayOfWeek dayOfWeek

    The day of week.

    System.Int32 weeksForward

    Weeks forward from the start of the month.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Add a monthly repeating n-week, day-of-week event, counting from the start of the month. Example: A meeting that occurs on the second Tuesday of every month.

    Examples
    CalendarDateTime.AddMonthlyDayOfWeekForwardEvent("Monthly Second Tuesday", false, DayOfWeek.Tuesday, 2);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when weeksForward is less han 1.

    | Improve this Doc View Source

    AddMonthlyDayOfWeekReverseEvent(String, Boolean, DayOfWeek, Int32, Nullable<DateTime>, Nullable<DateTime>)

    Adds a monthly day of week reverse (from end of month) event.

    Declaration
    public static void AddMonthlyDayOfWeekReverseEvent([CanBeNull] string eventName, bool dayOff, DayOfWeek dayOfWeek, int weeksReverse, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.DayOfWeek dayOfWeek

    The day of week.

    System.Int32 weeksReverse

    Weeks reverse from the end of the month.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Add a monthly Day-of-Week, n-weeks reverse from the end of the month. Example, The last Monday of each month. Memorial day (US) follows this pattern (it's not always the 4th Monday of May).

    Examples
    CalendarDateTime.AddMonthlyDayOfWeekReverseEvent("Last Monday Every Month", false, DateTime.Tuesday, 1)
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when weeksForward is less han 1.

    | Improve this Doc View Source

    AddMonthlyLastDayEvent(String, Boolean, Nullable<DateTime>, Nullable<DateTime>)

    Adds a monthly last day event.

    Declaration
    public static void AddMonthlyLastDayEvent([CanBeNull] string eventName, bool dayOff, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Add a monthly last day of the month. Typically the 30, or 31 of the month 28 or 29 in February.

    Examples
    CalendarDateTime.AddMonthlyLastDayEvent("Last date of every month", false);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    | Improve this Doc View Source

    AddWeeklyEvent(String, Boolean, IEnumerable<DayOfWeek>, Nullable<DateTime>, Int32, Nullable<DateTime>, Nullable<DateTime>)

    Adds a weekly event.

    Declaration
    public static void AddWeeklyEvent([CanBeNull] string eventName, bool dayOff, [CanBeNull] IEnumerable<DayOfWeek> daysOfWeek, DateTime? seedWeek = default(DateTime? ), int interval = 1, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Collections.Generic.IEnumerable<System.DayOfWeek> daysOfWeek

    The days of week. This may be null.

    System.Nullable<System.DateTime> seedWeek

    (Optional) (Optional if interval = 1) Seed date in the week of an occurrence.

    System.Int32 interval

    (Optional) The week skip interval, 1=every week, 2 = every 2 weeks, 3 = 3 weeks...

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Add a weekly day-of-week events, can occur on multiple days of the week and at some skip interval. The baseDate is the date of the interval. Paydays typically follow this pattern. The number of occurrences may vary from month to month because some months are 4 weeks, some are 5 weeks. Another example; a meeting every two weeks on Tuesdays and Thursday within a date range.

    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when interval is less than one.

    | Improve this Doc View Source

    AddWeeklyInMonthEvent(String, Boolean, DayOfWeek, IEnumerable<Int32>, Nullable<DateTime>, Nullable<DateTime>)

    Adds a weekly in month event.

    Declaration
    public static void AddWeeklyInMonthEvent([CanBeNull] string eventName, bool dayOff, DayOfWeek dayOfWeek, [CanBeNull] IEnumerable<int> weekIntervals = null, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.DayOfWeek dayOfWeek

    The day of week.

    System.Collections.Generic.IEnumerable<System.Int32> weekIntervals

    (Optional) The weekly intervals, If null every week, 1: 1 first week, 2: second week, 3: third week... Not every month will have a fifth week.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Adds weekly day-of-week events, can occur on multiple days of the week and at some interval by week. If the interval is null, all weeks [1...5.] are added, the 5th week does not occur every month. Its possible to set an odd pattern such as 1rst, 2nd week of every month.

    Examples
    // Mondays, first and third week.
    var weekIntervals = new int[] {1, 3};
    CalendarDateTime.AddWeeklyInMonthEvent("Backups", false, DayOfWeek.Monday, weekIntervals);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when interval is less than 1 or greater than 5.

    | Improve this Doc View Source

    AddWorkdays(DateTime, Int32)

    DateTime extension method that calculates (+/-) n-workdays from date. Workdays are defined by the calendar configuration.

    Declaration
    public static DateTime AddWorkdays(this DateTime date, int days)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.Int32 days

    Workdays to +add / -subtract.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Workdays are defined by calendar 'Add-' configuration methods, isWorkday define what days are skipped.

    Examples
    // 30 work days forward, skipping non-workdays in the calendar.
    var someDate = aDate.AddWorkdays(30);
    
    // 30 work days back, skipping non-workdays in the calendar.
    var backDate = aDate.AddWorkdays(-30);
    | Improve this Doc View Source

    AddYearlyCalculatedEvent(String, Boolean, Nullable<DateTime>, Nullable<DateTime>)

    Adds a yearly calculated event.

    Declaration
    public static void AddYearlyCalculatedEvent([CanBeNull] string eventName, bool dayOff, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Selects events what are mathematically derived, Easter Sunday and Good Friday.

    Examples
    // Note: Properties ending in "Text" (CalculatedEventsText.EasterSunday) are provided as convenience and to improve robustness.
    CalendarDateTime.AddYearlyCalculatedEvent(CalculatedEventsText.EasterSunday, true);
    CalendarDateTime.AddYearlyCalculatedEvent(CalculatedEventsText.GoodFriday, true);
    // Test:
    var easterDate2018 = new DateTime(2018, 4, 1);
    var result = easterDate2018.EventsOnDate(false, true);
    // [0] = "Easter Sunday"
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not either "EasterSunday" or "GoodFriday" or startDate > endDate.

    | Improve this Doc View Source

    AddYearlyDateEvent(String, Boolean, Int32, Int32, Boolean, Boolean, Nullable<DateTime>, Nullable<DateTime>)

    Adds a yearly date event.

    Declaration
    public static void AddYearlyDateEvent([CanBeNull] string eventName, bool dayOff, int month, int day, bool saturdayBack, bool sundayForward, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Int32 month

    The month.

    System.Int32 day

    The day.

    System.Boolean saturdayBack

    True to shift back to Friday if on Saturday.

    System.Boolean sundayForward

    True to shift forward to Monday if on Sunday.

    System.Nullable<System.DateTime> startDate

    (Optional) The start date.

    System.Nullable<System.DateTime> endDate

    (Optional) The end date.

    Remarks

    Selects yearly event on certain day of the month. If true, saturdayBack will shift celebration to Friday. If true, sundayForward will shift the celebration forward. New Years day is often shifted around the weekends.

    Examples
    // New Year's day, Jan 1, if on Saturday do not shift, if on Sunday then celebrate on Monday.
    CalendarDateTime("New Years Day", true, 1, 1, false, true);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when month is out of range [1...12] or when day is out of range for the given month.

    | Improve this Doc View Source

    AddYearlyDayOfWeekForwardEvent(String, Boolean, Int32, Int32, DayOfWeek, Nullable<DateTime>, Nullable<DateTime>)

    Adds a yearly day of week forward event.

    Declaration
    public static void AddYearlyDayOfWeekForwardEvent([CanBeNull] string eventName, bool dayOff, int month, int weeksForward, DayOfWeek dayOfWeek, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Int32 month

    The month.

    System.Int32 weeksForward

    Weeks forward from the start of the month.

    System.DayOfWeek dayOfWeek

    The day of week.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Selects events yearly events that occur on a certain day of the week going forward from the start of the month. Example: Martin Luther King day occurs on the second Monday in January.

    Examples
    // Thanksgiving is on the 4th Thursday (US) in November.
    CalendarDateTime.AddYearlyDayOfWeekForwardEvent("Thanksgiving", true, 11, 4);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when month is out of range [1...12] or when day is out of range for the given month.

    | Improve this Doc View Source

    AddYearlyDayOfWeekReverseEvent(String, Boolean, Int32, Int32, DayOfWeek, Nullable<DateTime>, Nullable<DateTime>)

    Adds a yearly day of week reverse event.

    Declaration
    public static void AddYearlyDayOfWeekReverseEvent([CanBeNull] string eventName, bool dayOff, int month, int weeksReverse, DayOfWeek dayOfWeek, DateTime? startDate = default(DateTime? ), DateTime? endDate = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event, must be unique.

    System.Boolean dayOff

    True if is a day off (is a workday).

    System.Int32 month

    The month.

    System.Int32 weeksReverse

    Weeks reverse from the end of the month.

    System.DayOfWeek dayOfWeek

    The day of week.

    System.Nullable<System.DateTime> startDate

    (Optional) The date start, DateTime.MinValue if null.

    System.Nullable<System.DateTime> endDate

    (Optional) The date end, DateTime.MaxValue if null.

    Remarks

    Selects events yearly events that occur on a certain day of the week, and week going reverse from the end of the month. Example: Memorial day is on the last Monday of May.

    Examples
    // Labor Day is the last Monday in May (US), usually the 4 week but not always.
    CalendarDateTime.AddYearlyDayOfWeekReverseEvent("Labor Day", true, 1, DayOfWeek.Monday);
    Exceptions
    Type Condition
    System.ArgumentNullException

    Thrown when eventName is null or empty.

    System.ArgumentException

    Thrown when eventName is not unique or startDate > endDate.

    System.ArgumentOutOfRangeException

    Thrown when month is out of range [1...12] or when day is out of range for the given month.

    | Improve this Doc View Source

    ClearCalendar()

    Clears the event calendar.

    Declaration
    public static void ClearCalendar()
    | Improve this Doc View Source

    ContainsEventKey(String)

    Query if 'eventName' contains event key.

    Declaration
    public static bool ContainsEventKey([CanBeNull] string eventName)
    Parameters
    Type Name Description
    System.String eventName

    Name of the event. This may be null.

    Returns
    Type Description
    System.Boolean

    True if it succeeds, false if it fails.

    | Improve this Doc View Source

    DateId(DateTime)

    date as "yyyyMMdd", typically used as dateId key on date dimension tables.

    Declaration
    public static int DateId(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Int32

    An int representing a date as yyyyMMdd.

    Remarks

    2018/1/1 (1/1/2018) => 20180101.

    Examples
    var aDate = new DateTime(2018, 5, 8);
    var result = aDate.DateId();
    // result = 20180508
    | Improve this Doc View Source

    DayOfWeekCountInMonth(DateTime)

    DateTime extension method returns the day-of-week count in month. Example: Feb 12, 2019 is the second Tuesday of the month.

    Declaration
    public static int DayOfWeekCountInMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Int32

    An int.

    Examples
    var aDate = new DateTime(2018, 5, 8);
    var result = aDate.DayOfWeekCountInMonth();
    // result = 2
    | Improve this Doc View Source

    DayOfWeekCountInYear(DateTime)

    DateTime extension method returns week count of the year.

    Declaration
    public static int DayOfWeekCountInYear(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Int32

    An int.

    Remarks

    Example: Feb 4, 2019 is 5 Mondays into the year and Feb 5, 2019 is 6 Tuesdays into the year.

    Examples
    var aDate = new DateTime(2019, 2, 5);
    var result = aDate.DayOfWeekCountInYear();
    // result = 6
    | Improve this Doc View Source

    DayOfWeekMonthForward(Int32, Int32, DayOfWeek, Int32)

    Returns the n-th Day-of-week from the start of the month going forward.

    Declaration
    public static DateTime DayOfWeekMonthForward(int year, int month, DayOfWeek dayOfWeek, int weeksForward)
    Parameters
    Type Name Description
    System.Int32 year

    The year.

    System.Int32 month

    The month.

    System.DayOfWeek dayOfWeek

    The day-of-week.

    System.Int32 weeksForward

    The weeks forward.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Use this method to return a day-of-week date count into the month. Example, 2th Tuesday of 2018 is February 13, 2018.

    Examples
    var result = CalendarDateTime.DayOfWeekMonthForward(2018, 2, DayOfWeek.Tuesday, 2);
    // result = {2/13/2018 12:00:00 AM}
    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown when DateTime.Year is out of bounds and if Month is out of bounds.

    System.ArgumentException

    Thrown when weeksForwards is less than 1.

    | Improve this Doc View Source

    DayOfWeekMonthReverse(Int32, Int32, DayOfWeek, Int32)

    Returns the nth Day-of-week from the end of the month going reverse.

    Declaration
    public static DateTime DayOfWeekMonthReverse(int year, int month, DayOfWeek dayOfWeek, int weeksReverse)
    Parameters
    Type Name Description
    System.Int32 year

    The year.

    System.Int32 month

    The month.

    System.DayOfWeek dayOfWeek

    The day-of-week.

    System.Int32 weeksReverse

    The weeks forward.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Use this method to return a day-of-week date count from the end of the month. Example, 2th February Tuesday from the end of the month in 2018, is February 20, 2018.

    Examples
    var result = CalendarDateTime.DayOfWeekMonthReverse(2018, 2, DayOfWeek.Tuesday, 2);
    // result = {2/20/2018 12:00:00 AM} 
    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown when DateTime.Year is out of bounds and if Month is out of bounds.

    System.ArgumentException

    Thrown when weeksForwards is less than 1.

    | Improve this Doc View Source

    DayOfWeekShift(DateTime, DayOfWeek)

    Shift to target day-of-week from date within the week.

    Declaration
    public static DateTime DayOfWeekShift(this DateTime date, DayOfWeek target)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.DayOfWeek target

    Target for day-of-week.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Target day-of-week is always in the same week of the date.

    Examples
    var date = new DateTime(2018, 5, 2);                        // date.DayOfWeek = Wednesday
    
    var resultSun = date.DayOfWeekShift(DayOfWeek.Sunday);
    // resultSun = {4/29/2018 12:00:00 AM}
    
    var resultMon = date.DayOfWeekShift(DayOfWeek.Monday);
    // resultMon = {4/30/2018 12:00:00 AM}
    
    var resultTue = date.DayOfWeekShift(DayOfWeek.Tuesday);
    // resultTue = {5/1/2018 12:00:00 AM}
    
    var resultWed = date.DayOfWeekShift(DayOfWeek.Wednesday);
    // resultWed = {5/2/2018 12:00:00 AM}
    
    var resultThu = date.DayOfWeekShift(DayOfWeek.Thursday);
    // resultThu = {5/3/2018 12:00:00 AM}
    
    var resultFri = date.DayOfWeekShift(DayOfWeek.Friday);
    // resultFri = {4/4/2018 12:00:00 AM}
    
    var resultSat = date.DayOfWeekShift(DayOfWeek.Saturday);
    // resultSat = {5/5/2018 12:00:00 AM}
    | Improve this Doc View Source

    EventDatesBetween(String, Nullable<DateTime>, Nullable<DateTime>)

    Extension method that gets event dates between date ranges.

    Declaration
    public static ImmutableArray<DateTime> EventDatesBetween([CanBeNull] this string eventName, DateTime? date1 = default(DateTime? ), DateTime? date2 = default(DateTime? ))
    Parameters
    Type Name Description
    System.String eventName

    Name of the event.

    System.Nullable<System.DateTime> date1

    (Optional) The first date, DateTime.MinValue if null.

    System.Nullable<System.DateTime> date2

    (Optional) The second date, DateTime.MaxValue if null.

    Returns
    Type Description
    System.Collections.Immutable.ImmutableArray<System.DateTime>

    An ImmutableArray<DateTime>

    | Improve this Doc View Source

    EventDatesBetween(String, Nullable<Int32>, Nullable<Int32>)

    Extension method that gets event dates between date ranges.

    Declaration
    public static ImmutableArray<DateTime> EventDatesBetween([CanBeNull] this string eventName, int? year1, int? year2)
    Parameters
    Type Name Description
    System.String eventName

    Name of the event. This may be null.

    System.Nullable<System.Int32> year1

    (optional) The first year, DateTime.MinValue.Year if null.

    System.Nullable<System.Int32> year2

    (optional) The second year, DateTime.MaxValue.Year if null.

    Returns
    Type Description
    System.Collections.Immutable.ImmutableArray<System.DateTime>

    An ImmutableArray<DateTime>

    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown if either year1 or year2 are out of DateTime year min or max.

    | Improve this Doc View Source

    EventsOnDate(DateTime, Boolean, Boolean)

    A DateTime extension method that returns list of events on date.

    Declaration
    public static ImmutableArray<string> EventsOnDate(this DateTime date, bool includeWorkdays, bool includeDaysOff)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.Boolean includeWorkdays

    True to include, false to include workday events.

    System.Boolean includeDaysOff

    True to disable, false to include days off events.

    Returns
    Type Description
    System.Collections.Immutable.ImmutableArray<System.String>

    An ImmutableArray<string>

    Examples
    CalendarDateTime.AddYearlyDateEvent("myBirthday", true, 5, 20, false, false);
    var aDate = new DateTime(2018, 5, 20, 5, 30, 0);
    var events = aDate.EventsOnDate(true, true);
    // events = [0] = "myBirthday"
    | Improve this Doc View Source

    IsBetweenEqual(DateTime, DateTime, DateTime)

    A DateTime extension method returns true if date is between or equal date range.

    Declaration
    public static bool IsBetweenEqual(this DateTime date, DateTime date1, DateTime date2)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.DateTime date1

    The date 1 Date/Time.

    System.DateTime date2

    The date 2 Date/Time.

    Returns
    Type Description
    System.Boolean

    True if between equal, false if not.

    Remarks

    Order of date1 and date2 is unimportant.

    Examples
    var date1 = new DateTime(2012, 5, 4);
    var date2 = new DateTime(2020, 4, 1);
    var alpha = new DateTime(2018, 4, 4);
    var result = alpha.IsBetweenEqual(date1, date2);
    // true
    | Improve this Doc View Source

    IsDayOff(DateTime)

    A DateTime extension method that query if 'date' is day off. The days off is configured using the Add-calendar event methods.

    Declaration
    public static bool IsDayOff(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if day off, false if not.

    Examples
    // LINQ example.
    var starting = new DateTime(2018, 1, 1);
    var ending = new DateTime(2018, 12, 31);
    var allDates = Enumerable.Range(0, 1 + ending.Subtract(starting).Days).Select(i=> starting.AddDays(i));
    
    CalendarDateTime.AddYearlyDateEvent("theDate", true, 6, 10, false, false);
    var result = allDates.Where(d => d.IsDayOff());
    // result = [0] = {6/10/2018 12:00:00 AM}
    | Improve this Doc View Source

    IsFirstDayOfMonth(DateTime)

    A DateTime extension method that query if 'date' is first day of month.

    Declaration
    public static bool IsFirstDayOfMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if first day of month, false if not.

    Remarks

    Simple method, returns true if the date is the 1rst of the month. Provided for consistency.

    Examples
    var aDate = new DateTime(2018, 2, 1);
    var result = aDate.IsFirstDaDayOfMonth();
    // true
    | Improve this Doc View Source

    IsFirstWeekOfMonth(DateTime)

    A DateTime extension method that query if 'date' is first week of month.

    Declaration
    public static bool IsFirstWeekOfMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if first week of month, false if not.

    Remarks

    The first week is the first week that ends on Saturday, not always a full week.

    Examples
    var d = new DateTime(2018, 5, 29);
    var result = d.IsLastWeekOfMonth();
    // false
    | Improve this Doc View Source

    IsLastDayOfMonth(DateTime)

    A DateTime extension method that query if 'date' is last day of month.

    Declaration
    public static bool IsLastDayOfMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if last day of month, false if not.

    Examples
    var d = new DateTime(2018, 5, 31);
    var result = d.IsLastDayOfMonth();
    // true
    | Improve this Doc View Source

    IsLastWeekOfMonth(DateTime)

    A DateTime extension method that query if 'date' is last week of month.

    Declaration
    public static bool IsLastWeekOfMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if last week of month, false if not.

    Examples
    var d = new DateTime(2018, 5, 29);
    var result = d.IsLastWeekOfMonth();
    // true
    | Improve this Doc View Source

    IsLeapYear(DateTime)

    An int extension method that query if 'year' is leap year.

    Declaration
    public static bool IsLeapYear(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if leap year, false if not.

    Examples
    var result = CalendarDateTime.IsLeapYear(new DateTime(2018, 5, 5));
    // false
    | Improve this Doc View Source

    IsLeapYear(Int32)

    An int extension method that query if 'year' is leap year.

    Declaration
    public static bool IsLeapYear(this int year)
    Parameters
    Type Name Description
    System.Int32 year

    The year.

    Returns
    Type Description
    System.Boolean

    True if leap year, false if not.

    Examples
    var result = CalendarDateTime.IsLeapYear(2018);
    // false
    | Improve this Doc View Source

    IsNthDayOfWeek(DateTime, Int32, DayOfWeek)

    A DateTime extension method that query if 'date' is nth day-of-week.

    Declaration
    public static bool IsNthDayOfWeek(this DateTime date, int weekNumber, DayOfWeek dayOfWeek)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.Int32 weekNumber

    The week number.

    System.DayOfWeek dayOfWeek

    The day-of-week.

    Returns
    Type Description
    System.Boolean

    True if nth day of week, false if not.

    Remarks

    Example: true if the date is the 3rd Monday of the month.

    Examples
    var d = new DateTime(2018, 5, 21);
    var result = d.IsNthDayOfWeek(3, DayOfWeek.Monday);
    // true
    | Improve this Doc View Source

    IsWeekDay(DateTime)

    A DateTime extension method that query if 'date' is week day [Monday...Friday].

    Declaration
    public static bool IsWeekDay(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if week day, false if not.

    Examples
    var d = new DateTime(2018, 5, 21);
    var result = d.IsWeekDay();
    // true
    | Improve this Doc View Source

    IsWeekend(DateTime)

    A DateTime extension method that query if 'date' is weekend, [Saturday...Sunday].

    Declaration
    public static bool IsWeekend(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if weekend, false if not.

    Examples
    var d = new DateTime(2018, 5, 21);
    var result = d.IsWeekDay();
    // false
    | Improve this Doc View Source

    IsWorkDay(DateTime)

    A DateTime extension method that query if 'date' is work day. Workdays is configured by calendar Add- event methods.

    Declaration
    public static bool IsWorkDay(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Boolean

    True if work day, false if not.

    Examples
    // LINQ example.
    var starting = new DateTime(2018, 1, 1);
    var ending = new DateTime(2018, 12, 31);
    var allDates = Enumerable.Range(0, 1 + ending.Subtract(starting).Days).Select(i=> starting.AddDays(i));
    
    CalendarDateTime.AddYearlyDateEvent("theDate", true, 6, 10, false, false);
    var result = allDates.Where(d == d.IsWorkDay());
    // result = lots, except {6/10/2018 12:00:00 AM}
    | Improve this Doc View Source

    LastDateOfMonth(DateTime)

    Returns the last date of month.

    Declaration
    public static DateTime LastDateOfMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Examples
    var aDate = new DateTime(2018, 5, 3);
    var result = aDate.LastDateOfMonth();
    //	result = {5/31/2018 12:00:00 AM}
    | Improve this Doc View Source

    LastDateOfMonth(Int32, Int32)

    Returns the last date of month.

    Declaration
    public static DateTime LastDateOfMonth(int year, int month)
    Parameters
    Type Name Description
    System.Int32 year

    The year.

    System.Int32 month

    The month.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Examples
    var result = CalendarDateTime.LastDateOfMonth(2018, 5);
    //	result = {5/31/2018 12:00:00 AM}
    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown when year is out of DateTime.MinValue/MaxValue year. Month is less than 1 or greater than 12.

    | Improve this Doc View Source

    Quarter(DateTime)

    A DateTime extension method returns the date quarter count, i.e. [1, 2, 3, 4].

    Declaration
    public static int Quarter(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Int32

    An int.

    Examples
    var result = aDate.Quarter();
    //	result = 2
    | Improve this Doc View Source

    QuarterLong(DateTime)

    A DateTime extension method returns date quarter as 'Quarter n' where n is [1...4].

    Declaration
    [NotNull]
    public static string QuarterLong(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns as ["Quarter 1", "Quarter 2", "Quarter 3", "Quarter 4"].

    Examples
    var result = aDate.Quarter();
    //	result = Quarter 2
    | Improve this Doc View Source

    QuarterShort(DateTime)

    A DateTime extension method returns date quarter as 'Qn' where n is [1...4].

    Declaration
    [NotNull]
    public static string QuarterShort(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns as ["Q1", "Q2", "Q3", "Q4"].

    Examples
    var result = aDate.Quarter();
    //	result = Q2
    | Improve this Doc View Source

    RemoveEvent(String)

    Removes the event described by eventName.

    Declaration
    public static bool RemoveEvent([CanBeNull] string eventName)
    Parameters
    Type Name Description
    System.String eventName

    Name of the event. This may be null.

    Returns
    Type Description
    System.Boolean

    True if it succeeds, false if it fails.

    | Improve this Doc View Source

    RoundToHour(DateTime)

    A DateTime extension method that rounds to hour.

    Declaration
    public static DateTime RoundToHour(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Returns 4:36:45.1575 PM as 5:00:00.000 PM.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 13, 36, 45);
    var result = dateTime.RoundToHour();
    //	result = {5/21/2018 2:00:00 PM}
    | Improve this Doc View Source

    RoundToInterval(DateTime, TimeSpan)

    A DateTime extension method that rounds to TimeSpan interval./.

    Declaration
    public static DateTime RoundToInterval(this DateTime date, TimeSpan interval)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.TimeSpan interval

    The interval.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 23, 36, 47, 854);
    
    // Round to the day.
    var timeSpan = new TimeSpan(1, 0, 0, 0);
    
    var result = dateTime.RoundToInterval(timeSpan);
    //	result = {5/22/2018 12:00:00 AM}
    | Improve this Doc View Source

    RoundToMinute(DateTime)

    A DateTime extension method that rounds to minute.

    Declaration
    public static DateTime RoundToMinute(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Returns 4:36:45.6575 PM as 4:36:46.000 PM.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 13, 36, 47, 854);
    var result = dateTime.RoundToSecond();
    //	result = {5/21/2018 1:36:48 PM}
    | Improve this Doc View Source

    RoundToSecond(DateTime)

    A DateTime extension method that rounds to second.

    Declaration
    public static DateTime RoundToSecond(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Returns 4:36:45.857 PM as 16:36:46.000 PM.

    Examples
    var aDate = new DateTime(2018, 4, 12, 12, 30, 54, 825);
    var result = aDate.RoundToSecond();
    // result = {4/12/2018 12:30:55 PM}
    | Improve this Doc View Source

    TimeId(DateTime)

    A DateTime extension method that time identifier in HHmmssfff format. Typically used as Time key on tables.

    Declaration
    [NotNull]
    public static string TimeId(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns 4:36:45.157 PM as 163645157.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 23, 36, 47, 854);
    var result = dateTime.TimeId();
    //	result = "233647854"
    | Improve this Doc View Source

    TimeIdToHour(DateTime)

    A DateTime extension method that rounds time identifier to hour.

    Declaration
    [NotNull]
    public static string TimeIdToHour(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns 4:36:45.1575 PM as 170000000.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 10, 36, 47, 854);
    var result = dateTime.TimeIdToHour();
    //	result = "110000000"
    | Improve this Doc View Source

    TimeIdToInterval(DateTime, TimeSpan)

    A DateTime extension method that rounds time identifier to TimeSpan interval.

    Declaration
    [NotNull]
    public static string TimeIdToInterval(this DateTime date, TimeSpan interval)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.TimeSpan interval

    The interval.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Custom round off interval.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 10, 36, 47, 854);
    
    // 10 millisecond round off.
    var timeSpan = new TimeSpan(0, 0, 0, 0, 10);
    
    var result = dateTime.TimeIdToInterval(timeSpan);
    //	result = "103647850"
    | Improve this Doc View Source

    TimeIdToMinute(DateTime)

    A DateTime extension method that rounds time identifier to minute.

    Declaration
    [NotNull]
    public static string TimeIdToMinute(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns 4:36:45.6575 PM as 163700000.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 10, 36, 47, 854);
    var result = dateTime.TimeIdToMinute();
    //	result = "103700000"
    | Improve this Doc View Source

    TimeIdToSecond(DateTime)

    A DateTime extension method that rounds time identifier to second.

    Declaration
    [NotNull]
    public static string TimeIdToSecond(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.String

    A string. This will never be null.

    Remarks

    Returns 4:36:45.6575 PM as 163646000.

    Examples
    var dateTime = new DateTime(2018, 5, 21, 10, 36, 47, 854);
    var result = dateTime.TimeIdToSecond();
    //	result = "103648000"
    | Improve this Doc View Source

    WeekendAdjustDate(DateTime, Boolean, Boolean)

    A DateTime extension method that adjusts the date back if on Saturday or forward if on Sunday.

    Declaration
    public static DateTime WeekendAdjustDate(this DateTime date, bool saturdaysBack, bool sundaysForward)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    System.Boolean saturdaysBack

    True to adjust Saturday dates back to Friday.

    System.Boolean sundaysForward

    True to adjust Sundays dates forward to Monday.

    Returns
    Type Description
    System.DateTime

    A DateTime.

    Remarks

    Some events, such as New Years day is celebrated on Friday if on Saturday, or on Monday if on Sunday for example.

    Examples
    var aSaturday = new DateTime(2018, 5, 19);
    var aSunday = new DateTime(2018, 5, 20);
    
    var back = aSaturday.WeekendAdjustDate(true, false);
    // back = {5/18/2018 12:00:00 AM}
    
    var forward = aSunday.WeekendAdjustDate(true, true);
    // forward = {5/21/2018 12:00:00 AM}
    | Improve this Doc View Source

    WeekOfMonth(DateTime)

    A DateTime extension method that returns the date week of the month.

    Declaration
    public static int WeekOfMonth(this DateTime dateTime)
    Parameters
    Type Name Description
    System.DateTime dateTime

    The dateTime to act on.

    Returns
    Type Description
    System.Int32

    An int.

    Examples
    var aDate = new DateTime(2018, 5, 8);
    var result = aDate.WeekOfMonth();
    // result = 2
    | Improve this Doc View Source

    WeekOfYear(DateTime)

    A DateTime extension method that returns the date week of year.

    Declaration
    public static int WeekOfYear(this DateTime dateTime)
    Parameters
    Type Name Description
    System.DateTime dateTime

    The dateTime to act on.

    Returns
    Type Description
    System.Int32

    An int.

    Examples
    var aDate = new DateTime(2018, 5, 8);
    var result = aDate.WeekOfYear();
    // result = 19
    | Improve this Doc View Source

    WeeksInMonth(DateTime)

    Returns the number of weeks in month./.

    Declaration
    public static int WeeksInMonth(this DateTime date)
    Parameters
    Type Name Description
    System.DateTime date

    The date.

    Returns
    Type Description
    System.Int32

    An int.

    Remarks

    From first of the month, to the last day of the month integer days / 7.

    Examples
    var aDate = new DateTime(2018, 5, 8);
    var result = aDate.WeeksInMonth();
    // result = 4
    | Improve this Doc View Source

    WeeksInMonth(Int32, Int32)

    Returns the number of weeks in month./.

    Declaration
    public static int WeeksInMonth(int year, int month)
    Parameters
    Type Name Description
    System.Int32 year

    The year.

    System.Int32 month

    The month.

    Returns
    Type Description
    System.Int32

    An int.

    Remarks

    From first of the month, to the last day of the month integer days / 7.

    Examples
    var result = CalendarDateTime.WeeksInMonth(2018, 5);
    // result = result = 4
    Exceptions
    Type Condition
    System.ArgumentOutOfRangeException

    Thrown when year exceeds DateTime.MinValue.Year/DateTime.MaxValue.Year, or Month is less than 1 or greater than 12. the required range.

    • Improve this Doc
    • View Source
    Back to top Generated by DocFX