import DateUtil from "./DateUtil";

describe("DateUtil", () => {
  it("isDateInRangeIgnoringYear", () => {
    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2020, 5, 30),
        new Date(2020, 0, 31),
        new Date(2020, 11, 31),
      ),
    ).toBeTruthy();
    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2020, 1, 32),
        new Date(2020, 10, 31),
        new Date(2020, 6, 30),
      ),
    ).toBeTruthy();
    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2020, 10, 1),
        new Date(2020, 10, 1),
        new Date(2020, 6, 30),
      ),
    ).toBeTruthy();

    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2020, 10, 30),
        new Date(2020, 10, 31),
        new Date(2020, 6, 30),
      ),
    ).toBeFalsy();
    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2020, 6, 16),
        new Date(2020, 10, 31),
        new Date(2020, 6, 15),
      ),
    ).toBeFalsy();
    expect(
      DateUtil.isDateInRangeIgnoringYear(
        new Date(2023, 6, 14),
        new Date(2020, 10, 31),
        new Date(2020, 6, 15),
      ),
    ).toBeTruthy();
  });

  it("getDateWithSubtractedDays", () => {
    expect(
      DateUtil.getDateWithSubtractedDays(
        new Date("2024-01-15T10:30:00.000Z"),
        3,
      ).toISOString(),
    ).toEqual("2024-01-12T10:30:00.000Z");

    expect(
      DateUtil.getDateWithSubtractedDays(
        new Date("2024-01-15T10:30:00.000Z"),
        0,
      ).toISOString(),
    ).toEqual("2024-01-15T10:30:00.000Z");
  });

  it("getDaysBetweenDates", () => {
    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/01/01"),
        new Date("2024/01/01"),
      ),
    ).toEqual(0);
    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/01/01"),
        new Date("2024/01/02"),
      ),
    ).toEqual(1);
    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/01/01"),
        new Date("2024/02/01"),
      ),
    ).toEqual(31);
    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/01/01"),
        new Date("2024/12/31"),
      ),
    ).toEqual(365);

    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/01/01"),
        new Date("2025/01/01"),
      ),
    ).toEqual(366); // 2024 is a leap year
    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2025/01/01"),
        new Date("2026/01/01"),
      ),
    ).toEqual(365); // 2025 is not a leap year

    expect(
      DateUtil.getDaysBetweenDates(
        new Date("2024/06/15"),
        new Date("2024/12/25"),
      ),
    ).toEqual(193);
  });

  it("getDate", () => {
    expect(DateUtil.getDate("2024-10-10")?.toISOString()).toEqual(
      "2024-10-10T00:00:00.000Z",
    );
    expect(DateUtil.getDate(null)).toEqual(null);
    expect(
      DateUtil.getDate(new Date(2024, 9, 11, 0, 0, 0))?.toISOString(),
    ).toEqual("2024-10-10T21:00:00.000Z");
  });
});
