Timezone stuff

This commit is contained in:
tree 2023-03-25 17:36:02 +01:00
parent ee0e231a81
commit f4eb0fa52f
5 changed files with 20 additions and 4 deletions

10
package-lock.json generated
View File

@ -14,6 +14,7 @@
"@sveltejs/kit": "^1.3.3",
"autoprefixer": "^10.4.13",
"date-fns": "^2.29.3",
"date-fns-tz": "^2.0.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-svelte3": "^4.0.0",
@ -980,6 +981,15 @@
"url": "https://opencollective.com/date-fns"
}
},
"node_modules/date-fns-tz": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-2.0.0.tgz",
"integrity": "sha512-OAtcLdB9vxSXTWHdT8b398ARImVwQMyjfYGkKD2zaGpHseG2UPHbHjXELReErZFxWdSLph3c2zOaaTyHfOhERQ==",
"dev": true,
"peerDependencies": {
"date-fns": ">=2.0.0"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",

View File

@ -16,6 +16,7 @@
"@sveltejs/kit": "^1.3.3",
"autoprefixer": "^10.4.13",
"date-fns": "^2.29.3",
"date-fns-tz": "^2.0.0",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-svelte3": "^4.0.0",

View File

@ -1,7 +1,9 @@
<script>
import { format } from 'date-fns';
import ItemLogo from '$lib/components/ItemLogo.svelte';
import EventTypeBadge from '$lib/components/EventTypeBadge.svelte';
import { config } from '$lib/pbw';
import { format } from 'date-fns';
import { formatInTimeZone } from 'date-fns-tz'
export let segments;
export let date;
@ -34,8 +36,9 @@
>
<div class="flex gap-2">
<div class="text-xl md:w-32 md:text-right">
{format(new Date(segment.startTime), 'HH:mm')} - {format(
{formatInTimeZone(new Date(segment.startTime), config.tz, 'HH:mm')} - {formatInTimeZone(
new Date(segment.endTime),
config.tz,
'HH:mm'
)}
</div>

View File

@ -1,4 +1,5 @@
export const config = {
tz: "Europe/Prague",
collections: {
places: {
title: 'Places',

View File

@ -12,6 +12,7 @@
import { formatItemDate, bareDomain, getFlagEmoji } from '$lib/utils.js';
import { config } from '$lib/pbw';
import { format } from 'date-fns';
import { formatInTimeZone } from 'date-fns-tz'
const colsDef = Object.fromEntries(
Object.keys(config.collections).map((col) => {
@ -29,7 +30,7 @@
const dates = [];
for (const seg of event.segments) {
if (seg.remote) continue;
const date = format(new Date(seg.startTime), 'yyyy-MM-dd');
const date = formatInTimeZone(new Date(seg.startTime), config.tz, 'yyyy-MM-dd');
if (!dates.includes(date)) {
dates.push(date);
}
@ -369,7 +370,7 @@
<div class="mt-4">
<CalendarList
{date}
segments={item.segments.filter((s) => s.remote || s.startTime.match(new RegExp('^' + date)))}
segments={item.segments.filter((s) => s.remote || formatInTimeZone(new Date(s.startTime), config.tz, 'yyyy-MM-dd') === date)}
{entry}
bundle={data.bundle}
event={item}