diff --git a/src/app-components/Datepicker/utils/dateHelpers.test.ts b/src/app-components/Datepicker/utils/dateHelpers.test.ts index dc6ebf2d0d..f217609f6e 100644 --- a/src/app-components/Datepicker/utils/dateHelpers.test.ts +++ b/src/app-components/Datepicker/utils/dateHelpers.test.ts @@ -72,6 +72,14 @@ describe('dateHelpers', () => { { props: ['2022-45-15', 'max'], expected: DatepickerMaxDateDefault }, { props: [DateFlags.Today, 'min'], expected: '2023-07-07T00:00:00Z' }, { props: [DateFlags.Today, 'max'], expected: '2023-07-07T23:59:59Z' }, + { props: [DateFlags.Yesterday, 'min'], expected: '2023-07-06T00:00:00Z' }, + { props: [DateFlags.Yesterday, 'max'], expected: '2023-07-06T23:59:59Z' }, + { props: [DateFlags.Tomorrow, 'min'], expected: '2023-07-08T00:00:00Z' }, + { props: [DateFlags.Tomorrow, 'max'], expected: '2023-07-08T23:59:59Z' }, + { props: [DateFlags.OneYearAgo, 'min'], expected: '2022-07-07T00:00:00Z' }, + { props: [DateFlags.OneYearAgo, 'max'], expected: '2022-07-07T23:59:59Z' }, + { props: [DateFlags.OneYearFromNow, 'min'], expected: '2024-07-07T00:00:00Z' }, + { props: [DateFlags.OneYearFromNow, 'max'], expected: '2024-07-07T23:59:59Z' }, { props: ['2022-11-05T12:00:00.000Z', 'min'], expected: '2022-11-05T00:00:00Z' }, { props: ['2022-11-05T12:00:00.000Z', 'max'], expected: '2022-11-05T23:59:59Z' }, { props: ['2022-01-31', 'min'], expected: '2022-01-31T00:00:00Z' }, diff --git a/src/app-components/Datepicker/utils/dateHelpers.ts b/src/app-components/Datepicker/utils/dateHelpers.ts index efd11b0128..e7033d51c5 100644 --- a/src/app-components/Datepicker/utils/dateHelpers.ts +++ b/src/app-components/Datepicker/utils/dateHelpers.ts @@ -62,6 +62,26 @@ export function getDateConstraint(dateOrFlag: string | DateFlags | undefined, co if (dateOrFlag === DateFlags.Today) { return shiftTime(new Date()); } + if (dateOrFlag === DateFlags.Yesterday) { + const date = new Date(); + date.setDate(date.getDate() - 1); + return shiftTime(date); + } + if (dateOrFlag === DateFlags.Tomorrow) { + const date = new Date(); + date.setDate(date.getDate() + 1); + return shiftTime(date); + } + if (dateOrFlag === DateFlags.OneYearAgo) { + const date = new Date(); + date.setFullYear(date.getFullYear() - 1); + return shiftTime(date); + } + if (dateOrFlag === DateFlags.OneYearFromNow) { + const date = new Date(); + date.setFullYear(date.getFullYear() + 1); + return shiftTime(date); + } const date = strictParseISO(dateOrFlag); if (date && isValid(date)) { diff --git a/src/layout/Datepicker/config.ts b/src/layout/Datepicker/config.ts index be8753d9de..9d60e7e086 100644 --- a/src/layout/Datepicker/config.ts +++ b/src/layout/Datepicker/config.ts @@ -27,7 +27,14 @@ export const Config = new CG.component({ .addProperty( new CG.prop( 'minDate', - new CG.union(new CG.str(), new CG.const('today')) + new CG.union( + new CG.str(), + new CG.const('today'), + new CG.const('yesterday'), + new CG.const('tomorrow'), + new CG.const('oneYearAgo'), + new CG.const('oneYearFromNow'), + ) .optional({ default: '1900-01-01T12:00:00.000Z' }) .setTitle('Earliest date') .setDescription( @@ -39,7 +46,14 @@ export const Config = new CG.component({ .addProperty( new CG.prop( 'maxDate', - new CG.union(new CG.str(), new CG.const('today')) + new CG.union( + new CG.str(), + new CG.const('today'), + new CG.const('yesterday'), + new CG.const('tomorrow'), + new CG.const('oneYearAgo'), + new CG.const('oneYearFromNow'), + ) .optional({ default: '2100-01-01T12:00:00.000Z' }) .setTitle('Latest date') .setDescription( diff --git a/src/types/index.ts b/src/types/index.ts index d3c75dc349..e728ea45d1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -41,6 +41,10 @@ export enum PresentationType { export enum DateFlags { Today = 'today', + Yesterday = 'yesterday', + Tomorrow = 'tomorrow', + OneYearAgo = 'oneYearAgo', + OneYearFromNow = 'oneYearFromNow', } export function isProcessTaskType(taskType: string): taskType is ProcessTaskType {