Skip to content

Commit

Permalink
OpeningHoursEditor: skip auxiliary Mo off; (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
zbycz authored Oct 7, 2024
1 parent c7d74f5 commit 0a03bea
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,22 @@ describe('canEditorHandle() === false', () => {
{ input: 'Mo-We 1:00-2:00; Fr 1:00-2:00' }, // we cant merge days yet, TODO update sanitize ?
{ input: 'Mo' },
{ input: 'Mo,PH 08:00-12:00' },
{ input: 'Mo-Tu off; Tu-Sa 10:00-13:00' },
])('$input', ({ input }) => {
expect(canItHandle(input)).toBe(false);
});
});

describe('Mo off', () => {
test.each([
{ input: 'Mo off', output: '' },
{ input: 'Mo off; Tu-Sa 10:00-13:00; Su off', output: 'Tu-Sa 10:00-13:00' },
])('$input', ({ input, output }) => {
expect(buildString(getDaysTable(input))).toEqual(output);
expect(canItHandle(input)).toBe(true);
});
});

describe('daysPart conversion', () => {
test.each([
{ input: 'Mo,Th' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const sanitizeDaysParts = (value: string) => {
return (value ?? '')
.split(/ *; */)
.map((part) => {
if (part.match(/^(Mo|Tu|We|Th|Fr|Sa|Su) off$/)) {
return false;
}
if (part.match(/^((Mo|Tu|We|Th|Fr|Sa|Su)[-, ]*)+/)) {
const [daysPart, timePart] = splitByFirstSpace(part);
const days = parseDaysPart(daysPart);
Expand All @@ -21,6 +24,7 @@ const sanitizeDaysParts = (value: string) => {
}
return part;
})
.filter(Boolean)
.join('; ')
.replace(/ *, */g, ',')
.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export const getEmptyValue = () =>
);

const getTimeSlots = (timePart: string) =>
timePart.split(/ *, */).map((time: string, slot: number) => {
const [from, to = ''] = time.split('-');
return { slotIdx: slot, from, to } as Slot;
});
timePart.trim() === 'off'
? []
: timePart.split(/ *, */).map((time: string, slot: number) => {
const [from, to = ''] = time.split('-');
return { slotIdx: slot, from, to } as Slot;
});

export const parseDaysPart = (daysPart: string): string[] => {
const otherDays = [];
Expand Down

0 comments on commit 0a03bea

Please sign in to comment.