This question is similar to [this][1] stackoverflow question insofar as
the Exception thrown is clear and explicit:
I'm converting the 1st Jan 2009 (perth time) to UTC and getting
"/System.ArgumentException: The supplied DateTime represents an invalid
time/"
|[TestMethod]
public void TestMethod1()
{
var date= DateTime.Parse("1-Jan-2009 00:00");
var wstTimezone= TimeZoneInfo.FindSystemTimeZoneById("W. Australia Standard Time");
Trace.WriteLine(wstTimezone.IsInvalidTime(date));//is invalid
Trace.WriteLine(TimeZoneInfo.ConvertTime(date, wstTimezone,
TimeZoneInfo.FindSystemTimeZoneById("UTC")));//throw Exception
}
|
1) I'm more curious than concerned - *Can anyone out here in the west
recall why this time might be invalid?* One hour either side of this
works ok; I can't recall daylight savings moving/changing during this
period.
2) In general, how are people handling cases like this? For example, if
you have a user who wants to select all the foos from 1st Jan 2009
onwards then you would naturally get the start time in the users
timezone (1-Jan-2009 00:00) and convert to UTC - this is especially
problematic if you only allow the user to select the start and end date
(no times) which means you'd have to ask the user to select a different
date completely because 'midnight didnt exist in your timezone on the
selected date'
Hope I'm making sense
Wal
[1]:
http://stackoverflow.com/questions/2416439/exception-calling-when-timezoneinfo-converttimetoutc-for-certain-datetime-values