Fix timezones
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useMemo, useState, useEffect, Fragment } from 'react';
|
||||
import { useStats } from '../../hooks/useStats';
|
||||
import { timeToMinutes } from '../../utils/time';
|
||||
import { timeToMinutes, adjustForTimezone } from '../../utils/time';
|
||||
|
||||
interface TimetableProps {
|
||||
from_date: string;
|
||||
@@ -106,8 +106,8 @@ const Timetable = ({ from_date, to_date, day_start, day_end }: TimetableProps) =
|
||||
return timetable.slots.some((slot) => {
|
||||
if (slot.date !== date || !slot.sleeping) return false;
|
||||
|
||||
const sStart = timeToMinutes(slot.slot_start);
|
||||
const sEnd = timeToMinutes(slot.slot_end);
|
||||
const sStart = adjustForTimezone(timeToMinutes(slot.slot_start));
|
||||
const sEnd = adjustForTimezone(timeToMinutes(slot.slot_end));
|
||||
|
||||
if (sEnd <= sStart) {
|
||||
const overlap1 = Math.max(sStart, intervalStart) < Math.min(1440, intervalEnd);
|
||||
|
||||
@@ -68,7 +68,11 @@ export function formatElapsedTime(utcTimestamp: string): string {
|
||||
* @returns formatted datetime string
|
||||
*/
|
||||
export function formatDateTime(date: Date | string): string {
|
||||
const d = typeof date === 'string' ? new Date(date) : date;
|
||||
let dateToParse = date;
|
||||
if (typeof date === 'string' && !date.endsWith('Z') && !date.includes('+')) {
|
||||
dateToParse = date + 'Z';
|
||||
}
|
||||
const d = typeof dateToParse === 'string' ? new Date(dateToParse) : dateToParse;
|
||||
return d.toLocaleString('sv-SE', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
|
||||
Reference in New Issue
Block a user