add timezone to timespan

This commit is contained in:
Darius
2025-11-24 01:36:55 +01:00
parent 3dfa3007bf
commit 36f2535cf8
4 changed files with 24 additions and 9 deletions

13
dist/timehelper.js vendored
View File

@@ -1,10 +1,12 @@
export class TimeSpan {
start;
end;
constructor(timeSpanStr) {
timeZone;
constructor(timeSpanStr, timeZone) {
const [startStr, endStr] = timeSpanStr.split("-");
this.start = this.parseTime(startStr);
this.end = this.parseTime(endStr);
this.timeZone = timeZone;
}
parseTime(timeStr) {
const [hours, minutes] = timeStr.split(":").map(Number);
@@ -12,8 +14,13 @@ export class TimeSpan {
}
contains(timestamp = Date.now()) {
const date = new Date(timestamp);
const hours = date.getHours();
const minutes = date.getMinutes();
const berlinTimeStr = date.toLocaleString("de-DE", {
timeZone: this.timeZone, // "Europe/Berlin"
hour12: false,
hour: "2-digit",
minute: "2-digit",
});
const [hours, minutes] = berlinTimeStr.split(":").map(Number);
const currentMinutes = hours * 60 + minutes;
const startMinutes = this.start.hours * 60 + this.start.minutes;
const endMinutes = this.end.hours * 60 + this.end.minutes;