Ejemplo n.º 1
0
        public static List <string> CalculateYearRanges(IEnumerable <int> years)
        {
            var yearsInOrder = years.Distinct().OrderBy(x => x).ToList();

            if (!yearsInOrder.Any())
            {
                return(new List <string>());
            }

            return(yearsInOrder
                   .Select((n, i) => new { number = n, group = n - i })
                   .GroupBy(n => n.@group)
                   .Select(g =>
                           g.Count() >= 2
                        ? MultiTenantHelpers.FormatReportingYear(g.First().number) + "-" + MultiTenantHelpers.FormatReportingYear(g.Last().number)
                        : String.Join(", ", g.Select(x => MultiTenantHelpers.FormatReportingYear(x.number)))
                           )
                   .ToList());
        }
Ejemplo n.º 2
0
        public static DateTime LastReportingPeriodStartDate()
        {
            var startDayOfReportingPeriod = MultiTenantHelpers.GetStartDayOfReportingPeriod();

            return(new DateTime(CalculateCurrentYearToUseForRequiredReporting(), startDayOfReportingPeriod.Month, startDayOfReportingPeriod.Day));
        }
        public void CalculateCalendarYearRangeAccountingForExistingYearsWithCeilingOfCurrentYearToUseTest()
        {
            // Test empty list: should return just current year
            var currentYearToUse = DateTime.Today.Year;
            var ceilingYear      = currentYearToUse;

            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), null, null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), Is.EquivalentTo(Enumerable.Range(currentYearToUse, 1)));

            // Test GetRangeOfYears with same year twice; should return just the one year
            Assert.That(FirmaDateUtilities.GetRangeOfYears(currentYearToUse, currentYearToUse).Count == 1);
            // Test inverted range; should throw
            Assert.Throws <ArgumentOutOfRangeException>(() => FirmaDateUtilities.GetRangeOfYears(currentYearToUse, currentYearToUse - 1));

            // No existing budget records

            // Testing if only have a start year
            // -- Start Year in the past: should go from Start Year to Current Year
            var startYear = currentYearToUse - 2;

            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, currentYearToUse)));
            // -- Start Year same as current year: should just be Start Year
            startYear = currentYearToUse;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, startYear)));
            // -- Start Year in the future: should just be the ceiling year
            startYear = currentYearToUse + 3;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(ceilingYear, ceilingYear)));

            // Testing if only have a completion year
            var completionYear = currentYearToUse - 2;

            // -- Completion Year in the past or same as current year, should only show Completion Year
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), null, completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(completionYear, completionYear)));
            completionYear = currentYearToUse;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), null, completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(completionYear, completionYear)));
            // -- Completion Year in the future: should be the ceiling year
            completionYear = currentYearToUse + 3;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), null, completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(ceilingYear, ceilingYear)));

            // Testing if have both Start Year and Completion Year: should always be Start Year to Completion Year
            // -- Start Year in the past
            startYear = currentYearToUse - 2;
            // -- Completion year in the past
            completionYear = currentYearToUse - 1;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, completionYear)));
            // -- Completion year same as current year
            completionYear = currentYearToUse;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, completionYear)));
            // -- Completion year in future, should only go up to the ceiling year
            completionYear = startYear + 5;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, ceilingYear)));

            // -- Start Year same as current year
            startYear = currentYearToUse;
            // -- Completion year in the past; should throw since that cannot happen!
            completionYear = currentYearToUse - 1;
            Assert.Throws <PreconditionException>(() => FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), "Cannot have a start year > end year!");
            // -- Completion year same as current year
            completionYear = currentYearToUse;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, completionYear)));
            // -- Completion year in future
            completionYear = startYear + 5;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(startYear, ceilingYear)));

            // -- Start Year in the future
            startYear = currentYearToUse + 2;
            // -- Completion year in the past; should throw since that cannot happen!
            completionYear = currentYearToUse - 1;
            Assert.Throws <PreconditionException>(() => FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), "Cannot have a start year > end year!");
            // -- Completion year same as current year
            completionYear = currentYearToUse;
            Assert.Throws <PreconditionException>(() => FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear), "Cannot have a start year > end year!");
            // -- Completion year in future
            completionYear = startYear + 5;
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int>(), new DateTime(startYear, 1, 1), completionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(ceilingYear, ceilingYear)));

            // If we have existing budget records, we need to factor those in
            var yearBeforeCurrentYear = currentYearToUse - 2;
            var yearAfterCurrentYear  = currentYearToUse + 4;

            // no start year and no end year provided
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear
            }, null, null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, currentYearToUse)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear, yearAfterCurrentYear
            }, null, null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, yearAfterCurrentYear)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearAfterCurrentYear
            }, null, null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(currentYearToUse, yearAfterCurrentYear)));
            // start year provided
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear
            }, new DateTime(currentYearToUse, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, currentYearToUse)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear, yearAfterCurrentYear
            }, new DateTime(currentYearToUse, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, yearAfterCurrentYear)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearAfterCurrentYear
            }, new DateTime(currentYearToUse, 1, 1), null, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(currentYearToUse, yearAfterCurrentYear)));
            // end year provided
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear
            }, null, currentYearToUse, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, currentYearToUse)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear, yearAfterCurrentYear
            }, null, currentYearToUse, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, yearAfterCurrentYear)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearAfterCurrentYear
            }, null, currentYearToUse, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(currentYearToUse, yearAfterCurrentYear)));
            // start year and end year provided
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear
            }, new DateTime(currentYearToUse - 1, 1, 1), currentYearToUse + 1, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, ceilingYear)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearBeforeCurrentYear, yearAfterCurrentYear
            }, new DateTime(currentYearToUse - 1, 1, 1), currentYearToUse + 1, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(yearBeforeCurrentYear, yearAfterCurrentYear)));
            Assert.That(FirmaDateUtilities.CalculateCalendarYearRangeAccountingForExistingYears(new List <int> {
                yearAfterCurrentYear
            }, new DateTime(currentYearToUse - 1, 1, 1), currentYearToUse + 1, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), ceilingYear),
                        Is.EquivalentTo(FirmaDateUtilities.GetRangeOfYears(currentYearToUse - 1, yearAfterCurrentYear)));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Range of Years for user input, using MinimumYearForReporting and DateTime.Now.Year
 /// </summary>
 /// <returns></returns>
 public static List <CalendarYearString> ReportingYearsForUserInput()
 {
     return(GetRangeOfYears(MultiTenantHelpers.GetMinimumYear(), CalculateCurrentYearToUseForUpToAllowableInputInReporting()).Select(x => new CalendarYearString(x)).ToList());
 }
Ejemplo n.º 5
0
 public static List <int> ReportingYearsForUserInputAsIntegers()
 {
     return(GetRangeOfYears(MultiTenantHelpers.GetMinimumYear(),
                            CalculateCurrentYearToUseForUpToAllowableInputInReporting()));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Range of Years for user input, using MinimumYear and MaximumYearforUserInput
 /// </summary>
 /// <returns></returns>
 public static List <CalendarYearString> YearsForUserInput()
 {
     return(GetRangeOfYears(MultiTenantHelpers.GetMinimumYear(), DateTime.Now.Year + YearsBeyondPresentForMaximumYearForUserInput).Select(x => new CalendarYearString(x)).ToList());
 }
Ejemplo n.º 7
0
 public static List <int> GetRangeOfYearsForReporting()
 {
     return(GetRangeOfYears(MultiTenantHelpers.GetMinimumYear(), CalculateCurrentYearToUseForRequiredReporting()));
 }
Ejemplo n.º 8
0
 public static bool DateIsInReportingRange(int calendarYear)
 {
     return(calendarYear > MultiTenantHelpers.GetMinimumYear() && calendarYear <= CalculateCurrentYearToUseForRequiredReporting());
 }
Ejemplo n.º 9
0
 public static List <int> CalculateCalendarYearRangeForExpendituresAccountingForExistingYears(List <int> existingYears, IProject project, int currentYearToUse)
 {
     return(CalculateCalendarYearRangeAccountingForExistingYears(existingYears, project?.PlanningDesignStartYear, project?.CompletionYear, currentYearToUse, MultiTenantHelpers.GetMinimumYear(), currentYearToUse));
 }
Ejemplo n.º 10
0
        public static int CalculateCurrentYearToUseForRequiredReporting()
        {
            var startDayOfReportingPeriod = MultiTenantHelpers.GetStartDayOfReportingPeriod();

            return(CalculateCurrentYearToUseForReportingImpl(DateTime.Today, startDayOfReportingPeriod.Month, startDayOfReportingPeriod.Day));
        }