fix: use date constructor instead of luxon
This commit is contained in:
parent
f8b3df2936
commit
74ea878073
|
@ -132,8 +132,8 @@ describe('parse', () => {
|
|||
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')
|
||||
expect(secondEvent.startDate).toEqual('2021-05-28T00:00:00.000Z')
|
||||
expect(secondEvent.endDate).toEqual('2021-05-28T00:00:00.000Z')
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -240,8 +240,8 @@ describe('parse', () => {
|
|||
title: 'Canceled: Julavslutning 8C',
|
||||
description: 'Nåt kul',
|
||||
location: 'Lakritskolan',
|
||||
startDate: '2020-12-14T14:10:00.000+01:00',
|
||||
endDate: '2020-12-14T14:40:00.000+01:00',
|
||||
startDate: '2020-12-14T13:10:00.000Z',
|
||||
endDate: '2020-12-14T13:40:00.000Z',
|
||||
oneDayEvent: true,
|
||||
allDayEvent: false,
|
||||
},
|
||||
|
@ -327,8 +327,8 @@ describe('parse', () => {
|
|||
expect(item.intro).toEqual(
|
||||
'Hej, Nu är problemet löst! Alla betyg syns som de ska. God jul!...'
|
||||
)
|
||||
expect(item.modified).toEqual('2020-12-18T16:18:00.000+01:00')
|
||||
expect(item.published).toEqual('2020-12-18T16:15:00.000+01:00')
|
||||
expect(item.modified).toEqual('2020-12-18T15:18:00.000Z')
|
||||
expect(item.published).toEqual('2020-12-18T15:15:00.000Z')
|
||||
})
|
||||
it('parses body correctly', () => {
|
||||
const [item] = parse.news(response)
|
||||
|
@ -408,8 +408,8 @@ describe('parse', () => {
|
|||
expect(item.intro).toEqual(
|
||||
'Kära vårdnadshavare! I helgen är det avlusningsdagar!'
|
||||
)
|
||||
expect(item.published).toEqual('2021-02-04T14:31:00.000+01:00')
|
||||
expect(item.modified).toEqual('2021-02-14T14:37:00.000+01:00')
|
||||
expect(item.published).toEqual('2021-02-04T13:31:00.000Z')
|
||||
expect(item.modified).toEqual('2021-02-14T13:37:00.000Z')
|
||||
expect(item.author).toEqual('Tieto Evry')
|
||||
})
|
||||
it('parses body correctly', () => {
|
||||
|
@ -586,7 +586,7 @@ describe('parse', () => {
|
|||
message: 'Betygen är publicerade.',
|
||||
sender: 'Elevdokumentation',
|
||||
url: 'https://elevdokumentation.stockholm.se/loa3/gradesStudent.do',
|
||||
dateCreated: '2020-12-18T15:59:46.340+01:00',
|
||||
dateCreated: '2020-12-18T14:59:46.340Z',
|
||||
category: null,
|
||||
type: 'webnotify',
|
||||
},
|
||||
|
|
61
lib/parse.ts
61
lib/parse.ts
|
@ -1,4 +1,3 @@
|
|||
import { DateTime, DateTimeOptions } from 'luxon'
|
||||
import { toMarkdown } from './parseHtml'
|
||||
import {
|
||||
CalendarItem,
|
||||
|
@ -15,24 +14,6 @@ import {
|
|||
|
||||
const camel = require('camelcase-keys')
|
||||
|
||||
const dateTimeOptions: DateTimeOptions = {
|
||||
locale: 'sv',
|
||||
setZone: true,
|
||||
zone: 'Europe/Stockholm',
|
||||
}
|
||||
|
||||
const tryParseDate = (
|
||||
date: string,
|
||||
format: string,
|
||||
options: DateTimeOptions
|
||||
) => {
|
||||
try {
|
||||
return DateTime.fromFormat(date, format, options).toISO()
|
||||
} catch (err) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export interface EtjanstResponse {
|
||||
Success: boolean
|
||||
Error: string | null
|
||||
|
@ -116,10 +97,10 @@ export const calendarItem = ({
|
|||
location,
|
||||
allDay: allDayEvent,
|
||||
startDate: longEventDateTime
|
||||
? DateTime.fromSQL(longEventDateTime, dateTimeOptions).toUTC().toISO()
|
||||
? new Date(longEventDateTime).toISOString()
|
||||
: undefined,
|
||||
endDate: longEndDateTime
|
||||
? DateTime.fromSQL(longEndDateTime, dateTimeOptions).toUTC().toISO()
|
||||
? new Date(longEndDateTime).toISOString()
|
||||
: undefined,
|
||||
})
|
||||
export const calendar = (data: any): CalendarItem[] =>
|
||||
|
@ -137,26 +118,18 @@ export const newsItem = ({
|
|||
modDateSe,
|
||||
authorDisplayName,
|
||||
altText,
|
||||
}: any): NewsItem => {
|
||||
const published = tryParseDate(
|
||||
pubDateSe,
|
||||
'd LLLL yyyy HH:mm',
|
||||
dateTimeOptions
|
||||
)
|
||||
const modified = tryParseDate(modDateSe, 'd LLLL yyyy HH:mm', dateTimeOptions)
|
||||
return {
|
||||
header,
|
||||
published,
|
||||
modified,
|
||||
id: newsId,
|
||||
author: authorDisplayName,
|
||||
intro: preamble.replace(/([!,.])(\w)/gi, '$1 $2'),
|
||||
imageUrl: bannerImageUrl,
|
||||
fullImageUrl: `${IMAGE_HOST}${bannerImageUrl}`,
|
||||
imageAltText: altText,
|
||||
body: toMarkdown(body),
|
||||
}
|
||||
}
|
||||
}: any): NewsItem => ({
|
||||
header,
|
||||
published: pubDateSe ? new Date(pubDateSe).toISOString() : '',
|
||||
modified: modDateSe ? new Date(modDateSe).toISOString() : '',
|
||||
id: newsId,
|
||||
author: authorDisplayName,
|
||||
intro: preamble.replace(/([!,.])(\w)/gi, '$1 $2'),
|
||||
imageUrl: bannerImageUrl,
|
||||
fullImageUrl: `${IMAGE_HOST}${bannerImageUrl}`,
|
||||
imageAltText: altText,
|
||||
body: toMarkdown(body),
|
||||
})
|
||||
export const news = (data: any): NewsItem[] =>
|
||||
etjanst(data).newsItems.map(newsItem)
|
||||
|
||||
|
@ -176,8 +149,8 @@ export const scheduleItem = ({
|
|||
description,
|
||||
location,
|
||||
allDayEvent,
|
||||
startDate: DateTime.fromSQL(longEventDateTime, dateTimeOptions).toISO(),
|
||||
endDate: DateTime.fromSQL(longEndDateTime, dateTimeOptions).toISO(),
|
||||
startDate: new Date(longEventDateTime).toISOString(),
|
||||
endDate: new Date(longEndDateTime).toISOString(),
|
||||
oneDayEvent: isSameDay,
|
||||
})
|
||||
export const schedule = (data: any): ScheduleItem[] =>
|
||||
|
@ -251,7 +224,7 @@ export const notification = ({
|
|||
message: messagetext,
|
||||
sender: name,
|
||||
url: linkbackurl,
|
||||
dateCreated: DateTime.fromISO(dateCreated, dateTimeOptions).toISO(),
|
||||
dateCreated: new Date(dateCreated).toISOString(),
|
||||
category,
|
||||
type,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue