Skip to content

Commit

Permalink
feat(calendar): strip events that are at least 1 month old
Browse files Browse the repository at this point in the history
  • Loading branch information
mtthp committed Apr 20, 2024
1 parent 77c437f commit 271f2d8
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/services/calendar.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {add, sub} from 'date-fns'
import {add, isAfter, sub} from 'date-fns'
import {zonedTimeToUtc} from 'date-fns-tz'
import got from 'got'
import {uniq} from 'lodash-es'
Expand Down Expand Up @@ -56,19 +56,24 @@ const fetchAmourFoodEvents = async () => {
}
}).json()

return events.map(event => {
const eventDay = zonedTimeToUtc(event.time * 1000, 'Europe/Paris')
return {
title: event.details?.plat_viande || event.nom,
description: event.description.replaceAll(/<[^>]*>?/gm, ''), // Strip HTML tags
start: add(eventDay, {hours: 12}).toISOString(),
end: add(eventDay, {hours: 13, minutes: 30}).toISOString(),
location: 'L\'Amour Food, 7 Av. de Blida, 57000 Metz',
urls: [event.disponible && event.permalink].filter(Boolean),
pictures: [event.illustration],
calendar: 'AMOUR_FOOD'
}
})
return events
.filter(event => {
const eventDay = zonedTimeToUtc(event.time * 1000, 'Europe/Paris')
return isAfter(eventDay, sub(new Date(), {months: 1}))
})
.map(event => {
const eventDay = zonedTimeToUtc(event.time * 1000, 'Europe/Paris')
return {
title: event.details?.plat_viande || event.nom,
description: event.description.replaceAll(/<[^>]*>?/gm, ''), // Strip HTML tags
start: add(eventDay, {hours: 12}).toISOString(),
end: add(eventDay, {hours: 13, minutes: 30}).toISOString(),
location: 'L\'Amour Food, 7 Av. de Blida, 57000 Metz',
urls: [event.disponible && event.permalink].filter(Boolean),
pictures: [event.illustration],
calendar: 'AMOUR_FOOD'
}
})
}

/**
Expand Down

0 comments on commit 271f2d8

Please sign in to comment.