Solved

Help with generating .ics file with correct time.

Posted on 2016-10-29
19
35 Views
Last Modified: 2016-10-31
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.
0
Comment
Question by:Andy Brown
  • 11
  • 7
19 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41865344
one uses UTC AKA Zulu Time (Z)
What you are seeing is based upon the users locale time at that time.
0
 

Author Comment

by:Andy Brown
ID: 41865376
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
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41865484
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
 

Author Comment

by:Andy Brown
ID: 41865648
Does that need to take in whether DST is in operation or not?
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41865656
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
 

Author Comment

by:Andy Brown
ID: 41865658
Thanks Gustav - do you know of a simple, reliable method.
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 41865667
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
 

Author Comment

by:Andy Brown
ID: 41865674
No way - surly it can't be that simple :0)
0
 

Author Comment

by:Andy Brown
ID: 41865789
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41865802
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
 

Author Comment

by:Andy Brown
ID: 41865805
I'll give it a go.  Thanks Gustav for the help.
0
 

Author Comment

by:Andy Brown
ID: 41865807
It adds two hours if the date was yesterday and one hour if the date is today.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41865823
That seems correct as DST was turned of last night.

/gustav
0
 

Author Comment

by:Andy Brown
ID: 41865826
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
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41865836
Well, yes. So why don't you send it converted to UTC - with the Z?

/gustav
0
 

Author Comment

by:Andy Brown
ID: 41865840
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
 

Author Closing Comment

by:Andy Brown
ID: 41866516
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
 

Author Comment

by:Andy Brown
ID: 41866517
PS - Gustav - if you're ever in Hamburg, I owe you a beer.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 41866522
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Granting full access permission allows users to access mailboxes present in their database. By giving full access permission one can open and read the content of any mailbox but cannot send emails from that mailbox.
Set OWA language and time zone in Exchange for individuals, all users or per database.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now