2020-10-02 19:00:24 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
|
|
|
import {UIEventSource} from "../Logic/UIEventSource";
|
2020-10-08 19:03:00 +02:00
|
|
|
import opening_hours from "opening_hours";
|
2020-10-02 19:00:24 +02:00
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
export default class OpeningHoursVisualization extends UIElement {
|
2020-10-02 19:00:24 +02:00
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
constructor(tags: UIEventSource<any>) {
|
|
|
|
super(tags);
|
2020-10-02 19:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
private static GetRanges(tags: any, from: Date, to: Date): {
|
|
|
|
isOpen: boolean,
|
|
|
|
isUnknown: boolean,
|
|
|
|
comment: string,
|
|
|
|
startDate: Date
|
|
|
|
}[] {
|
|
|
|
|
|
|
|
const oh = new opening_hours(tags.opening_hours, {
|
|
|
|
lat: tags._lat,
|
|
|
|
lon: tags._lon,
|
|
|
|
address: {
|
|
|
|
country_code: tags._country
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const values = [];
|
|
|
|
|
|
|
|
const iterator = oh.getIterator(from);
|
|
|
|
|
|
|
|
while (iterator.advance(to)) {
|
|
|
|
|
|
|
|
const value = {
|
|
|
|
isUnknown: iterator.getUnknown(),
|
|
|
|
isOpen: iterator.getState(),
|
|
|
|
comment: iterator.getComment(),
|
|
|
|
startDate: iterator.getDate()
|
2020-10-02 19:00:24 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
if (value.comment === undefined && !value.isOpen && !value.isUnknown) {
|
|
|
|
// simply closed, nothing special here
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(value)
|
|
|
|
values.push(value);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
|
|
|
|
|
|
|
|
const from = new Date("2019-12-31");
|
|
|
|
const to = new Date("2020-01-05");
|
|
|
|
|
|
|
|
const ranges = OpeningHoursVisualization.GetRanges(this._source.data, from, to);
|
|
|
|
|
|
|
|
|
|
|
|
let text = "";
|
|
|
|
for (const range of ranges) {
|
|
|
|
text += `From${range.startDate} it is${range.isOpen} ${range.comment?? ""}<br/>`
|
|
|
|
}
|
2020-10-02 19:00:24 +02:00
|
|
|
|
2020-10-08 19:03:00 +02:00
|
|
|
return text;
|
2020-10-02 19:00:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|