Example #1
0
        /// <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;
        }
Example #3
0
 public Quarter(int year, int quarter)
 {
     Preconditions.CheckArgumentOutOfRange(nameof(year), year, Constants.MinCalendarYearNum, Constants.MaxCalendarYearNum);
     Preconditions.CheckArgumentOutOfRange(nameof(quarter), quarter, 1, 4);
     _value = (year - 1) * 4 + quarter - 1;
 }
Example #4
0
 /// <summary>
 /// Constructs an instance of <see cref="Month"/> by directly setting the private integer _value field.
 /// </summary>
 /// <param name="value">Integer value to assign to private _value field.</param>
 private Month(int value)
 {
     Preconditions.CheckArgumentOutOfRange(nameof(value), value, MinValue, MaxValue);
     _value = value;
 }
Example #5
0
 /// <summary>
 /// Constructs an instance of <see cref="Month"/> from integer year and month 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>
 /// <exception cref="ArgumentOutOfRangeException">Either the year or month parameters is outside of the range of permissible
 /// years or months respectively.</exception>
 public Month(int year, int month)
 {
     Preconditions.CheckArgumentOutOfRange(nameof(year), year, Constants.MinCalendarYearNum, Constants.MaxCalendarYearNum);
     Preconditions.CheckArgumentOutOfRange(nameof(month), month, 1, 12);
     _value = (year - 1) * 12 + month - 1;
 }
        private ushort             _value; // Not readonly to avoid defensive copying (see https://blog.nodatime.org/2014/07/micro-optimization-surprising.html)
        #endregion Fields

        #region Constructors
        /// <summary>
        /// Constructs an instance of <see cref="CalendarYear"/> from an integer year number.
        /// </summary>
        /// <param name="year">The number of the year being constructed. Must be in the inclusive range 1 to 9998.</param>
        /// <exception cref="ArgumentOutOfRangeException">The year parameter is outside of the range of permissible years.</exception>
        public CalendarYear(int year)
        {
            Preconditions.CheckArgumentOutOfRange(nameof(year), year, Constants.MinCalendarYearNum, Constants.MaxCalendarYearNum);
            _value = (ushort)(year - 1);
        }