diff --git a/app.js b/app.js index 931db1f..df75cc2 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ import { h } from 'preact' import { useState, useEffect } from 'preact/hooks' import { isWithinInterval, subHours } from 'date-fns' +import { zonedTimeToUtc, utcToZonedTime, format } from 'date-fns-tz' import { addHours } from 'date-fns/esm' import Video from './src/components/Video' @@ -23,18 +24,27 @@ export default () => { useEffect(() => { if (data && data.length) { data.forEach((stream, index) => { + const utcStartDate = zonedTimeToUtc( + new Date(stream.start), + 'Europe/Berlin' + ) + const utcEndDate = zonedTimeToUtc(new Date(stream.end), 'Europe/Berlin') + const { timeZone } = Intl.DateTimeFormat().resolvedOptions() + + const zonedStartDate = utcToZonedTime(utcStartDate, timeZone) + const zonedEndDate = utcToZonedTime(utcEndDate, timeZone) if ( isWithinInterval(new Date(), { - start: subHours(stream.start, 1), - end: addHours(stream.end, 1), + start: subHours(zonedStartDate, 1), + end: addHours(zonedEndDate, 1), }) ) { setCurrentVideo(stream) } if ( isWithinInterval(new Date(), { - start: stream.start, - end: stream.end, + start: zonedStartDate, + end: zonedEndDate, }) ) { setStreamIsLive(true) diff --git a/index.html b/index.html index a4671cd..7172f23 100644 --- a/index.html +++ b/index.html @@ -37,7 +37,7 @@ /> @@ -47,7 +47,7 @@ /> diff --git a/src/components/Chat/index.js b/src/components/Chat/index.js index da07da6..106cd83 100644 --- a/src/components/Chat/index.js +++ b/src/components/Chat/index.js @@ -13,11 +13,11 @@ import { } from './styles' import { colours } from '../../assets/theme' -const Chat = ({}) => { +const Chat = ({ overlayActive }) => { const { width, height } = useWindowDimensions() const [chatIsOpen, toggleChatOpen] = useToggle(true) return chatIsOpen ? ( - +