toOADate static method
Convert date to OA value.
Implementation
static double toOADate(DateTime date) {
int ticks = 0;
ticks = _dateToTicks(date.year, date.month, date.day) +
_timeToTicks(date.hour, date.minute, date.second);
if (ticks == 0) {
return 0.0;
}
const int ticksPerDay = 10000 * 1000 * 60 * 60 * 24;
const int daysTo1899 = (((365 * 4 + 1) * 25 - 1) * 4 + 1) * 4 +
((365 * 4 + 1) * 25 - 1) * 3 -
367;
const int doubleDateOffset = daysTo1899 * ticksPerDay;
const int oaDateMinAsTicks = (((365 * 4 + 1) * 25 - 1) - 365) * ticksPerDay;
if (ticks < oaDateMinAsTicks) {
throw Exception('Arg_OleAutDateInvalid');
}
const int millisPerDay = 1000 * 60 * 60 * 24;
return ((ticks - doubleDateOffset) / 10000) / millisPerDay;
}