|
| 1 | +import {expect} from "chai"; |
| 2 | +import {toString, toDateString, toTimeString} from "./DateUtils"; |
| 3 | + |
| 4 | +describe("DateUtils", () => { |
| 5 | + describe("toString", () => { |
| 6 | + it("should return the correct date and time string", () => { |
| 7 | + const date = new Date("2023-10-05T14:48:00"); |
| 8 | + const result = toString(date); |
| 9 | + // Fallback to a different locale check so we can run these tests on different machines |
| 10 | + try { |
| 11 | + expect(result).to.equal("5 Oct, 2023 14:48:00"); |
| 12 | + } catch (e) { |
| 13 | + expect(result).to.equal("5 Oct, 2023 2:48:00 PM"); |
| 14 | + } |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + describe("toDateString", () => { |
| 19 | + it("should return the correct date string", () => { |
| 20 | + const date = new Date("2023-10-05T14:48:00"); |
| 21 | + const result = toDateString(date); |
| 22 | + expect(result).to.equal("5 Oct, 2023"); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe("toTimeString", () => { |
| 27 | + it("should return the correct time string", () => { |
| 28 | + const date = new Date("2023-10-05T14:48:00"); |
| 29 | + const result = toTimeString(date); |
| 30 | + try { |
| 31 | + expect(result).to.equal("14:48:00"); |
| 32 | + } catch (e) { |
| 33 | + expect(result).to.equal("2:48:00 PM"); |
| 34 | + } |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments