From e9c57c811f7d4e1029bbc11f573840b051908a2a Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Thu, 19 Jan 2023 12:20:03 +0100 Subject: [PATCH] update test, set fix timezone --- ui/src/app/components/datetime/DateTime.js | 7 +++++-- ui/src/app/components/datetime/DateTime.test.js | 13 +++++++++++++ ui/src/app/components/datetime/time.test.js | 12 ++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 ui/src/app/components/datetime/DateTime.test.js create mode 100644 ui/src/app/components/datetime/time.test.js diff --git a/ui/src/app/components/datetime/DateTime.js b/ui/src/app/components/datetime/DateTime.js index 3ce2644..c0b2613 100644 --- a/ui/src/app/components/datetime/DateTime.js +++ b/ui/src/app/components/datetime/DateTime.js @@ -9,8 +9,11 @@ import { parseServerTime } /** * DateTime formats the provided datetime */ -const DateTime = ({value, format="LLLL"}) => { - const time = parseServerTime(value); +const DateTime = ({value, format="LLLL", utc=false}) => { + let time = parseServerTime(value); + if (utc) { + time = time.utc(); + } return (<>{time.format(format)}); } diff --git a/ui/src/app/components/datetime/DateTime.test.js b/ui/src/app/components/datetime/DateTime.test.js new file mode 100644 index 0000000..e3ac86e --- /dev/null +++ b/ui/src/app/components/datetime/DateTime.test.js @@ -0,0 +1,13 @@ +import {render, screen} from '@testing-library/react'; +import moment from 'moment'; + +import DateTime from 'app/components/datetime/DateTime'; + + +test("render a parsed server time as date time", () => { + const t = "2022-05-06T23:42:11.123Z"; + render(

); + + const result = screen.getByTestId("result"); + expect(result.innerHTML).toBe("Friday, May 6, 2022 11:42 PM"); +}); diff --git a/ui/src/app/components/datetime/time.test.js b/ui/src/app/components/datetime/time.test.js new file mode 100644 index 0000000..a09dff7 --- /dev/null +++ b/ui/src/app/components/datetime/time.test.js @@ -0,0 +1,12 @@ + +import {parseServerTime} from 'app/components/datetime/time'; + +test("parse server time", () => { + const t = "2023-10-24T23:42:11.3333333333Z"; + const result = parseServerTime(t).utc(); + expect(result).not.toBe(null); + + expect(result.month()).toBe(9); + expect(result.year()).toBe(2023); + expect(result.date()).toBe(24); +});