Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Quarter#GetMonths #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jlmunozcu1984
Copy link

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.

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.
public ITimePeriodCollection GetMonths()
{
TimePeriodCollection months = new TimePeriodCollection();
YearMonth startMonth = YearBaseMonth;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion for line 98 and 99:

YearMonth startMonth;
TimeTool.AddMonth(startYear, YearBaseMonth, ((int)StartQuarter - 1) * TimeSpec.MonthsPerQuarter, out _, out startMonth);

@Giannoudis
Copy link
Owner

@jlmunozcu1984 You can add also the following unit tests:

QuarterTest.cs:

        // ----------------------------------------------------------------------
        [Trait("Category", "Quarter")]
        [Fact]
        public void QuarterGetMonthsTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            var q2 = new Quarter(currentYear, YearQuarter.Second);

            var months = q2.GetMonths();
            Assert.Equal(3, months.Count);
            Assert.Equal(months[0].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1));
            Assert.Equal(months[1].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1).AddMonths(1));
            Assert.Equal(months[2].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1).AddMonths(2));
        }

QuartersTest.cs:

         // ----------------------------------------------------------------------
        [Trait("Category", "Quarters")]
        [Fact]
        public void QuartersGetMonthsTest()
        {
            var currentYear = ClockProxy.Clock.Now.Year;

            var q2and3 = new Quarters(currentYear, YearQuarter.Second, 2);

            var months = q2and3.GetMonths();
            Assert.Equal(6, months.Count);
            Assert.Equal(months[0].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1));
            Assert.Equal(months[1].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1).AddMonths(1));
            Assert.Equal(months[2].Start, new DateTime(currentYear, TimeSpec.SecondQuarterMonthIndex, 1).AddMonths(2));
            Assert.Equal(months[3].Start, new DateTime(currentYear, TimeSpec.ThirdQuarterMonthIndex, 1));
            Assert.Equal(months[4].Start, new DateTime(currentYear, TimeSpec.ThirdQuarterMonthIndex, 1).AddMonths(1));
            Assert.Equal(months[5].Start, new DateTime(currentYear, TimeSpec.ThirdQuarterMonthIndex, 1).AddMonths(2));
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants