Skip to content

Instantly share code, notes, and snippets.

@thuliumsystems
Created February 27, 2024 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuliumsystems/4b1ed1990a0d5052d28b5435cd51e2fe to your computer and use it in GitHub Desktop.
Save thuliumsystems/4b1ed1990a0d5052d28b5435cd51e2fe to your computer and use it in GitHub Desktop.
iCal
import { NextApiRequest, NextApiResponse } from 'next';
import ical, { ICalEventStatus } from 'ical-generator';
const iCal = async (req: NextApiRequest, res: NextApiResponse) => {
const calendar = ical({
name: 'my first iCal',
prodId: '//cia//inc//EN',
url: 'site.com'
});
const startTime = new Date();
const endTime = new Date();
const endTime2 = new Date();
const endTime3 = new Date();
const status = ICalEventStatus.CONFIRMED
endTime.setHours(startTime.getHours() + 1);
endTime2.setHours(startTime.getHours() + 2);
endTime3.setHours(startTime.getHours() + 3);
calendar.createEvent({
start: startTime,
end: endTime,
summary: 'Example Event',
description: 'It works ;)',
location: { title: 'my room', address: 'Kissimmee' },
sequence: 0
})
calendar.createEvent({
start: startTime,
end: endTime2,
summary: 'Example Event 2',
description: 'It works ;2)',
location: { title: 'my room 2', address: 'Kissimmee 2' },
status: status,
id: 43
})
calendar.serve(res)
console.log(calendar.toString())
res.json(calendar.toString())
}
export default iCal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment