The main thing you are missing is that "Greenwich Standard Time" is not the
TimeZoneInfo
id for London. That one actually belongs to "(UTC) Monrovia, Reykjavik".You want "GMT Standard Time", which maps to "(UTC) Dublin, Edinburgh, Lisbon, London"
Yes, Windows time zones are weird. (At least you don't live in France, which gets strangely labeled as "Romance Standard Time"!)
Also, you should not be doing this part:
return DateTime.SpecifyKind(userDateTime, DateTimeKind.Local);
That will make various other code think it came from the local machine's time zone. Leave it with the "Unspecified" kind. (Or even better, use a
DateTimeOffset
instead of aDateTime
)Then you also need to use the
.IsDaylightSavingsTime
method on theTimeZoneInfo
object, rather than the one on the.DateTime
object. (There are two different methods, with the same name, on different objects, with differing behavior. Ouch!)
But I wholeheartedly agree that this is way too complicated and error prone. Just use Noda Time. You'll be glad you did!