Help with generating .ics file with correct time.

I am having trouble with creating iCalendar files with the correct time (based on DST and time-zone).  It's currently the 29th October and the clocks go back this evening.  If I create the .ics file with todays date, it will correctly open the file in outlook and set it for 21:00, which is the time as set within my app (all is good).  However, if I change it for tomorrow (30th) - it brings it to 20:00.  

I've seen a couple of fixes out there but could do with a bit of help.  Here's my current file:

BEGIN:VCALENDAR
PRODID:-//Dev//App1//EN
CALSCALE:GREGORIAN
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20161029T162630Z
DTSTART:20161029T190000Z
DTEND:20161029T200000Z
UID:4D1B0E5949E643D1828EBFB45EFBF6B40B902578D75A45E1B327B101AB16F3D56F55E6017B8B4838AB483E2CBA87BB40
CLASS:PUBLIC
SUMMARY:00 Quick test
DESCRIPTION:Test\n
BEGIN:VALARM
TRIGGER:-PT720M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR

Open in new window


When I change the following fields to tomorrow's date, it comes up at 20:00:

DTSTAMP:20161030T162630Z
DTSTART:20161030T190000Z
DTEND:20161030T200000Z

Open in new window


I think it's something obvious, but I haven't been able to fix it so could really do with some help.

Thank you.
Andy BrownDeveloperAsked:
Who is Participating?
 
Gustav BrockConnect With a Mentor CIOCommented:
You just have to remove the trailing Z:

RFC 2445 iCalendar specification (1998-11)

Then the time will be read as local time, DST or not:

DTSTART:20161030T210000
DTEND:20161030T220000

Open in new window

/gustav
0
 
David Johnson, CD, MVPOwnerCommented:
one uses UTC AKA Zulu Time (Z)
What you are seeing is based upon the users locale time at that time.
0
 
Andy BrownDeveloperAuthor Commented:
Thanks for that, but I'm not sure what to do.  Should I just remove the Z and use the actual time, or what?  Sorry, to sound a little slow (it's been a long week today).
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
Gustav BrockCIOCommented:
If you wish to set the appointment to start at 21.00 local time, UTC time on 2016-10-31 will be only one hour off, thus:

DTSTART:20161030T200000Z
DTEND:20161030T210000Z

Open in new window

/gustav
0
 
Andy BrownDeveloperAuthor Commented:
Does that need to take in whether DST is in operation or not?
0
 
Gustav BrockCIOCommented:
No. UTC (Z or popular Zulu time) has no DST. But, of course, to know the offset to local time zone, you must know if that local time zone operates with DST or not.

/gustav
0
 
Andy BrownDeveloperAuthor Commented:
Thanks Gustav - do you know of a simple, reliable method.
0
 
Andy BrownDeveloperAuthor Commented:
No way - surly it can't be that simple :0)
0
 
Andy BrownDeveloperAuthor Commented:
Okay - so I removed the "Z" and sure enough, it mostly works.  If you export as an .ics file, open it in outlook - sure enough the time is correct (for both today and yesterday).  If I manually copy that file, add it to an Outlook email and send it - again it works.  This is certainly progress....

However, if I create the email through my software, attach the .ics file through the code and send it to the same account.  The received email doesn't come up with a simple attachment to open, it comes in as a calendar item, which is fine - but the time is now wrong again (using the same file that works in Outlook if you open it manually) - see attached file.
Email.JPG
0
 
Gustav BrockCIOCommented:
Yes, it is not easy.

But then I would specify the time in UTC:

DTSTART:20161030T130000Z
DTEND:20161030T140000Z

Open in new window


How does that behave?

/gustav
0
 
Andy BrownDeveloperAuthor Commented:
I'll give it a go.  Thanks Gustav for the help.
0
 
Andy BrownDeveloperAuthor Commented:
It adds two hours if the date was yesterday and one hour if the date is today.
0
 
Gustav BrockCIOCommented:
That seems correct as DST was turned of last night.

/gustav
0
 
Andy BrownDeveloperAuthor Commented:
Sure - but here's the thing.  As it is now (without the "Z"),

if you export the ics file, open it by double-clicking on it (opens into Outlook), it's perfect (for both dates).  If it's sent as an email (generated from within my Access database, but using the same ics file), it doesn't receive it as an attachment, but as a calendar event - and throws out the time by an hour (see email.jpg).

So, if I open it manually - everything is great.  If I send it as an email attachment, Outlook tries to display it not as an attachment, but as a calendar event (with the wrong time).
0
 
Gustav BrockCIOCommented:
Well, yes. So why don't you send it converted to UTC - with the Z?

/gustav
0
 
Andy BrownDeveloperAuthor Commented:
Because it all appears to work fine (up until Outlook receives an email/appointment).

I'm just not quite sure which way to turn now.  As per the other question (that you commented on), if Outlook could simply receive it as an attachment - we're done (without the UTC time).  However, if I do need to use UTC time. I'm almost starting again.

Sorry for this dragging on.
0
 
Andy BrownDeveloperAuthor Commented:
Hi Gustav,

In the end, I removed the "Z" switch and setup my database, so that the time-zone for each recipient needs to be set.  I then added the timezone information to the .ics file and it works consistently.  Just in case you/anyone is interested.  I also found this link helpful:

http://erics-notes.blogspot.de/2013/05/fixing-ics-time-zone.html

Thanks again for all of your help on this.
0
 
Andy BrownDeveloperAuthor Commented:
PS - Gustav - if you're ever in Hamburg, I owe you a beer.
0
 
Gustav BrockCIOCommented:
Great!

And yes, it does happen, though the last time - previous summer to avoid the heavy traffic - we first passed West of at Glückstadt to visit Cuxhaven and Bremerhaven, then East of at Swarzenbek.

/gustav
0
All Courses

From novice to tech pro — start learning today.