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

relativeDateToDateRange test fails for 'month' with days < current month days #761

Open
tannerjt opened this issue Mar 30, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@tannerjt
Copy link
Contributor

For utils.test.ts, expect(m).toBeLessThan(curMonth); test fails on occasion:

it("converts months", () => {
const rd: IRelativeDate = {
type: "relative-date",
num: 1,
unit: "months",
};
const chk = relativeDateToDateRange(rd);
expect(chk.from).toBeLessThan(chk.to);
const m = new Date(chk.from).getMonth();
const curMonth = new Date().getMonth();
// Account for January/December
if (curMonth > 0) {
expect(m).toBeLessThan(curMonth);
} else {
expect(m).toBe(11);
}
});

I believe the reason is because it is attempting to get the number of days in the current month and apply that to the from month. I tried to run this test today March 30 and attempting to get a 1 month range returns March 02 (since there are 28 days in February in 2022).

Here is the where we are subtracting relative.num the current month:

case "months":
// get the current month and subtract num
now.setMonth(now.getMonth() - relative.num);
result.from = now.getTime();
break;

I think we can either update the test to also check for equality expect(m).toBeLessThanOrEqual(curMonth), or adjust relativeDateToRange to roll to previous month in these edge cases.

@tannerjt tannerjt added the bug Something isn't working label Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant