LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Cocoa timestamp implementation.""" | 2 """Cocoa timestamp 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 day_of_month = date_time_values.get('day_of_month', 0) | 90 day_of_month = date_time_values.get('day_of_month', 0) |
91 hours = date_time_values.get('hours', 0) | 91 hours = date_time_values.get('hours', 0) |
92 minutes = date_time_values.get('minutes', 0) | 92 minutes = date_time_values.get('minutes', 0) |
93 seconds = date_time_values.get('seconds', 0) | 93 seconds = date_time_values.get('seconds', 0) |
94 microseconds = date_time_values.get('microseconds', None) | 94 microseconds = date_time_values.get('microseconds', None) |
95 | 95 |
96 timestamp = self._GetNumberOfSecondsFromElements( | 96 timestamp = self._GetNumberOfSecondsFromElements( |
97 year, month, day_of_month, hours, minutes, seconds) | 97 year, month, day_of_month, hours, minutes, seconds) |
98 timestamp += self._COCOA_TO_POSIX_BASE | 98 timestamp += self._COCOA_TO_POSIX_BASE |
99 | 99 |
100 timestamp = decimal.Decimal(timestamp) | |
101 if microseconds is not None: | 100 if microseconds is not None: |
102 timestamp += (decimal.Decimal(microseconds) / | 101 timestamp += (float(microseconds) / |
103 definitions.MICROSECONDS_PER_SECOND) | 102 definitions.MICROSECONDS_PER_SECOND) |
104 | 103 |
105 self._normalized_timestamp = None | 104 self._normalized_timestamp = None |
106 self._timestamp = timestamp | 105 self._timestamp = timestamp |
107 self.is_local_time = False | 106 self.is_local_time = False |
108 | 107 |
109 def CopyToDateTimeString(self): | 108 def CopyToDateTimeString(self): |
110 """Copies the Cocoa timestamp to a date and time string. | 109 """Copies the Cocoa timestamp to a date and time string. |
111 | 110 |
112 Returns: | 111 Returns: |
(...skipping 24 matching lines...) Expand all Loading... |
137 """ | 136 """ |
138 if self.timestamp is None: | 137 if self.timestamp is None: |
139 return None, None, None | 138 return None, None, None |
140 | 139 |
141 try: | 140 try: |
142 number_of_days, _, _, _ = self._GetTimeValues(int(self.timestamp)) | 141 number_of_days, _, _, _ = self._GetTimeValues(int(self.timestamp)) |
143 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | 142 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) |
144 | 143 |
145 except ValueError: | 144 except ValueError: |
146 return None, None, None | 145 return None, None, None |
LEFT | RIGHT |