Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions programmerbar-web/src/lib/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toZonedTime } from 'date-fns-tz';
import { toZonedTime, fromZonedTime } from 'date-fns-tz';
import { format } from 'date-fns';

export type Dateish = string | Date | number;
Expand Down Expand Up @@ -33,13 +33,18 @@ export const toLocalDateTimeString = (date: Dateish): string => {
};

export const parseDateTimeLocal = (value: string): Date => {
return new Date(value);
return fromZonedTime(value, OSLO_TIME_ZONE);
};

export const toUtcISOStringFromLocal = (value: string) => {
return new Date(value).toISOString();
return fromZonedTime(value, OSLO_TIME_ZONE).toISOString();
};

export const ISOStandard = (date: Dateish) => {
return toLocalDateTimeString(date);
};

export const toDateTimeLocalInput = (date: Dateish): string => {
const utcDate = ensureDate(date);
return format(utcDate, "yyyy-MM-dd'T'HH:mm");
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Checkbox from '$lib/components/ui/Checkbox.svelte';
import { enhance } from '$app/forms';
import { CreateEventState } from '$lib/states/create-event-state.svelte';
import { ISOStandard } from '$lib/date';
import { toDateTimeLocalInput } from '$lib/date';
import { beforeNavigate } from '$app/navigation';
import { onMount } from 'svelte';

Expand All @@ -19,14 +19,14 @@

onMount(() => {
eventState.name = data.event.name;
eventState.date = ISOStandard(data.event.date);
eventState.date = toDateTimeLocalInput(data.event.date);
eventState.description = data.event.description || '';
eventState.shouldBePublic = !!(data.event.description || data.event.slug);

data.event.shifts.forEach((shift) => {
eventState.shifts.push({
startAt: ISOStandard(shift.startAt),
endAt: ISOStandard(shift.endAt),
startAt: toDateTimeLocalInput(shift.startAt),
endAt: toDateTimeLocalInput(shift.endAt),
users: shift.members.map((member) => ({
id: member.user.id,
name: member.user.name
Expand Down