fix: sort stock and bond events by payment date
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isValidPeriod, moscowDate } from "./calendar";
|
||||
import { compareDateDesc, isValidPeriod, moscowDate } from "./calendar";
|
||||
import { calendarDate } from "./calendar.schema";
|
||||
|
||||
describe("calendar dates", () => {
|
||||
@@ -32,4 +32,22 @@ describe("calendar dates", () => {
|
||||
expect(moscowDate(new Date("2026-12-31T20:59:59Z"))).toBe("2026-12-31");
|
||||
expect(moscowDate(new Date("2026-12-31T21:00:00Z"))).toBe("2027-01-01");
|
||||
});
|
||||
|
||||
it("compares dates newest first and keeps dateless rows last", () => {
|
||||
const dates = [null, "2026-01-01", "2026-03-01", "2026-02-01"];
|
||||
|
||||
expect(dates.toSorted(compareDateDesc)).toEqual([
|
||||
"2026-03-01",
|
||||
"2026-02-01",
|
||||
"2026-01-01",
|
||||
null,
|
||||
]);
|
||||
|
||||
expect(dates.toSorted((a, b) => compareDateDesc(b, a))).toEqual([
|
||||
null,
|
||||
"2026-01-01",
|
||||
"2026-02-01",
|
||||
"2026-03-01",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user