-1

I've created an ASP.net application and I'm using Google Calendar API (Google.GData.Calendar) to schedule/add an event in Google calendar.

FYI, My client is from South Australia and my site is hosted on Godaddy India server.

In Australia from Oct to April is the daylight saving time. (South Australia (SA): First Sunday in October First Sunday in April Earlier observed DST in 1917 and 1942-1944 years. Since 1971 uses it regularly.)

Here is the problem I'm facing:

When I add an event from the site, from India, then event added on same time without any variations even in daylight saving days. But when my client add an event, from South Australia, then event added one hour early. E.g. If event time is 10AM-11AM, then it will be 9AM-10AM.

Sometimes event add on right time from South Australia using iPad/Tab/some other PCs.

Here is my code for the event:

var startHour = new DateTime(dtstartdatetime.Year, dtstartdatetime.Month, dtstartdatetime.Day, startTime.Hours, startTime.Minutes, 00).ToUniversalTime().AddHours(-7);
var startHour1 = new DateTime(dtstartdatetime.Year, dtstartdatetime.Month, dtstartdatetime.Day, endTime.Hours, endTime.Minutes, 00).ToUniversalTime().AddHours(-7);

Australia has 6 time zones and we are adjusting the event start and end time according to it.

Please let me know where I've to do changes

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Devendra
  • 47
  • 1
  • 1
  • 7

1 Answers1

1

A few things:

  • You are describing Google Calendar, but the code you show is just pure DateTime manipulation. Either update with code showing the Google Calendar specifics, or reduce your question to match the code you are showing.

  • GData uses v2 of the Google Calendar API, which has been deprecated. You should be using the current v3. Read this answer for more details.

  • You're building a DateTime with .Kind of Unspecified. When you call ToUniversalTime that is going to treat the starting time as if it were local. So the server's time zone is creeping in to your calculation.

  • You appear to be aware of 6 time zones and daylight saving time rules, but then you just add a hard-coded -7 hours. This is not the right way to determine a time zone or adjust for one. Go read about TimeZoneInfo and DateTimeOffset.

  • You may want to consider using Noda Time - which may help since Google Calendar uses IANA time zone identifiers.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575