Skip to content

Commit

Permalink
Replaced custom DateTime logic with DateTime.FromAODate()
Browse files Browse the repository at this point in the history
The old code was only needed when MimeKit was built for old
PCL profiles that are no longer supported.
  • Loading branch information
jstedfast committed Jan 20, 2024
1 parent a7d38a0 commit 6e9322c
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions MimeKit/Tnef/TnefPropertyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,33 +400,11 @@ double ReadDouble ()
return reader.ReadDouble ();
}

// Note: this method taken from Microsoft's Reference Source in DateTime.cs
static long DoubleDateToTicks (double value)
{
// The check done this way will take care of NaN
if (!(value < OADateMaxAsDouble) || !(value > OADateMinAsDouble))
throw new ArgumentException ("Invalid OLE Automation Date.", nameof (value));

long millis = (long) (value * MillisPerDay + (value >= 0 ? 0.5 : -0.5));

if (millis < 0)
millis -= (millis % MillisPerDay) * 2;

millis += DoubleDateOffset / TicksPerMillisecond;

if (millis < 0 || millis >= MaxMillis)
throw new ArgumentException ("Invalid OLE Automation Date.", nameof (value));

return millis * TicksPerMillisecond;
}

DateTime ReadAppTime ()
{
var appTime = ReadDouble ();

// Note: equivalent to DateTime.FromOADate(). Unfortunately, FromOADate() is
// not available in some PCL profiles.
return new DateTime (DoubleDateToTicks (appTime), DateTimeKind.Unspecified);
return DateTime.FromOADate (appTime);
}

DateTime ReadSysTime ()
Expand Down

0 comments on commit 6e9322c

Please sign in to comment.