0

Server response using original UTC:

TimeSlot: "2009-11-01T06:00:00Z"
TimeSlot: "2009-11-01T06:05:00Z"
TimeSlot: "2009-11-01T06:10:00Z"
TimeSlot: "2009-11-01T06:15:00Z"
TimeSlot: "2009-11-01T06:20:00Z"
TimeSlot: "2009-11-01T06:25:00Z"
TimeSlot: "2009-11-01T06:30:00Z"
TimeSlot: "2009-11-01T06:35:00Z"
TimeSlot: "2009-11-01T06:40:00Z"
TimeSlot: "2009-11-01T06:45:00Z"
TimeSlot: "2009-11-01T06:50:00Z"
TimeSlot: "2009-11-01T06:55:00Z"
TimeSlot: "2009-11-01T07:00:00Z"
TimeSlot: "2009-11-01T07:05:00Z"
TimeSlot: "2009-11-01T07:10:00Z"
TimeSlot: "2009-11-01T07:15:00Z"
TimeSlot: "2009-11-01T07:20:00Z"
TimeSlot: "2009-11-01T07:25:00Z"
TimeSlot: "2009-11-01T07:30:00Z"
TimeSlot: "2009-11-01T07:35:00Z"
TimeSlot: "2009-11-01T07:40:00Z"
TimeSlot: "2009-11-01T07:45:00Z"
TimeSlot: "2009-11-01T07:50:00Z"
TimeSlot: "2009-11-01T07:55:00Z"

TimeSlot: "2009-11-01T08:00:00Z"
TimeSlot: "2009-11-01T08:05:00Z"
TimeSlot: "2009-11-01T08:10:00Z"
TimeSlot: "2009-11-01T08:15:00Z"
TimeSlot: "2009-11-01T08:20:00Z"
TimeSlot: "2009-11-01T08:25:00Z"
TimeSlot: "2009-11-01T08:30:00Z"
TimeSlot: "2009-11-01T08:35:00Z"
TimeSlot: "2009-11-01T08:40:00Z"
TimeSlot: "2009-11-01T08:45:00Z"
TimeSlot: "2009-11-01T08:50:00Z"
TimeSlot: "2009-11-01T08:55:00Z"
TimeSlot: "2009-11-01T09:00:00Z"


After using the code below the DST intervals are moved:

DateTime.SpecifyKind(time, DateTimeKind.Utc).ConvertUtcTimeToMountainTime().ConvertMountainTimeToUtcTime() 

The response

TimeSlot: "2009-11-01T06:00:00Z"
TimeSlot: "2009-11-01T06:05:00Z"
TimeSlot: "2009-11-01T06:10:00Z"
TimeSlot: "2009-11-01T06:15:00Z"
TimeSlot: "2009-11-01T06:20:00Z"
TimeSlot: "2009-11-01T06:25:00Z"
TimeSlot: "2009-11-01T06:30:00Z"
TimeSlot: "2009-11-01T06:35:00Z"
TimeSlot: "2009-11-01T06:40:00Z"
TimeSlot: "2009-11-01T06:45:00Z"
TimeSlot: "2009-11-01T06:50:00Z"
TimeSlot: "2009-11-01T06:55:00Z"
TimeSlot: "2009-11-01T08:00:00Z"
TimeSlot: "2009-11-01T08:00:00Z"
TimeSlot: "2009-11-01T08:05:00Z"
TimeSlot: "2009-11-01T08:05:00Z"
TimeSlot: "2009-11-01T08:10:00Z"
TimeSlot: "2009-11-01T08:10:00Z"
TimeSlot: "2009-11-01T08:15:00Z"
TimeSlot: "2009-11-01T08:15:00Z"
TimeSlot: "2009-11-01T08:20:00Z"
TimeSlot: "2009-11-01T08:20:00Z"
TimeSlot: "2009-11-01T08:25:00Z"
TimeSlot: "2009-11-01T08:25:00Z"
TimeSlot: "2009-11-01T08:30:00Z"
TimeSlot: "2009-11-01T08:30:00Z"
TimeSlot: "2009-11-01T08:35:00Z"
TimeSlot: "2009-11-01T08:35:00Z"
TimeSlot: "2009-11-01T08:40:00Z"
TimeSlot: "2009-11-01T08:40:00Z"
TimeSlot: "2009-11-01T08:45:00Z"
TimeSlot: "2009-11-01T08:45:00Z"
TimeSlot: "2009-11-01T08:50:00Z"
TimeSlot: "2009-11-01T08:50:00Z"
TimeSlot: "2009-11-01T08:55:00Z"
TimeSlot: "2009-11-01T08:55:00Z"

TimeSlot: "2009-11-01T09:00:00Z"

Here are the methods being used

TimeZoneInfo MountainTime = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");

public static DateTime ConvertUtcTimeToMountainTime(this DateTime date)
{
    return TimeZoneInfo.ConvertTimeFromUtc(date, MountainTime);
}

public static DateTime ConvertMountainTimeToUtcTime(this DateTime date)
{
    date = DateTime.SpecifyKind(date, DateTimeKind.Unspecified);
    return TimeZoneInfo.ConvertTimeToUtc(date, MountainTime);
}

What is going wrong here?

TheyCallMeSam
  • 133
  • 10
  • 1
    How are you generating those lists? Also, please consider copying and pasting the text into the question rather than uploading an image. – Heretic Monkey Mar 24 '16 at 22:19
  • Why are you modifying `date` in `ConvertMountainTimeToUtcTime`? – Wai Ha Lee Mar 24 '16 at 22:19
  • @MikeMcCaughan instead of posting the lists from the client I'll post the response from the server and change it to text instead of images. Give me a few. – TheyCallMeSam Mar 24 '16 at 22:26
  • I think @WaiHaLee is on the right track in any case. `date` is a reference, and you're altering the reference. Try changing the second function to be `return TimeZoneInfo.ConvertTimeToUtc(DateTime.SpecifyKind(date, DateTimeKind.Unspecified), MountainTime);` – Heretic Monkey Mar 24 '16 at 22:34
  • @MikeMcCaughan no luck with that change.. still shows the second output posted above – TheyCallMeSam Mar 24 '16 at 22:45
  • 1
    Okay, I see what the problem is. Basically, you don't want to use `DateTime` for this. You want to use `DateTimeOffset`. I'm going to suggest we close this as a duplicate of http://stackoverflow.com/q/6214633/215552, since I can't do better than that answer :). – Heretic Monkey Mar 24 '16 at 23:07
  • Thank you for linking me to that! – TheyCallMeSam Mar 24 '16 at 23:18

0 Answers0