From 4b404f6e9ed4f2e7aa3acc6ec20a43b04f081776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Zbytovsk=C3=BD?= Date: Fri, 11 Oct 2024 18:43:51 +0200 Subject: [PATCH] OpeningHoursEditor: handle `Mo-Su 0:00-24:00` as `24/7` --- .../parser/__tests__/parser.test.ts | 10 ++++++++++ .../OpeningHoursEditor/parser/canItHandle.ts | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/__tests__/parser.test.ts b/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/__tests__/parser.test.ts index fbeb46781..cede91a9c 100644 --- a/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/__tests__/parser.test.ts +++ b/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/__tests__/parser.test.ts @@ -69,6 +69,16 @@ describe('Mo off', () => { }); }); +describe('24/7', () => { + test.each([{ input: 'Mo-Su 0:00-24:00' }, { input: 'Mo-Su 00:00-24:00' }])( + `$input`, + ({ input }) => { + expect(buildString(getDaysTable(input))).toEqual('24/7'); + expect(canItHandle(input)).toBe(true); + }, + ); +}); + describe('daysPart conversion', () => { test.each([ { input: 'Mo,Th' }, diff --git a/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/canItHandle.ts b/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/canItHandle.ts index 3aec70e71..1e54aee8a 100644 --- a/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/canItHandle.ts +++ b/src/components/FeaturePanel/EditDialog/EditContent/OpeningHoursEditor/parser/canItHandle.ts @@ -8,7 +8,7 @@ const splitByFirstSpace = (str: string) => { }; const sanitizeDaysParts = (value: string) => { - return (value ?? '') + return value .split(/ *; */) .map((part) => { if (part.match(/^(Mo|Tu|We|Th|Fr|Sa|Su) off$/)) { @@ -18,9 +18,14 @@ const sanitizeDaysParts = (value: string) => { const [daysPart, timePart] = splitByFirstSpace(part); const days = parseDaysPart(daysPart); const sanitizedDays = buildDaysPart(days); - return ( - (sanitizedDays === 'Mo-Su' ? '' : `${sanitizedDays} `) + `${timePart}` - ); + + if (sanitizedDays === 'Mo-Su' && timePart.match(/^0?0:00-24:00$/)) { + return '24/7'; + } + if (sanitizedDays === 'Mo-Su') { + return timePart; + } + return `${sanitizedDays} ${timePart}`; } return part; })