The problem is that this piece of code
private static DateTime julianDateToDate(double julianDate)results in an ArgumentOutOfRangeException if the argument julianDate is NaN (which happens when the app logic fails to calculate various twilight times – they cannot be calculated at all at certain times of year and place).
{
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds((julianDate + 0.5 - J1970) * msInDay);
return dt;
}
The weird thing is that the exception gets raised only when run on the emulator. If it is run on a real device, no exception is raised! Luckily it is possible to debug the code when it is running on a device, which revealed the problem.
The simple correction is to modify the method to manually check the argument and raise the exception:
private static DateTime julianDateToDate(double julianDate)The lesson here obviously is: the emulator is not the same thing as the real device. Remember to test your apps on the device as well!
{
if (double.IsNaN(julianDate))
throw new ArgumentOutOfRangeException("julianDate");
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds((julianDate + 0.5 - J1970) * msInDay);
return dt;
}
Edit 10.5.2013: corrected the first piece of code to reflect reality!
No comments:
Post a Comment