/// <summary>
        /// Converts the specified quarter to a string representation of it's ordinal indicator
        /// (i.e. "1st", "2nd", "3rd", or "4th").
        /// </summary>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <returns>
        /// A string representation of the specified quarter number's ordinal indicator.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        public static string ToOrdinalIndicator(
            this QuarterNumber quarterNumber)
        {
            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(quarterNumber)}' == '{QuarterNumber.Invalid}'"), (Exception)null);
            }

            string result;

            switch ((int)quarterNumber)
            {
            case 1:
                result = "1st";
                break;

            case 2:
                result = "2nd";
                break;

            case 3:
                result = "3rd";
                break;

            case 4:
                result = "4th";
                break;

            default:
                throw new NotSupportedException("This quarter is not supported: " + quarterNumber);
            }

            return(result);
        }
        public FiscalQuarter DeepCloneWithQuarterNumber(QuarterNumber quarterNumber)
        {
            var result = new FiscalQuarter(
                this.Year.DeepClone(),
                quarterNumber);

            return(result);
        }
        public CalendarQuarter DeepCloneWithQuarterNumber(QuarterNumber quarterNumber)
        {
            var result = new CalendarQuarter(
                this.Year.DeepClone(),
                quarterNumber);

            return(result);
        }
예제 #4
0
        public GenericQuarter DeepCloneWithQuarterNumber(QuarterNumber quarterNumber)
        {
            var result = new GenericQuarter(
                this.Year.DeepClone(),
                quarterNumber);

            return(result);
        }
        /// <summary>
        /// Constructs a <see cref="GenericQuarter"/> from a <see cref="QuarterNumber"/> and a year.
        /// </summary>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <param name="year">The year.</param>
        /// <returns>
        /// The <see cref="GenericQuarter"/>.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        public static GenericQuarter ToGeneric(
            this QuarterNumber quarterNumber,
            int year)
        {
            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(quarterNumber)}' == '{QuarterNumber.Invalid}'"), (Exception)null);
            }

            var result = new GenericQuarter(year, quarterNumber);

            return(result);
        }
예제 #6
0
        /// <summary>
        /// Constructs a generic quarter from a <see cref="QuarterNumber"/> and a year.
        /// </summary>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <param name="year">The year.</param>
        /// <returns>
        /// A generic quarter constructed from the specified <see cref="QuarterNumber"/> and year.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        public static GenericQuarter ToGeneric(
            this QuarterNumber quarterNumber,
            int year)
        {
            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentException(Invariant($"{nameof(quarterNumber)} is {nameof(QuarterNumber.Invalid)}"));
            }

            var result = new GenericQuarter(year, quarterNumber);

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FiscalQuarter"/> class.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="year"/> is less than 1 or greater than 9999.</exception>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is invalid.</exception>
        public FiscalQuarter(
            int year,
            QuarterNumber quarterNumber)
        {
            if ((year < 1) || (year > 9999))
            {
                throw new ArgumentOutOfRangeException(nameof(year), Invariant($"year ({year}) is less than 1 or greater than 9999"));
            }

            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentException("quarter is invalid", nameof(quarterNumber));
            }

            this.Year          = year;
            this.QuarterNumber = quarterNumber;
        }
        /// <summary>
        /// Converts a <see cref="FiscalQuarter"/> to a <see cref="CalendarQuarter"/>.
        /// </summary>
        /// <param name="calendarQuarter">The calendar quarter to convert.</param>
        /// <param name="calendarQuarterThatIsFirstFiscalQuarter">The calendar quarter that is associated with the first fiscal quarter for the company.</param>
        /// <returns>
        /// The fiscal quarter associated with the specified calendar quarter.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="calendarQuarter"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="calendarQuarterThatIsFirstFiscalQuarter"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        public static FiscalQuarter ToFiscalQuarter(
            this CalendarQuarter calendarQuarter,
            QuarterNumber calendarQuarterThatIsFirstFiscalQuarter)
        {
            if (calendarQuarter == null)
            {
                throw new ArgumentNullException(nameof(calendarQuarter));
            }

            if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(calendarQuarterThatIsFirstFiscalQuarter)}' == '{QuarterNumber.Invalid}'"), (Exception)null);
            }

            int offset;

            if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q4)
            {
                offset = 1;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q3)
            {
                offset = 2;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q2)
            {
                offset = 3;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q1)
            {
                offset = 0;
            }
            else
            {
                throw new NotSupportedException("This quarter number is not supported: " + calendarQuarterThatIsFirstFiscalQuarter);
            }

            var result = new FiscalQuarter(calendarQuarter.Year, calendarQuarter.QuarterNumber);

            result = result.Plus(offset);

            return(result);
        }
예제 #9
0
        /// <summary>
        /// Converts a <see cref="FiscalQuarter"/> to a <see cref="CalendarQuarter"/>.
        /// </summary>
        /// <param name="calendarQuarter">The calendar quarter to convert.</param>
        /// <param name="calendarQuarterThatIsFirstFiscalQuarter">The calendar quarter that is associated with the first fiscal quarter for the company.</param>
        /// <returns>
        /// The fiscal quarter associated with the specified calendar quarter.
        /// </returns>
        /// <exception cref="ArgumentNullException"><paramref name="calendarQuarter"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="calendarQuarterThatIsFirstFiscalQuarter"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        public static FiscalQuarter ToFiscalQuarter(
            this CalendarQuarter calendarQuarter,
            QuarterNumber calendarQuarterThatIsFirstFiscalQuarter)
        {
            if (calendarQuarter == null)
            {
                throw new ArgumentNullException(nameof(calendarQuarter));
            }

            if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Invalid)
            {
                throw new ArgumentException("calendar quarter that is first fiscal quarter is Invalid.", nameof(calendarQuarterThatIsFirstFiscalQuarter));
            }

            int offset;

            if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q4)
            {
                offset = 1;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q3)
            {
                offset = 2;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q2)
            {
                offset = 3;
            }
            else if (calendarQuarterThatIsFirstFiscalQuarter == QuarterNumber.Q1)
            {
                offset = 0;
            }
            else
            {
                throw new NotSupportedException("This quarter number is not supported: " + calendarQuarterThatIsFirstFiscalQuarter);
            }

            var fiscalQuarter = new FiscalQuarter(calendarQuarter.Year, calendarQuarter.QuarterNumber);

            fiscalQuarter = fiscalQuarter.Plus(offset);
            return(fiscalQuarter);
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarQuarter"/> class.
        /// </summary>
        /// <param name="year">The year.</param>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="year"/> is less than 1 or greater than 9999.</exception>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is invalid.</exception>
        public CalendarQuarter(
            int year,
            QuarterNumber quarterNumber)
        {
            if (year < 1)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(year)}' < '{1}'"), (Exception)null);
            }

            if (year > 9999)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(year)}' > '{9999}'"), (Exception)null);
            }

            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(quarterNumber)}' == '{QuarterNumber.Invalid}'"), (Exception)null);
            }

            this.Year          = year;
            this.QuarterNumber = quarterNumber;
        }
        /// <summary>
        /// Constructs a <see cref="UnitOfTime"/> whose <see cref="UnitOfTimeGranularity"/> is <see cref="UnitOfTimeGranularity.Quarter"/>
        /// from a <see cref="QuarterNumber"/>, year, and <see cref="UnitOfTimeKind"/>.
        /// </summary>
        /// <param name="quarterNumber">The quarter number.</param>
        /// <param name="year">The year.</param>
        /// <param name="unitOfTimeKind">The unit-of-time kind.</param>
        /// <returns>
        /// The <see cref="UnitOfTime"/>.
        /// </returns>
        /// <exception cref="ArgumentException"><paramref name="quarterNumber"/> is <see cref="QuarterNumber.Invalid"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="unitOfTimeKind"/> is <see cref="UnitOfTimeKind.Invalid"/>.</exception>
        public static UnitOfTime ToUnitOfTime(
            this QuarterNumber quarterNumber,
            int year,
            UnitOfTimeKind unitOfTimeKind)
        {
            if (quarterNumber == QuarterNumber.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(quarterNumber)}' == '{QuarterNumber.Invalid}'"), (Exception)null);
            }

            if (unitOfTimeKind == UnitOfTimeKind.Invalid)
            {
                throw new ArgumentOutOfRangeException(Invariant($"'{nameof(unitOfTimeKind)}' == '{UnitOfTimeKind.Invalid}'"), (Exception)null);
            }

            UnitOfTime result;

            switch (unitOfTimeKind)
            {
            case UnitOfTimeKind.Calendar:
                result = quarterNumber.ToCalendar(year);
                break;

            case UnitOfTimeKind.Fiscal:
                result = quarterNumber.ToFiscal(year);
                break;

            case UnitOfTimeKind.Generic:
                result = quarterNumber.ToGeneric(year);
                break;

            default:
                throw new NotSupportedException(Invariant($"This {nameof(UnitOfTimeKind)} is not supported: {unitOfTimeKind}"));
            }

            return(result);
        }
예제 #12
0
 public Quarter(int number, Score homeScore, Score awayScore)
 {
     Number    = (QuarterNumber)number;
     HomeScore = homeScore;
     AwayScore = awayScore;
 }