1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2024-10-04 12:14:19 +02:00
foris-js/src/utils/__tests__/datetime.test.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-02-20 14:30:28 +01:00
/*
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
import { toLocaleDateString } from "../datetime";
describe("toLocaleDateString", () => {
it("should work with different locale", () => {
global.ForisTranslations = { locale: "fr" };
2020-08-18 15:39:00 +02:00
expect(toLocaleDateString("2020-02-20T12:51:36+00:00")).toBe(
"20 février 2020 12:51"
);
2020-02-20 14:30:28 +01:00
global.ForisTranslations = { locale: "en" };
2020-08-18 15:39:00 +02:00
});
2020-02-20 14:30:28 +01:00
it("should convert with default format", () => {
2020-08-18 15:39:00 +02:00
expect(toLocaleDateString("2020-02-20T12:51:36+00:00")).toBe(
"February 20, 2020 12:51 PM"
);
2020-02-20 14:30:28 +01:00
});
it("should convert with custom input format", () => {
expect(
2020-08-18 15:39:00 +02:00
toLocaleDateString("2020-02-20 12:51:36 +0000", {
inputFormat: "YYYY-MM-DD HH:mm:ss Z",
})
2020-02-20 14:30:28 +01:00
).toBe("February 20, 2020 12:51 PM");
});
it("should convert with custom output format", () => {
expect(
2020-08-18 15:39:00 +02:00
toLocaleDateString("2020-02-20T12:51:36+00:00", {
outputFormat: "LL",
})
2020-02-20 14:30:28 +01:00
).toBe("February 20, 2020");
});
it("should convert with custom input and output format", () => {
expect(
2020-08-18 15:39:00 +02:00
toLocaleDateString("2020-02-20 12:51:36 +0000", {
inputFormat: "YYYY-MM-DD HH:mm:ss Z",
outputFormat: "LL",
})
2020-02-20 14:30:28 +01:00
).toBe("February 20, 2020");
});
});