LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Delphi TDateTime implementation.""" | 2 """Delphi TDateTime implementation.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import decimal | 6 import decimal |
7 | 7 |
8 from dfdatetime import definitions | 8 from dfdatetime import definitions |
9 from dfdatetime import interface | 9 from dfdatetime import interface |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 """Retrieves the normalized timestamp. | 59 """Retrieves the normalized timestamp. |
60 | 60 |
61 Returns: | 61 Returns: |
62 decimal.Decimal: normalized timestamp, which contains the number of | 62 decimal.Decimal: normalized timestamp, which contains the number of |
63 seconds since January 1, 1970 00:00:00 and a fraction of second used | 63 seconds since January 1, 1970 00:00:00 and a fraction of second used |
64 for increased precision, or None if the normalized timestamp cannot be | 64 for increased precision, or None if the normalized timestamp cannot be |
65 determined. | 65 determined. |
66 """ | 66 """ |
67 if self._normalized_timestamp is None: | 67 if self._normalized_timestamp is None: |
68 if self._timestamp is not None: | 68 if self._timestamp is not None: |
69 self._normalized_timestamp = ( | 69 self._SetNormalizedTimestamp( |
70 decimal.Decimal(self._timestamp) - self._DELPHI_TO_POSIX_BASE) | 70 (decimal.Decimal(self._timestamp) - self._DELPHI_TO_POSIX_BASE) * |
71 self._normalized_timestamp *= definitions.SECONDS_PER_DAY | 71 definitions.SECONDS_PER_DAY) |
72 self._Quantize() | |
73 | 72 |
74 return self._normalized_timestamp | 73 return self._normalized_timestamp |
75 | 74 |
76 def CopyFromDateTimeString(self, time_string): | 75 def CopyFromDateTimeString(self, time_string): |
77 """Copies a Delphi TDateTime timestamp from a string. | 76 """Copies a Delphi TDateTime timestamp from a string. |
78 | 77 |
79 Args: | 78 Args: |
80 time_string (str): date and time value formatted as: | 79 time_string (str): date and time value formatted as: |
81 YYYY-MM-DD hh:mm:ss.######[+-]##:## | 80 YYYY-MM-DD hh:mm:ss.######[+-]##:## |
82 | 81 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 if self.timestamp is None: | 146 if self.timestamp is None: |
148 return None, None, None | 147 return None, None, None |
149 | 148 |
150 try: | 149 try: |
151 number_of_seconds = self.timestamp * definitions.SECONDS_PER_DAY | 150 number_of_seconds = self.timestamp * definitions.SECONDS_PER_DAY |
152 number_of_days, _, _, _ = self._GetTimeValues(int(number_of_seconds)) | 151 number_of_days, _, _, _ = self._GetTimeValues(int(number_of_seconds)) |
153 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | 152 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) |
154 | 153 |
155 except ValueError: | 154 except ValueError: |
156 return None, None, None | 155 return None, None, None |
LEFT | RIGHT |