Skip to content

Commit

Permalink
fix: parse calendar dates as utc before iso (kolplattformen#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
believer authored Mar 30, 2021
1 parent 2926de3 commit 73f6d8b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
51 changes: 40 additions & 11 deletions lib/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] =>
Expand Down

0 comments on commit 73f6d8b

Please sign in to comment.