LEFT | RIGHT |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Date and time interfaces.""" | 2 """Date and time interfaces.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import abc | 6 import abc |
7 import calendar | 7 import calendar |
8 import decimal | 8 import decimal |
9 import math | 9 import math |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 super(DateTimeValues, self).__init__() | 81 super(DateTimeValues, self).__init__() |
82 self._normalized_timestamp = None | 82 self._normalized_timestamp = None |
83 self.is_local_time = False | 83 self.is_local_time = False |
84 self.precision = None | 84 self.precision = None |
85 | 85 |
86 def _SetNormalizedTimestamp(self, timestamp): | 86 def _SetNormalizedTimestamp(self, timestamp): |
87 """Sets the normalized timestamp with the correct precision. | 87 """Sets the normalized timestamp with the correct precision. |
88 | 88 |
89 If the desired precision is listed in definitions.DECIMAL_EXPONENTS, the | 89 If the desired precision is listed in definitions.DECIMAL_EXPONENTS, the |
90 normalized timestamp is quantized to it. | 90 normalized timestamp is quantized to it. |
| 91 |
| 92 Args: |
| 93 timestamp (decimal.Decimal): the timestamp to be set. |
91 """ | 94 """ |
92 try: | 95 try: |
93 granularity = self._DECIMAL_GRANULARITY[self.precision] | 96 granularity = self._DECIMAL_GRANULARITY[self.precision] |
94 except KeyError: | 97 except KeyError: |
95 pass | 98 pass |
96 if granularity: | 99 if granularity: |
97 timestamp = timestamp.quantize(granularity) | 100 timestamp = timestamp.quantize(granularity) |
98 self._normalized_timestamp = timestamp | 101 self._normalized_timestamp = timestamp |
99 | 102 |
100 def __eq__(self, other): | 103 def __eq__(self, other): |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 | 902 |
900 Returns: | 903 Returns: |
901 int: a POSIX timestamp in microseconds or None on error. | 904 int: a POSIX timestamp in microseconds or None on error. |
902 """ | 905 """ |
903 normalized_timestamp = self._GetNormalizedTimestamp() | 906 normalized_timestamp = self._GetNormalizedTimestamp() |
904 if normalized_timestamp is None: | 907 if normalized_timestamp is None: |
905 return | 908 return |
906 | 909 |
907 normalized_timestamp *= definitions.MICROSECONDS_PER_SECOND | 910 normalized_timestamp *= definitions.MICROSECONDS_PER_SECOND |
908 return int(math.ceil(normalized_timestamp)) | 911 return int(math.ceil(normalized_timestamp)) |
LEFT | RIGHT |