forked from MapComplete/MapComplete
Feature: allow freeform input for opening hours, fix #2522, refactor some uppercase method names; fixes to linked data loader
This commit is contained in:
parent
e7de94576f
commit
96fb4c457d
7 changed files with 90 additions and 85 deletions
|
@ -158,7 +158,10 @@ export default class LinkedDataLoader {
|
|||
openingHoursSpecification,
|
||||
<any>LinkedDataLoader.COMPACTING_CONTEXT_OH
|
||||
)
|
||||
const spec: object = compacted["@graph"]
|
||||
const spec:({
|
||||
"@type":"http://schema.org/OpeningHoursSpecification",
|
||||
"dayOfWeek": string[]
|
||||
})[] = compacted["@graph"]
|
||||
if (!spec) {
|
||||
return undefined
|
||||
}
|
||||
|
@ -173,17 +176,21 @@ export default class LinkedDataLoader {
|
|||
}
|
||||
return dow.toLowerCase().substring(0, 2)
|
||||
})
|
||||
const opens: string = rule.opens
|
||||
const closes: string = rule.closes === "23:59" ? "24:00" : rule.closes
|
||||
allRules.push(...OH.ParseRule(dow + " " + opens + "-" + closes))
|
||||
const opens: string = rule["http://schema.org/opens"] ?? rule["opens"]
|
||||
let closes: string = (rule["http://schema.org/closes"] ?? rule["closes"])
|
||||
closes = closes === "23:59" ? "24:00" : closes
|
||||
|
||||
allRules.push(...OH.parseRule(dow + " " + opens + "-" + closes))
|
||||
}
|
||||
|
||||
return OH.ToString(OH.MergeTimes(allRules))
|
||||
return OH.toString(OH.MergeTimes(allRules))
|
||||
}
|
||||
|
||||
static async compact(data: object, options?: JsonLdLoaderOptions): Promise<object> {
|
||||
static async compact(data: object, options?: JsonLdLoaderOptions): Promise<Record<string, string> | Record<string, string>[]> {
|
||||
if (Array.isArray(data)) {
|
||||
return await Promise.all(data.map((point) => LinkedDataLoader.compact(point, options)))
|
||||
|
||||
const result: Awaited<Record<string, string> | Record<string, string>[]>[] = await Promise.all(data.map((point) => LinkedDataLoader.compact(point, options)))
|
||||
return result.flatMap(x => Array.isArray(x) ? x : [x])
|
||||
}
|
||||
|
||||
const country = options?.country
|
||||
|
@ -276,8 +283,8 @@ export default class LinkedDataLoader {
|
|||
continue
|
||||
}
|
||||
if (k === "opening_hours") {
|
||||
const oh = [].concat(...v.split(";").map((r) => OH.ParseRule(r) ?? []))
|
||||
const merged = OH.ToString(OH.MergeTimes(oh ?? []))
|
||||
const oh = [].concat(...v.split(";").map((r) => OH.parseRule(r) ?? []))
|
||||
const merged = OH.toString(OH.MergeTimes(oh ?? []))
|
||||
if (merged === d[k]) {
|
||||
delete d[k]
|
||||
continue
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue