update test, set fix timezone
This commit is contained in:
parent
9f3b8d6399
commit
e9c57c811f
@ -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)}</>);
|
||||
}
|
||||
|
||||
|
13
ui/src/app/components/datetime/DateTime.test.js
Normal file
13
ui/src/app/components/datetime/DateTime.test.js
Normal file
@ -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(<p data-testid="result"><DateTime value={t} utc={true}/></p>);
|
||||
|
||||
const result = screen.getByTestId("result");
|
||||
expect(result.innerHTML).toBe("Friday, May 6, 2022 11:42 PM");
|
||||
});
|
12
ui/src/app/components/datetime/time.test.js
Normal file
12
ui/src/app/components/datetime/time.test.js
Normal file
@ -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);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user