From 10a335001306f63d6992cdaf35f5af36618110fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mu=C3=B1oz=20Su=C3=A1rez?= Date: Fri, 12 Jul 2024 11:06:03 -0400 Subject: [PATCH] Error on Quarter#GetMonths Situation: All quarters GetMonths begin in January. Ej: var q2 = Quarter(2024,YearQuarter.Second); var april = q2.GetMonths().First(); /* Expected April but January returns. Same with Q3 and Q4, only Q1 works. --- TimePeriod/QuarterTimeRange.cs | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/TimePeriod/QuarterTimeRange.cs b/TimePeriod/QuarterTimeRange.cs index f7e427b..b8086a6 100644 --- a/TimePeriod/QuarterTimeRange.cs +++ b/TimePeriod/QuarterTimeRange.cs @@ -91,25 +91,28 @@ public string EndQuarterOfYearName get { return Calendar.GetQuarterOfYearName( EndYear, EndQuarter ); } } // EndQuarterOfYearName - // ---------------------------------------------------------------------- - public ITimePeriodCollection GetMonths() - { - TimePeriodCollection months = new TimePeriodCollection(); - for ( int i = 0; i < quarterCount; i++ ) - { - for ( int month = 0; month < TimeSpec.MonthsPerQuarter; month++ ) - { - int year; - YearMonth yearMonth; - TimeTool.AddMonth( startYear, YearBaseMonth, ( i * TimeSpec.MonthsPerQuarter ) + month, out year, out yearMonth ); - months.Add( new Month( year, yearMonth, Calendar ) ); - } - } - return months; - } // GetMonths - - // ---------------------------------------------------------------------- - protected override bool IsEqual( object obj ) + // ---------------------------------------------------------------------- + public ITimePeriodCollection GetMonths() + { + TimePeriodCollection months = new TimePeriodCollection(); + YearMonth startMonth = YearBaseMonth; + TimeTool.AddMonth( startYear, startMonth, (((int)StartQuarter) - 1) * TimeSpec.MonthsPerQuarter, out _, out startMonth ); + + for ( int i = 0; i < quarterCount; i++ ) + { + for ( int month = 0; month < TimeSpec.MonthsPerQuarter; month++ ) + { + int year; + YearMonth yearMonth; + TimeTool.AddMonth( startYear, startMonth, ( i * TimeSpec.MonthsPerQuarter ) + month, out year, out yearMonth ); + months.Add( new Month( year, yearMonth, Calendar ) ); + } + } + return months; + } // GetMonths + + // ---------------------------------------------------------------------- + protected override bool IsEqual( object obj ) { return base.IsEqual( obj ) && HasSameData( obj as QuarterTimeRange ); } // IsEqual