Skip to content

Commit

Permalink
Set PQP to 1 month in advanced
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Jan 29, 2025
1 parent cdf9b34 commit 6b91866
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/lib/__tests__/getPqpRates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ describe("getPqpRates", () => {

it("should correctly calculate PQP rates for all vehicle categories", () => {
expect(getPqpRates(mockCoeData)).toEqual({
"2025-01": {
"2025-02": {
"Category A": 94513,
"Category B": 110537,
"Category C": 68481,
"Category D": 8457,
},
"2024-12": {
"2025-01": {
"Category A": 97747,
"Category B": 109164,
"Category C": 70912,
Expand All @@ -322,8 +322,8 @@ describe("getPqpRates", () => {
);
const result = getPqpRates(singleCategoryData);
expect(result).toEqual({
"2025-01": { "Category A": 94513 },
"2024-12": { "Category A": 97747 },
"2025-02": { "Category A": 94513 },
"2025-01": { "Category A": 97747 },
});
});

Expand Down
10 changes: 7 additions & 3 deletions src/lib/getPqpRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ const getPqpRates = (data: COE[]): Record<string, Record<string, number>> => {
);

return pqpResults.reduce((acc, { month, vehicle_class, pqp }) => {
if (!acc[month]) {
acc[month] = {};
const nextMonth = new Date(month);
nextMonth.setMonth(nextMonth.getMonth() + 1);
const nextMonthKey = nextMonth.toISOString().slice(0, 7);

if (!acc[nextMonthKey]) {
acc[nextMonthKey] = {};
}
acc[month][vehicle_class] = pqp;
acc[nextMonthKey][vehicle_class] = pqp;
return acc;
}, {});
};
Expand Down

0 comments on commit 6b91866

Please sign in to comment.