Skip to content

Commit

Permalink
fix: fix year reset in interval calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
srg-kostyrko committed Dec 16, 2023
1 parent 25a7014 commit e944a8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
42 changes: 21 additions & 21 deletions src/interval-journal/interval-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ describe("IntervalManager", () => {
{
...deepCopy(DEFAULT_CONFIG_INTERVAL),
numeration_type: "year",
start_index: 2,
start_date: "2022-05-01",
start_index: 4,
start_date: "2023-11-01",
duration: 3,
granularity: "month",
},
Expand All @@ -357,51 +357,51 @@ describe("IntervalManager", () => {
});

test.each([
["start interval for start date", "2022-05-01", { index: 2, startDate: "2022-05-01", endDate: "2022-07-31" }],
["start interval for start date", "2023-11-01", { index: 4, startDate: "2023-11-01", endDate: "2024-01-31" }],
[
"start interval for date within start interval",
"2022-06-01",
{ index: 2, startDate: "2022-05-01", endDate: "2022-07-31" },
"2023-12-01",
{ index: 4, startDate: "2023-11-01", endDate: "2024-01-31" },
],
[
"start interval for interval end date",
"2022-07-31",
{ index: 2, startDate: "2022-05-01", endDate: "2022-07-31" },
"2024-01-31",
{ index: 4, startDate: "2023-11-01", endDate: "2024-01-31" },
],
[
"next interval after start interval",
"2022-08-01",
{ index: 3, startDate: "2022-08-01", endDate: "2022-10-31" },
"2024-03-01",
{ index: 1, startDate: "2024-02-01", endDate: "2024-04-30" },
],
[
"next interval with date in middle of interval",
"2022-08-10",
{ index: 3, startDate: "2022-08-01", endDate: "2022-10-31" },
"2024-05-10",
{ index: 2, startDate: "2024-05-01", endDate: "2024-07-31" },
],
[
"next interval for end date of interval",
"2022-10-31",
{ index: 3, startDate: "2022-08-01", endDate: "2022-10-31" },
"2024-04-30",
{ index: 1, startDate: "2024-02-01", endDate: "2024-04-30" },
],
[
"prev interval before start interval",
"2022-02-01",
{ index: 1, startDate: "2022-02-01", endDate: "2022-04-30" },
"2023-08-01",
{ index: 3, startDate: "2023-08-01", endDate: "2023-10-31" },
],
[
"prev interval with date in middle of interval",
"2022-03-10",
{ index: 1, startDate: "2022-02-01", endDate: "2022-04-30" },
"2023-09-01",
{ index: 3, startDate: "2023-08-01", endDate: "2023-10-31" },
],
[
"prev interval for end date of interval",
"2022-03-31",
{ index: 1, startDate: "2022-02-01", endDate: "2022-04-30" },
"2023-10-31",
{ index: 3, startDate: "2023-08-01", endDate: "2023-10-31" },
],
[
"interval in next year with index reset",
"2023-03-01",
{ index: 1, startDate: "2023-02-01", endDate: "2023-04-30" },
"2025-03-01",
{ index: 1, startDate: "2025-02-01", endDate: "2025-04-30" },
],
[
"interval in prev year with index reset",
Expand Down
2 changes: 1 addition & 1 deletion src/interval-journal/interval-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class IntervalManager {
private calculateIntervalAfterKnown(date: MomentDate, interval: Interval): Interval {
let curent = interval.endDate.clone().add(1, "day");
let index = interval.index + 1;
if (this.shouldResetYearly && !curent.isSame(interval.endDate, "year")) {
if (this.shouldResetYearly && !curent.isSame(interval.startDate, "year")) {
index = 1;
}
while (curent.isBefore(date, "day")) {
Expand Down

0 comments on commit e944a8a

Please sign in to comment.