Sicos1977 / MsgKit

A .NET library to make MSG files without the need for Outlook
204 stars 56 forks source link

Date/Time Stamp 4 Hours Off #7

Closed michaelcoles closed 7 years ago

michaelcoles commented 7 years ago

Hi, thanks for the great tool. I'm playing around with it and I noticed a couple of issues. I'll file them as separate bugs for you. The first issue is that when I create an MSG file using the sample testing tool you provided, it seems to subtract 4 hours from the current time. As an example, I chose March 1, 2017 with the datepicker control, and saved at 12:06:39 PM. When I opened the file it indicated the creation date of March 1, 2017 at 8:06:39 AM. Not sure if the issue is with the datepicker control or elsewhere.

Sicos1977 commented 7 years ago

That can be possible, still need to finish some things in this library but the lack of time is the biggest problem :-)

michaelcoles commented 7 years ago

No worries. If it helps it seems to be happening around line 265 in Properties.cs in the AddProperty() method. This line:

            case PropertyType.PT_SYSTIME:
                var fileTime = ((DateTime)obj).ToFileTimeUtc();
                data = BitConverter.GetBytes(fileTime);
                break;

If I change it to this, it works:

            case PropertyType.PT_SYSTIME:
                var fileTime = ((DateTime)obj).ToFileTime();
                data = BitConverter.GetBytes(fileTime);
                break;

The odd thing is that the time conversion to UTC should add +4 hours from my time zone, not subtract 4 hours (I'm in U.S. EST). Looks like that might be a bug in a .NET Framework method.

Sicos1977 commented 7 years ago

Well I have to look into that. Maybe that I'm doing something wrong in the code.

michaelcoles commented 7 years ago

Your code looks good, it's just that last conversion to UTC that seems to be throwing it off.