Exemple #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;
        }