Fix: fix #1675
This commit is contained in:
parent
aa5422b34e
commit
65250d77be
2 changed files with 64 additions and 19 deletions
|
@ -289,6 +289,14 @@ export class OH {
|
|||
* rules[0].startHour // => 11
|
||||
* rules[3].endHour // => 19
|
||||
*
|
||||
* const rules = OH.ParseRule("Mo 20:00-02:00");
|
||||
* rules.length // => 2
|
||||
* rules[0].weekday // => 0
|
||||
* rules[0].startHour // => 20
|
||||
* rules[0].endHour // => 0
|
||||
* rules[1].weekday // => 1
|
||||
* rules[1].startHour // => 0
|
||||
* rules[1].endHour // => 2
|
||||
*/
|
||||
public static ParseRule(rule: string): OpeningHour[] {
|
||||
try {
|
||||
|
@ -414,14 +422,14 @@ export class OH {
|
|||
}
|
||||
|
||||
/*
|
||||
This function converts a number of ranges (generated by OpeningHours.js) into all the hours of day that a change occurs.
|
||||
E.g.
|
||||
Monday, some business is opended from 9:00 till 17:00
|
||||
Tuesday from 9:30 till 18:00
|
||||
Wednesday from 9:30 till 12:30
|
||||
This function will extract all those moments of change and will return 9:00, 9:30, 12:30, 17:00 and 18:00
|
||||
This list will be sorted
|
||||
*/
|
||||
This function converts a number of ranges (generated by OpeningHours.js) into all the hours of day that a change occurs.
|
||||
E.g.
|
||||
Monday, some business is opended from 9:00 till 17:00
|
||||
Tuesday from 9:30 till 18:00
|
||||
Wednesday from 9:30 till 12:30
|
||||
This function will extract all those moments of change and will return 9:00, 9:30, 12:30, 17:00 and 18:00
|
||||
This list will be sorted
|
||||
*/
|
||||
public static allChangeMoments(
|
||||
ranges: {
|
||||
isOpen: boolean
|
||||
|
@ -507,9 +515,9 @@ export class OH {
|
|||
}
|
||||
|
||||
/*
|
||||
Calculates when the business is opened (or on holiday) between two dates.
|
||||
Returns a matrix of ranges, where [0] is a list of ranges when it is opened on monday, [1] is a list of ranges for tuesday, ...
|
||||
*/
|
||||
Calculates when the business is opened (or on holiday) between two dates.
|
||||
Returns a matrix of ranges, where [0] is a list of ranges when it is opened on monday, [1] is a list of ranges for tuesday, ...
|
||||
*/
|
||||
public static GetRanges(
|
||||
oh: any,
|
||||
from: Date,
|
||||
|
@ -560,6 +568,9 @@ export class OH {
|
|||
return values
|
||||
}
|
||||
|
||||
/**
|
||||
* OH.parseHHMM("12:30") // => {hours: 12, minutes: 30}
|
||||
*/
|
||||
private static parseHHMM(hhmm: string): { hours: number; minutes: number } {
|
||||
if (hhmm === undefined || hhmm == null) {
|
||||
return null
|
||||
|
@ -575,6 +586,10 @@ export class OH {
|
|||
return hm
|
||||
}
|
||||
|
||||
/**
|
||||
* OH.ParseHhmmRanges("20:00-22:15") // => [{startHour: 20, startMinutes: 0, endHour: 22, endMinutes: 15}]
|
||||
* OH.ParseHhmmRanges("20:00-02:15") // => [{startHour: 20, startMinutes: 0, endHour: 2, endMinutes: 15}]
|
||||
*/
|
||||
private static ParseHhmmRanges(hhmms: string): {
|
||||
startHour: number
|
||||
startMinutes: number
|
||||
|
@ -641,13 +656,25 @@ export class OH {
|
|||
endHour: number
|
||||
endMinutes: number
|
||||
}[]
|
||||
) {
|
||||
): {
|
||||
weekday: number
|
||||
startHour: number
|
||||
startMinutes: number
|
||||
endHour: number
|
||||
endMinutes: number
|
||||
}[] {
|
||||
if ((weekdays ?? null) == null || (timeranges ?? null) == null) {
|
||||
return null
|
||||
}
|
||||
const ohs: OpeningHour[] = []
|
||||
for (const timerange of timeranges) {
|
||||
const overMidnight =
|
||||
!(timerange.endHour === 0 && timerange.endMinutes === 0) &&
|
||||
(timerange.endHour < timerange.startHour ||
|
||||
(timerange.endHour == timerange.startHour &&
|
||||
timerange.endMinutes < timerange.startMinutes))
|
||||
for (const weekday of weekdays) {
|
||||
if (!overMidnight) {
|
||||
ohs.push({
|
||||
weekday: weekday,
|
||||
startHour: timerange.startHour,
|
||||
|
@ -655,10 +682,27 @@ export class OH {
|
|||
endHour: timerange.endHour,
|
||||
endMinutes: timerange.endMinutes,
|
||||
})
|
||||
} else {
|
||||
ohs.push({
|
||||
weekday: weekday,
|
||||
startHour: timerange.startHour,
|
||||
startMinutes: timerange.startMinutes,
|
||||
endHour: 0,
|
||||
endMinutes: 0,
|
||||
})
|
||||
ohs.push({
|
||||
weekday: (weekday + 1) % 7,
|
||||
startHour: 0,
|
||||
startMinutes: 0,
|
||||
endHour: timerange.endHour,
|
||||
endMinutes: timerange.endMinutes,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return ohs
|
||||
}
|
||||
|
||||
public static getMondayBefore(d) {
|
||||
d = new Date(d)
|
||||
const day = d.getDay()
|
||||
|
|
|
@ -82,6 +82,7 @@ export default class OpeningHoursInput extends InputElement<string> {
|
|||
const rules = valueWithoutPrefix.data?.split(";") ?? []
|
||||
for (const rule of rules) {
|
||||
if (OH.ParsePHRule(rule) !== null) {
|
||||
// We found the rule containing the public holiday information
|
||||
ph = rule
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue