internal static DateTime DosTimeToDateTime(uint dateTime)
{
// do the bit shift as unsigned because the fields are unsigned, but
// we can safely convert to int, because they won't be too big
int year = (int)(ValidZipDate_YearMin + (dateTime >> 25));
int month = (int)((dateTime >> 21) & 0xF);
int day = (int)((dateTime >> 16) & 0x1F);
int hour = (int)((dateTime >> 11) & 0x1F);
int minute = (int)((dateTime >> 5) & 0x3F);
int second = (int)((dateTime & 0x001F) * 2); // only 5 bits for second, so we only have a granularity of 2 sec.
try
{
return new System.DateTime(year, month, day, hour, minute, second, 0);
}
catch (ArgumentOutOfRangeException)
{
return s_invalidDateIndicator;
}
catch (ArgumentException)
{
return s_invalidDateIndicator;
}
}