LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """UUID version 1 time implementation.""" | 2 """UUID version 1 time 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 Returns: | 63 Returns: |
64 decimal.Decimal: normalized timestamp, which contains the number of | 64 decimal.Decimal: normalized timestamp, which contains the number of |
65 seconds since January 1, 1970 00:00:00 and a fraction of second | 65 seconds since January 1, 1970 00:00:00 and a fraction of second |
66 used for increased precision, or None if the normalized timestamp | 66 used for increased precision, or None if the normalized timestamp |
67 cannot be determined. | 67 cannot be determined. |
68 """ | 68 """ |
69 if self._normalized_timestamp is None: | 69 if self._normalized_timestamp is None: |
70 if (self._timestamp is not None and self._timestamp >= 0 and | 70 if (self._timestamp is not None and self._timestamp >= 0 and |
71 self._timestamp <= self._UINT60_MAX): | 71 self._timestamp <= self._UINT60_MAX): |
72 self._SetNormalizedTimestamp( | 72 seconds = decimal.Decimal(self._timestamp) / self._100NS_PER_SECOND |
73 (decimal.Decimal(self._timestamp) / self._100NS_PER_SECOND) | 73 self._SetNormalizedTimestamp(seconds - self._UUID_TO_POSIX_BASE) |
74 - self._UUID_TO_POSIX_BASE) | |
75 | 74 |
76 return self._normalized_timestamp | 75 return self._normalized_timestamp |
77 | 76 |
78 def CopyFromDateTimeString(self, time_string): | 77 def CopyFromDateTimeString(self, time_string): |
79 """Copies an UUID timestamp from a date and time string. | 78 """Copies an UUID timestamp from a date and time string. |
80 | 79 |
81 Args: | 80 Args: |
82 time_string (str): date and time value formatted as: | 81 time_string (str): date and time value formatted as: |
83 YYYY-MM-DD hh:mm:ss.######[+-]##:## | 82 YYYY-MM-DD hh:mm:ss.######[+-]##:## |
84 | 83 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 self.timestamp > self._UINT60_MAX): | 143 self.timestamp > self._UINT60_MAX): |
145 return None, None, None | 144 return None, None, None |
146 | 145 |
147 try: | 146 try: |
148 timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) | 147 timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) |
149 number_of_days, _, _, _ = self._GetTimeValues(timestamp) | 148 number_of_days, _, _, _ = self._GetTimeValues(timestamp) |
150 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | 149 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) |
151 | 150 |
152 except ValueError: | 151 except ValueError: |
153 return None, None, None | 152 return None, None, None |
LEFT | RIGHT |