Left: | ||
Right: |
OLD | NEW |
---|---|
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 | |
7 | |
6 from dfdatetime import definitions | 8 from dfdatetime import definitions |
7 from dfdatetime import interface | 9 from dfdatetime import interface |
8 | 10 |
9 | 11 |
10 class UUIDTimeEpoch(interface.DateTimeEpoch): | 12 class UUIDTimeEpoch(interface.DateTimeEpoch): |
11 """UUID version 1 time epoch.""" | 13 """UUID version 1 time epoch.""" |
12 | 14 |
13 def __init__(self): | 15 def __init__(self): |
14 """Initializes an UUID version 1 time epoch.""" | 16 """Initializes an UUID version 1 time epoch.""" |
15 super(UUIDTimeEpoch, self).__init__(1582, 10, 15) | 17 super(UUIDTimeEpoch, self).__init__(1582, 10, 15) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 54 |
53 @property | 55 @property |
54 def timestamp(self): | 56 def timestamp(self): |
55 """int: UUID timestamp or None if timestamp is not set.""" | 57 """int: UUID timestamp or None if timestamp is not set.""" |
56 return self._timestamp | 58 return self._timestamp |
57 | 59 |
58 def _GetNormalizedTimestamp(self): | 60 def _GetNormalizedTimestamp(self): |
59 """Retrieves the normalized timestamp. | 61 """Retrieves the normalized timestamp. |
60 | 62 |
61 Returns: | 63 Returns: |
62 float: normalized timestamp, which contains the number of seconds since | 64 decimal.Decimal: normalized timestamp, which contains the number of |
63 January 1, 1970 00:00:00 and a fraction of second used for increased | 65 seconds since January 1, 1970 00:00:00 and a fraction of second |
64 precision, or None if the normalized timestamp cannot be determined. | 66 used for increased precision, or None if the normalized timestamp |
67 cannot be determined. | |
65 """ | 68 """ |
66 if self._normalized_timestamp is None: | 69 if self._normalized_timestamp is None: |
67 if (self._timestamp is not None and self._timestamp >= 0 and | 70 if (self._timestamp is not None and self._timestamp >= 0 and |
68 self._timestamp <= self._UINT60_MAX): | 71 self._timestamp <= self._UINT60_MAX): |
69 self._normalized_timestamp = ( | 72 self._SetNormalizedTimestamp( |
70 float(self._timestamp) / self._100NS_PER_SECOND) | 73 (decimal.Decimal(self._timestamp) / self._100NS_PER_SECOND) |
Joachim Metz
2018/03/09 01:02:46
style consistency nit: please put - at end of line
ep
2018/03/12 14:53:13
Done.
| |
71 self._normalized_timestamp -= self._UUID_TO_POSIX_BASE | 74 - self._UUID_TO_POSIX_BASE) |
72 | 75 |
73 return self._normalized_timestamp | 76 return self._normalized_timestamp |
74 | 77 |
75 def CopyFromDateTimeString(self, time_string): | 78 def CopyFromDateTimeString(self, time_string): |
76 """Copies an UUID timestamp from a date and time string. | 79 """Copies an UUID timestamp from a date and time string. |
77 | 80 |
78 Args: | 81 Args: |
79 time_string (str): date and time value formatted as: | 82 time_string (str): date and time value formatted as: |
80 YYYY-MM-DD hh:mm:ss.######[+-]##:## | 83 YYYY-MM-DD hh:mm:ss.######[+-]##:## |
81 | 84 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 self.timestamp > self._UINT60_MAX): | 144 self.timestamp > self._UINT60_MAX): |
142 return None, None, None | 145 return None, None, None |
143 | 146 |
144 try: | 147 try: |
145 timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) | 148 timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) |
146 number_of_days, _, _, _ = self._GetTimeValues(timestamp) | 149 number_of_days, _, _, _ = self._GetTimeValues(timestamp) |
147 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | 150 return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) |
148 | 151 |
149 except ValueError: | 152 except ValueError: |
150 return None, None, None | 153 return None, None, None |
OLD | NEW |