Left: | ||
Right: |
OLD | NEW |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """OLE automation date (or Floatingtime or Application time) implementation.""" | 2 """OLE automation date (or Floatingtime or Application time) implementation.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 from dfdatetime import definitions | 6 from dfdatetime import definitions |
7 from dfdatetime import interface | 7 from dfdatetime import interface |
8 | 8 |
9 | 9 |
10 class OLEAutomationDateEpoch(interface.DateTimeEpoch): | 10 class OLEAutomationDateEpoch(interface.DateTimeEpoch): |
(...skipping 23 matching lines...) Expand all Loading... | |
34 """ | 34 """ |
35 _EPOCH = OLEAutomationDateEpoch() | 35 _EPOCH = OLEAutomationDateEpoch() |
36 | 36 |
37 # The difference between December 30, 1899 and January 1, 1970 in days. | 37 # The difference between December 30, 1899 and January 1, 1970 in days. |
38 _OLE_AUTOMATION_DATE_TO_POSIX_BASE = 25569 | 38 _OLE_AUTOMATION_DATE_TO_POSIX_BASE = 25569 |
39 | 39 |
40 def __init__(self, timestamp=None): | 40 def __init__(self, timestamp=None): |
41 """Initializes an OLE Automation date. | 41 """Initializes an OLE Automation date. |
42 | 42 |
43 Args: | 43 Args: |
44 timestamp (Optional[float]): OLE Automation date. | 44 timestamp (Optional[decimal.Decimal]): OLE Automation date. |
Joachim Metz
2018/03/07 02:02:11
keep this a float
ep
2018/03/08 12:27:22
Done.
| |
45 """ | 45 """ |
46 super(OLEAutomationDate, self).__init__() | 46 super(OLEAutomationDate, self).__init__() |
47 self._timestamp = timestamp | 47 self._timestamp = timestamp |
48 self.precision = definitions.PRECISION_1_MICROSECOND | 48 self.precision = definitions.PRECISION_1_MICROSECOND |
49 | 49 |
50 @property | 50 @property |
51 def timestamp(self): | 51 def timestamp(self): |
52 """float: OLE Automation date timestamp or None if timestamp is not set.""" | 52 """decimal.Decimal: OLE Automation date timestamp or None if timestamp is |
53 not set.""" | |
53 return self._timestamp | 54 return self._timestamp |
54 | 55 |
55 def _GetNormalizedTimestamp(self): | 56 def _GetNormalizedTimestamp(self): |
56 """Retrieves the normalized timestamp. | 57 """Retrieves the normalized timestamp. |
57 | 58 |
58 Returns: | 59 Returns: |
59 float: normalized timestamp, which contains the number of seconds since | 60 decimal.Decimal: normalized timestamp, which contains the number of |
60 January 1, 1970 00:00:00 and a fraction of second used for increased | 61 seconds since January 1, 1970 00:00:00 and a fraction of second used |
61 precision, or None if the normalized timestamp cannot be determined. | 62 for increased precision, or None if the normalized timestamp cannot be |
63 determined. | |
62 """ | 64 """ |
63 if self._normalized_timestamp is None: | 65 if self._normalized_timestamp is None: |
64 if self._timestamp is not None: | 66 if self._timestamp is not None: |
65 self._normalized_timestamp = ( | 67 self._SetNormalizedTimestamp( |
66 self._timestamp - self._OLE_AUTOMATION_DATE_TO_POSIX_BASE) | 68 (self._timestamp - self._OLE_AUTOMATION_DATE_TO_POSIX_BASE) |
67 self._normalized_timestamp *= definitions.SECONDS_PER_DAY | 69 * definitions.SECONDS_PER_DAY) |
68 | 70 |
69 return self._normalized_timestamp | 71 return self._normalized_timestamp |
70 | 72 |
71 def CopyFromDateTimeString(self, time_string): | 73 def CopyFromDateTimeString(self, time_string): |
72 """Copies an OLE Automation date from a date and time string. | 74 """Copies an OLE Automation date from a date and time string. |
73 | 75 |
74 Args: | 76 Args: |
75 time_string (str): date and time value formatted as: | 77 time_string (str): date and time value formatted as: |
76 YYYY-MM-DD hh:mm:ss.######[+-]##:## | 78 YYYY-MM-DD hh:mm:ss.######[+-]##:## |
77 | 79 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 if self.timestamp is None: | 142 if self.timestamp is None: |
141 return None, None, None | 143 return None, None, None |
142 | 144 |
143 try: | 145 try: |
144 timestamp = self.timestamp * definitions.SECONDS_PER_DAY | 146 timestamp = self.timestamp * definitions.SECONDS_PER_DAY |
145 number_of_days, _, _, _ = self._GetTimeValues(int(timestamp)) | 147 number_of_days, _, _, _ = self._GetTimeValues(int(timestamp)) |
146 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | 148 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) |
147 | 149 |
148 except ValueError: | 150 except ValueError: |
149 return None, None, None | 151 return None, None, None |
OLD | NEW |