forked from mhammond/pywin32
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversions to and from COM VT_DATE types should no longer lose milli…
…seconds. Should fix mhammond#1385, fix mhammond#387
- Loading branch information
Showing
4 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from __future__ import print_function | ||
|
||
from datetime import datetime | ||
import unittest | ||
|
||
import pywintypes | ||
import win32com.client | ||
import win32com.test.util | ||
import win32com.server.util | ||
from win32timezone import TimeZoneInfo | ||
|
||
# A COM object so we can pass dates to and from the COM boundary. | ||
class Tester: | ||
_public_methods_ = [ 'TestDate' ] | ||
def TestDate(self, d): | ||
assert isinstance(d, datetime) | ||
return d | ||
|
||
|
||
def test_ob(): | ||
return win32com.client.Dispatch(win32com.server.util.wrap(Tester())) | ||
|
||
class TestCase(win32com.test.util.TestCase): | ||
def check(self, d, expected = None): | ||
if not issubclass(pywintypes.TimeType, datetime): | ||
self.skipTest("this is testing pywintypes and datetime") | ||
got = test_ob().TestDate(d) | ||
self.assertEqual(got, expected or d) | ||
|
||
def testUTC(self): | ||
self.check(datetime(year=2000, month=12, day=25, microsecond=500000, tzinfo=TimeZoneInfo.utc())) | ||
|
||
def testLocal(self): | ||
self.check(datetime(year=2000, month=12, day=25, microsecond=500000, tzinfo=TimeZoneInfo.local())) | ||
|
||
def testMSTruncated(self): | ||
# milliseconds are kept but microseconds are lost after rounding. | ||
self.check(datetime(year=2000, month=12, day=25, microsecond=500500, tzinfo=TimeZoneInfo.utc()), | ||
datetime(year=2000, month=12, day=25, microsecond=500000, tzinfo=TimeZoneInfo.utc())) | ||
|
||
if __name__=='__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters