1

I have some DDay iCal code that takes events from our SQL database and creates an iCal file so users can subscribe to the internet calendar in Outlook or Google Calendar. It's working fine except when a user in a different time zone syncs to their calendar it displays the time incorrectly. Our web server is in central time so a user in eastern time would see the time as 1 hour before the actual event time. Basically I want iCal to ignore time zones and just display the start and end time as it appears in my database. I have a feeling this is going to be impossible and we'll have to do the time conversion ourselves.

Dim iCal As iCalendar = New iCalendar()
Dim evt As [Event]
iCal.AddLocalTimeZone()
Dim dtStart As DateTime = dtr_SQL("StartDate").ToString()
Dim dtEnd As DateTime = dtr_SQL("EndDate").ToString()
Dim startDate As iCalDateTime = dtStart.ToUniversalTime()
Dim endDate As iCalDateTime = dtEnd.ToUniversalTime()
evt = iCal.Create(Of [Event])()
evt.Start = startDate
evt.Start.HasTime = True
evt.Start.IsUniversalTime = True
evt.End = endDate
evt.End.HasTime = True
evt.End.IsUniversalTime = True
GS442
  • 13
  • 3

1 Answers1

0

Since you are getting the time from a SQL database, it is unlikely there is a timezone associated with the time you are pulling. You will likely need to assign the time you are pulling to "Central Standard Time" as shown here:

Dim centralTime As New Date(dtStart)  'using the datetime you pulled from your database
Dim centralZoneId As String = "Central Standard Time"
Dim centralZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(centralZoneId)
Dim UTCTime as Date = TimeZoneInfo.ConvertTimeToUtc(centralTime, centralZone)

Now, if a user in Eastern Standard Time is executing your code, the time will be read from the database as CST (not EST, which is likely where your problem is coming from) and then converted to UTC. With a clear timezone associated with these times, Outlook and Google should be able to handle the rest when your calendar appointments are read by users in different time zones.

I hope this helps!

Dustin
  • 462
  • 1
  • 6
  • 19
  • This doesn't work though. I change my computer to Eastern Standard Time, sync the internet calendar to Outlook, and when I run the code it's still bumping the time down an hour inside of Outlook. I've tried setting the time zones and it never works. – GS442 Mar 29 '16 at 15:39
  • I may have misunderstood - are users executing any code you have written, or are they accessing directly from an Outlook appointment (or Google Calendar appointment) that has already been processed by your code? – Dustin Mar 29 '16 at 15:45
  • This is meant to be a live iCal feed that syncs with Outlook or Google Calendar. When users subscribe to the Internet Calendar in Outlook it polls the page every 5 minutes or so to get any possible changes. – GS442 Mar 29 '16 at 15:57
  • 1
    I changed the time zone to Eastern in your example and it is pulling the correct time now. I'm probably going to have to change my code so it passes the time zone from the user. Thanks for your help! – GS442 Mar 29 '16 at 16:29