From 73f6d8ba72bfdbb018fb564abcd4ad55bf288a3e Mon Sep 17 00:00:00 2001 From: Rickard Natt och Dag Date: Tue, 30 Mar 2021 17:42:05 +0200 Subject: [PATCH] fix: parse calendar dates as utc before iso (#100) --- lib/parse.test.ts | 51 +++++++++++++++++++++++++++++++++++++---------- lib/parse.ts | 4 ++-- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/lib/parse.test.ts b/lib/parse.test.ts index d8ed336ff..17c8d0c36 100644 --- a/lib/parse.test.ts +++ b/lib/parse.test.ts @@ -91,23 +91,52 @@ describe('parse', () => { ListId: null, Mentor: null, }, + { + Title: 'Utvecklingsdag, förskolorna är stängda', + Id: 5, + Description: null, + Location: null, + EventDate: '2021-05-28', + EventDateTime: '', + LongEventDateTime: '2021-05-28', + EndDate: '2021-05-28', + EndDateTime: '', + LongEndDateTime: '2021-05-28', + EventDateDayNumber: '28', + EventDateMonthName: 'maj', + EventDateMonthFullName: 'maj', + FullDateDescription: '2021-05-28 - 2021-05-28', + IsSameDay: true, + AllDayEvent: true, + ListId: null, + Mentor: null, + }, ], } }) + it('parses calendar correctly', () => { - expect(parse.calendar(response)).toEqual([ - { - id: 29, - location: null, - title: 'Jullov', - description: 'hello', - startDate: '2020-12-21T09:00:00.000+01:00', - endDate: '2021-01-08T10:00:00.000+01:00', - allDay: false, - }, - ]) + const [firstEvent] = parse.calendar(response) + + expect(firstEvent).toEqual({ + id: 29, + location: null, + title: 'Jullov', + description: 'hello', + startDate: '2020-12-21T08:00:00.000Z', + endDate: '2021-01-08T09:00:00.000Z', + allDay: false, + }) + }) + + it('parses start and end date without time', () => { + const [, secondEvent] = parse.calendar(response) + + expect(secondEvent.startDate).toEqual('2021-05-27T22:00:00.000Z') + expect(secondEvent.endDate).toEqual('2021-05-27T22:00:00.000Z') }) }) + describe('classmates', () => { beforeEach(() => { response = { diff --git a/lib/parse.ts b/lib/parse.ts index b41afb5b8..0a2ccce2b 100644 --- a/lib/parse.ts +++ b/lib/parse.ts @@ -116,10 +116,10 @@ export const calendarItem = ({ location, allDay: allDayEvent, startDate: longEventDateTime - ? DateTime.fromSQL(longEventDateTime, dateTimeOptions).toISO() + ? DateTime.fromSQL(longEventDateTime, dateTimeOptions).toUTC().toISO() : undefined, endDate: longEndDateTime - ? DateTime.fromSQL(longEndDateTime, dateTimeOptions).toISO() + ? DateTime.fromSQL(longEndDateTime, dateTimeOptions).toUTC().toISO() : undefined, }) export const calendar = (data: any): CalendarItem[] =>