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:
parent
a202b81344
commit
e4b0cf1c11
@ -8,9 +8,9 @@ interface IDateSingleValueProps {
|
|||||||
setError: React.Dispatch<React.SetStateAction<string>>;
|
setError: React.Dispatch<React.SetStateAction<string>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseValue = (value: string) => {
|
export const parseDateValue = (value: string) => {
|
||||||
const date = new Date(value);
|
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 = ({
|
export const DateSingleValue = ({
|
||||||
@ -28,7 +28,7 @@ export const DateSingleValue = ({
|
|||||||
id="date"
|
id="date"
|
||||||
label="Date"
|
label="Date"
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
value={parseValue(value)}
|
value={parseDateValue(value)}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
setError('');
|
setError('');
|
||||||
setValue(new Date(e.target.value).toISOString());
|
setValue(new Date(e.target.value).toISOString());
|
||||||
|
@ -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",
|
||||||
|
}
|
||||||
|
`;
|
@ -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();
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user