fromOADate static method

DateTime fromOADate(
  1. double doubleOLEValue
)

Returns a DateTime equivalent to the specified OLE Automation Date.

Implementation

static DateTime fromOADate(double doubleOLEValue) {
  if (doubleOLEValue < -657435.0 || doubleOLEValue > 2958465.99999999) {
    throw Exception('Not an valid OLE value.');
  }

  final double doubleSecondsPerDay = (24 * 60 * 60).toDouble();
  final double mantisaPart = doubleOLEValue % 1;

  final int integralPart = (doubleOLEValue - mantisaPart).toInt();
  final int totalMilliseconds =
      (mantisaPart * doubleSecondsPerDay * 1000).toInt();
  final DateTime minOLEDate = DateTime.parse('1899-12-30 00:00:00');
  DateTime oleDateFromValue = minOLEDate.add(Duration(days: integralPart));
  oleDateFromValue =
      oleDateFromValue.add(Duration(milliseconds: totalMilliseconds));
  return oleDateFromValue;
}