We have a scheduler application. Using this application an user can schedule a task to run at 8 AM PT daily for the next 30 days. We convert the time to UTC and store it in the databse as we have users from various time zones. We use the following function to convert the time to UTC:
public static DateTime ToAccountLocalTime(this DateTime dt)
{
return TimeZoneInfo.ConvertTimeFromUtc(dt, TimeZoneInfo.FindSystemTimeZoneById("user time zone"));
}
Now if the user scheduled a task to run at 8 AM PT daily for the next 30 days on 1st Nov 2012 then in the database 30 entries are made for each of the 30 days with time set to 4 PM UTC (as returned by the above method).
The problem occurred on Nov 4th when daylight saving ended. The task started running at 7 AM instead of 8 AM as the scheduler service runs all times based on UTC.
To solve this we need the above method to return 4 PM UTC for dates from 1st Nov to 3rd Nov and 3 PM UTC for dates after 4th Nov. What changes should I make to achieve this?