forked from MapComplete/MapComplete
Feature(opening_hours): correctly display "open ended" opening hours, see #2438
This commit is contained in:
parent
a01be66592
commit
9689cdfb65
7 changed files with 125 additions and 45 deletions
|
|
@ -10,16 +10,12 @@
|
|||
import { Translation } from "../../i18n/Translation"
|
||||
import Translations from "../../i18n/Translations"
|
||||
import { OH } from "../OpeningHours"
|
||||
import type { OpeningRange } from "../OpeningHours"
|
||||
|
||||
import { Utils } from "../../../Utils"
|
||||
|
||||
export let oh: opening_hours
|
||||
export let ranges: {
|
||||
isOpen: boolean
|
||||
isSpecial: boolean
|
||||
comment: string
|
||||
startDate: Date
|
||||
endDate: Date
|
||||
}[][] // Per weekday
|
||||
export let ranges: OpeningRange[][] // Per weekday
|
||||
export let rangeStart: Date
|
||||
let isWeekstable: boolean = oh.isWeekStable()
|
||||
let today = new Date()
|
||||
|
|
@ -34,8 +30,12 @@
|
|||
)
|
||||
let todayRanges = ranges.map((r, i) => r.filter(() => i === todayIndex))
|
||||
|
||||
// For the header
|
||||
const [changeHours, changeHourText] = OH.allChangeMoments(weekdayRanges)
|
||||
// For the header
|
||||
const [changeHoursWeekend, changeHourTextWeekend] = OH.allChangeMoments(weekendRanges)
|
||||
// To calculate the range to display
|
||||
const [changeHoursIncludingOpenEnd] = OH.allChangeMoments(weekdayRanges, true)
|
||||
|
||||
const weekdayHeaders: {
|
||||
changeHours: number[]
|
||||
|
|
@ -51,9 +51,9 @@
|
|||
let todayChangeMoments: Set<number> = new Set(OH.allChangeMoments(todayRanges)[0])
|
||||
// By default, we always show the range between 8 - 19h, in order to give a stable impression
|
||||
// Ofc, a bigger range is used if needed
|
||||
let earliestOpen = Math.min(8 * 60 * 60, ...changeHours)
|
||||
let earliestOpen = Math.min(8 * 60 * 60, ...changeHoursIncludingOpenEnd)
|
||||
// We always make sure there is 30m of leeway in order to give enough room for the closing entry
|
||||
let latestclose = Math.max(19 * 60 * 60, Math.max(...changeHours) + 30 * 60)
|
||||
let latestclose = Math.max(19 * 60 * 60, Math.max(...changeHoursIncludingOpenEnd) + 30 * 60)
|
||||
let availableArea = latestclose - earliestOpen
|
||||
|
||||
function calcLineOffset(moment: number) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue