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

Unit Test for shiftDateRange #23324

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions test/common/datetime/shift_date_range.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, it, expect } from "vitest";
import { shiftDateRange } from "../../../src/common/datetime/calc_date";
import {
NumberFormat,
TimeFormat,
FirstWeekday,
DateFormat,
TimeZone,
} from "../../../src/data/translation";

const mockConfig = {
time_zone: "America/New_York",
};

describe("shiftDateRange", () => {
const locale = {
language: "en",
number_format: NumberFormat.language,
time_format: TimeFormat.language,
date_format: DateFormat.language,
time_zone: TimeZone.local,
first_weekday: FirstWeekday.language,
};

it("shifts date range forward month", () => {
const startDate = new Date(2024, 0, 1);
const endDate = new Date(2024, 0, 31);
const result = shiftDateRange(startDate, endDate, true, locale, mockConfig);
expect(result.start).toEqual(new Date(2024, 1, 1));
expect(result.end).toEqual(new Date(2024, 1, 29, 23, 59, 59, 999));
});

it("shifts date range backward month", () => {
const startDate = new Date(2025, 0, 1);
const endDate = new Date(2025, 0, 31);
const result = shiftDateRange(
startDate,
endDate,
false,
locale,
mockConfig
);
expect(result.start).toEqual(new Date(2024, 11, 1));
expect(result.end).toEqual(new Date(2024, 11, 31, 23, 59, 59, 999));
});

it("shifts date range forward day", () => {
const startDate = new Date(2025, 0, 1);
const endDate = new Date(new Date(2025, 0, 1, 23, 59, 59, 999));
const result = shiftDateRange(startDate, endDate, true, locale, mockConfig);
expect(result.start).toEqual(new Date(2025, 0, 2));
expect(result.end).toEqual(new Date(2025, 0, 2, 23, 59, 59, 999));
});

it("shifts date range backward day", () => {
const startDate = new Date(2025, 0, 2);
const endDate = new Date(new Date(2025, 0, 2, 23, 59, 59, 999));
const result = shiftDateRange(
startDate,
endDate,
false,
locale,
mockConfig
);
expect(result.start).toEqual(new Date(2025, 0, 1));
expect(result.end).toEqual(new Date(2025, 0, 1, 23, 59, 59, 999));
});
});
Loading