ics
ics copied to clipboard
How to use timezone
How to add the TZID= to the time/date?
Thanks
See my solution.
Let's use an example: I have an event that is stored in my database and that has date/time without timezone, but I know it's tied to a location.
For example, my event happens in New York City on Feb 14, 2020 from 9 AM to 10 AM.
I'm in France and when I open the .ics file in my Outlook Calendar I should see this event from 5 PM to 6 PM (because I'm 6 hours ahead) in my calendar.
To achieve that, I did the below…
First, I installed moment-timezone. Then my code is:
let strStartTime = "2020-02-14 9:00:00";
let strEndTime = "2020-02-14 10:00:00";
// parse with NYC time, and then convert to UTC
let startTime = moment.tz(strStartTime, "America/New_York").utc();
let endTime = moment.tz(strEndTime, "America/New_York").utc();
// convert dates to array
startTime = [ startTime.get('year'), startTime.get('month')+1, startTime.get('date'), startTime.get('hour'), startTime.get('minute') ];
endTime = [ endTime.get('year'), endTime.get('month')+1, endTime.get('date'), endTime.get('hour'), endTime.get('minute') ];
// create event
createEvent({
title: "Event Title",
description: "Event Description",
location: "Room 1, New York City",
busyStatus: 'BUSY',
start: startTime,
startInputType: 'utc', // I define the start time as UTC
end: endTime,
endInputType: 'utc', // I define the start time as UTC
}, function(error, value) { […do something…] })
I hope it will help some others!
Thanks for the example! It should definitely go into the readme