1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: make sure we handle hours as 00-23

This commit is contained in:
Christopher Kolstad 2022-03-15 11:22:10 +01:00 committed by Christopher Kolstad
parent a202b81344
commit e4b0cf1c11
3 changed files with 29 additions and 3 deletions

View File

@ -8,9 +8,9 @@ interface IDateSingleValueProps {
setError: React.Dispatch<React.SetStateAction<string>>;
}
const parseValue = (value: string) => {
export const parseDateValue = (value: string) => {
const date = new Date(value);
return format(date, 'yyyy-MM-dd') + 'T' + format(date, 'kk:mm');
return format(date, 'yyyy-MM-dd') + 'T' + format(date, 'HH:mm');
};
export const DateSingleValue = ({
@ -28,7 +28,7 @@ export const DateSingleValue = ({
id="date"
label="Date"
type="datetime-local"
value={parseValue(value)}
value={parseDateValue(value)}
onChange={e => {
setError('');
setValue(new Date(e.target.value).toISOString());

View File

@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Date component - snapshot matching 1`] = `
Object {
"midday": "2022-03-15T12:00",
"midnight": "2022-03-15T00:00",
}
`;

View File

@ -0,0 +1,18 @@
import { parseDateValue } from '../DateSingleValue';
test(`Date component is able to parse midnight when it's 00`, () => {
let f = parseDateValue('2022-03-15T12:27');
let midnight = parseDateValue('2022-03-15T00:27');
expect(f).toEqual('2022-03-15T12:27');
expect(midnight).toEqual('2022-03-15T00:27');
});
test(`Date component - snapshot matching`, () => {
let midnight = '2022-03-15T00:00';
let midday = '2022-03-15T12:00';
let obj = {
midnight: parseDateValue(midnight),
midday: parseDateValue(midday),
};
expect(obj).toMatchSnapshot();
});