private static FiscalMonth TweakBy(
            this FiscalMonth fiscalMonth,
            int amount,
            FiscalMonthComponent componentToTweak)
        {
            if (componentToTweak == FiscalMonthComponent.Month)
            {
                var referenceMonth = new DateTime(fiscalMonth.Year, (int)fiscalMonth.MonthNumber, 1);

                var updatedMonth = referenceMonth.AddMonths(amount);

                var result = new FiscalMonth(updatedMonth.Year, (MonthNumber)updatedMonth.Month);

                return(result);
            }

            if (componentToTweak == FiscalMonthComponent.Year)
            {
                var result = new FiscalMonth(fiscalMonth.Year + amount, fiscalMonth.MonthNumber);

                return(result);
            }

            throw new NotSupportedException("this fiscal month component is not supported: " + componentToTweak);
        }
Example #2
0
        private static FiscalMonth TweakComponentOfFiscalMonth(this FiscalMonth fiscalMonth, FiscalMonthComponent componentToTweak)
        {
            if (componentToTweak == FiscalMonthComponent.Month)
            {
                var tweakedMonth = A.Dummy <MonthNumber>().ThatIsNot(fiscalMonth.MonthNumber);
                var result       = new FiscalMonth(fiscalMonth.Year, tweakedMonth);
                return(result);
            }

            if (componentToTweak == FiscalMonthComponent.Year)
            {
                var tweakedYear = A.Dummy <PositiveInteger>().ThatIs(y => y != fiscalMonth.Year && y <= 9999);
                var result      = new FiscalMonth(tweakedYear, fiscalMonth.MonthNumber);
                return(result);
            }

            throw new NotSupportedException("this fiscal month component is not supported: " + componentToTweak);
        }