/// <summary> /// Constructs an instance of <see cref="Day"/> from integer year, month and day numbers. /// </summary> /// <param name="year">The number of the year being constructed. Must be in the inclusive range 1 to 9998.</param> /// <param name="month">The number of the month of the year for the month being constructed, with 1 representing /// January, 2 February etc.</param> /// <param name="day">The day number of the month for the day being constructed. Must be in the inclusive range 1 to the /// number of days in the month.</param> /// <exception cref="ArgumentOutOfRangeException">Either the year, month or day parameters is outside of the range of permissible /// years or months respectively.</exception> public Day(int year, int month, int day) { // TODO if don't get rid of use of DateTime here then probably can get rid of these precondition checks as the DateTime constructor will perform the same checks Preconditions.CheckArgumentOutOfRange(nameof(year), year, Constants.MinCalendarYearNum, Constants.MaxCalendarYearNum); Preconditions.CheckArgumentOutOfRange(nameof(month), month, 1, 12); TimePeriodHelper.CheckDayOfMonth(nameof(day), year, month, day); // TODO need to create a method which calculates different in days which doesn't used DateTime var dateTime = new DateTime(year, month, day); _value = dateTime.Subtract(FirstDateTime).Days; }
public QuarterHour(int year, int month, int day, int hour, int minute) { // TODO if don't get rid of use of DateTime here then probably can get rid of these precondition checks as the DateTime constructor will perform the same checks Preconditions.CheckArgumentOutOfRange(nameof(year), year, Constants.MinCalendarYearNum, Constants.MaxCalendarYearNum); Preconditions.CheckArgumentOutOfRange(nameof(month), month, 1, 12); TimePeriodHelper.CheckDayOfMonth(nameof(day), year, month, day); Preconditions.CheckArgumentOutOfRange(nameof(hour), hour, 0, 23); if (minute != 0 && minute != 15 && minute != 30 && minute != 45) { throw new ArgumentException("minute argument value must equal either 0, 15, 30 or 45", nameof(minute)); } // TODO need to create a method which calculates different in days which doesn't used DateTime var dateTime = new DateTime(year, month, day, hour, minute, 0); _value = (int)dateTime.Subtract(FirstDateTime).TotalMinutes / 15; }
/// <summary> /// Expands the current instance into a collection of instances of a smaller time period type, which fit /// within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being expanded to.</typeparam> /// <returns>A collection of all instances of <typeparamref name="T"/> which fit within the <see cref="QuarterHour"/> /// represented by the current instance.</returns> public IEnumerable <T> Expand <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Expand <QuarterHour, T>(this)); }
/// <summary> /// Returns the last instance of time period type <typeparamref name="T"/> which sits within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being returns.</typeparam> /// <returns>The last instance of <typeparamref name="T"/> which sit within the <see cref="QuarterHour"/> /// represented by the current instance.</returns> public T Last <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Last <QuarterHour, T>(this)); }
/// <summary> /// Expands the current instance into a collection of instances of a smaller time period type, which fit /// within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being expanded to.</typeparam> /// <returns>A collection of all instances of <typeparamref name="T"/> which fit within the <see cref="Season"/> /// represented by the current instance.</returns> public IEnumerable <T> Expand <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Expand <Season, T>(this)); }
/// <summary> /// Returns the last instance of time period type <typeparamref name="T"/> which sits within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being returns.</typeparam> /// <returns>The last instance of <typeparamref name="T"/> which sit within the <see cref="Season"/> /// represented by the current instance.</returns> public T Last <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Last <Season, T>(this)); }
/// <summary> /// Returns the first instance of time period type <typeparamref name="T"/> which sits within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being returns.</typeparam> /// <returns>The first instance of <typeparamref name="T"/> which sit within the <see cref="Hour"/> /// represented by the current instance.</returns> public T First <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.First <Hour, T>(this)); }
/// <summary> /// Expands the current instance into a collection of instances of a smaller time period type, which fit /// within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being expanded to.</typeparam> /// <returns>A collection of all instances of <typeparamref name="T"/> which fit within the <see cref="CalendarYear"/> /// represented by the current instance.</returns> public IEnumerable <T> Expand <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Expand <CalendarYear, T>(this)); }
/// <summary> /// Returns the last instance of time period type <typeparamref name="T"/> which sits within the current instance. /// </summary> /// <typeparam name="T">The type of the time period being returns.</typeparam> /// <returns>The last instance of <typeparamref name="T"/> which sit within the <see cref="CalendarYear"/> /// represented by the current instance.</returns> public T Last <T>() where T : ITimePeriod <T> { return(TimePeriodHelper.Last <CalendarYear, T>(this)); }