forked from MapComplete/MapComplete
Fix: opening hours now correctly shows "closes at <point far in the future>"
This commit is contained in:
parent
8584a4ba68
commit
d5b0976fb0
3 changed files with 53 additions and 46 deletions
|
|
@ -7,7 +7,7 @@ import BaseUIElement from "../BaseUIElement"
|
|||
import Toggle from "../Input/Toggle"
|
||||
import { VariableUiElement } from "../Base/VariableUIElement"
|
||||
import Table from "../Base/Table"
|
||||
import { Translation } from "../i18n/Translation"
|
||||
import { Translation, TypedTranslation } from "../i18n/Translation"
|
||||
import Loading from "../Base/Loading"
|
||||
import opening_hours from "opening_hours"
|
||||
import Locale from "../i18n/Locale"
|
||||
|
|
@ -73,7 +73,7 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
ranges: OpeningRange[][],
|
||||
lastMonday: Date
|
||||
): BaseUIElement {
|
||||
// First, a small sanity check. The business might be permanently closed, 24/7 opened or something other special
|
||||
// First, a small sanity check. The business might be permanently closed, 24/7 opened or be another special case
|
||||
if (ranges.some((range) => range.length > 0)) {
|
||||
// The normal case: we have items for the coming days
|
||||
return OpeningHoursVisualization.ConstructVizTable(oh, ranges, lastMonday)
|
||||
|
|
@ -98,8 +98,7 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
const today = new Date()
|
||||
today.setHours(0, 0, 0, 0)
|
||||
|
||||
// @ts-ignore
|
||||
const todayIndex = Math.ceil((today - rangeStart) / (1000 * 60 * 60 * 24))
|
||||
const todayIndex = Math.ceil((today.getTime() - rangeStart.getTime()) / (1000 * 60 * 60 * 24))
|
||||
// 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
|
||||
const earliestOpen = Math.min(8 * 60 * 60, ...changeHours)
|
||||
|
|
@ -193,11 +192,9 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
|
||||
const startOfDay: Date = new Date(range.startDate)
|
||||
startOfDay.setHours(0, 0, 0, 0)
|
||||
// @ts-ignore
|
||||
const startpoint = (range.startDate - startOfDay) / 1000 - earliestOpen
|
||||
const startpoint = (range.startDate.getTime() - startOfDay.getTime()) / 1000 - earliestOpen
|
||||
// prettier-ignore
|
||||
// @ts-ignore
|
||||
const width = (100 * (range.endDate - range.startDate) / 1000) / (latestclose - earliestOpen);
|
||||
const width = (100 * (range.endDate.getTime() - range.startDate.getTime()) / 1000) / (latestclose - earliestOpen)
|
||||
const startPercentage = (100 * startpoint) / availableArea
|
||||
return new FixedUiElement(textToShow)
|
||||
.SetStyle(`left:${startPercentage}%; width:${width}%`)
|
||||
|
|
@ -236,7 +233,7 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
changeHourText: string[],
|
||||
earliestOpen: number
|
||||
): [BaseUIElement, string] {
|
||||
let header: BaseUIElement[] = []
|
||||
const header: BaseUIElement[] = []
|
||||
|
||||
header.push(
|
||||
...OpeningHoursVisualization.CreateLinesAtChangeHours(
|
||||
|
|
@ -249,7 +246,7 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
let showHigher = false
|
||||
let showHigherUsed = false
|
||||
for (let i = 0; i < changeHours.length; i++) {
|
||||
let changeMoment = changeHours[i]
|
||||
const changeMoment = changeHours[i]
|
||||
const offset = (100 * (changeMoment - earliestOpen)) / availableArea
|
||||
if (offset < 0 || offset > 100) {
|
||||
continue
|
||||
|
|
@ -285,21 +282,23 @@ export default class OpeningHoursVisualization extends Toggle {
|
|||
/*
|
||||
* Visualizes any special case: e.g. not open for a long time, 24/7 open, ...
|
||||
* */
|
||||
private static ShowSpecialCase(oh: any) {
|
||||
const opensAtDate = oh.getNextChange()
|
||||
if (opensAtDate === undefined) {
|
||||
const comm = oh.getComment() ?? oh.getUnknown()
|
||||
if (!!comm) {
|
||||
return new FixedUiElement(comm)
|
||||
}
|
||||
|
||||
if (oh.getState()) {
|
||||
return Translations.t.general.opening_hours.open_24_7.Clone()
|
||||
}
|
||||
return Translations.t.general.opening_hours.closed_permanently.Clone()
|
||||
private static ShowSpecialCase(oh: opening_hours) {
|
||||
const nextChange = oh.getNextChange()
|
||||
if (nextChange !== undefined) {
|
||||
const nowOpen = oh.getState(new Date())
|
||||
const t = Translations.t.general.opening_hours
|
||||
const tr: TypedTranslation<{ date }> = nowOpen ? t.open_until : t.closed_until
|
||||
const date = nextChange.toLocaleString()
|
||||
return tr.Subs({ date })
|
||||
}
|
||||
return Translations.t.general.opening_hours.closed_until.Subs({
|
||||
date: opensAtDate.toLocaleString(),
|
||||
})
|
||||
const comment = oh.getComment() ?? oh.getUnknown()
|
||||
if (typeof comment === "string") {
|
||||
return new FixedUiElement(comment)
|
||||
}
|
||||
|
||||
if (oh.getState()) {
|
||||
return Translations.t.general.opening_hours.open_24_7.Clone()
|
||||
}
|
||||
return Translations.t.general.opening_hours.closed_permanently.Clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue