26
26
from __future__ import division
27
27
28
28
import datetime
29
- import functools
30
29
import time
31
30
from builtins import object
32
31
from typing import Any
45
44
TimestampTypes = Union [int , float , 'Timestamp' ]
46
45
# types compatible with Duration.of()
47
46
DurationTypes = Union [int , float , 'Duration' ]
47
+ TimestampDurationTypes = Union [int , float , 'Duration' , 'Timestamp' ]
48
48
49
49
50
- @functools .total_ordering
51
50
class Timestamp (object ):
52
51
"""Represents a Unix second timestamp with microsecond granularity.
53
52
@@ -191,7 +190,7 @@ def __int__(self):
191
190
return self .micros // 1000000
192
191
193
192
def __eq__ (self , other ):
194
- # type: (Union[int, float, Timestamp, Duration] ) -> bool
193
+ # type: (TimestampDurationTypes ) -> bool
195
194
# Allow comparisons between Duration and Timestamp values.
196
195
if not isinstance (other , Duration ):
197
196
try :
@@ -206,12 +205,24 @@ def __ne__(self, other):
206
205
return not self == other
207
206
208
207
def __lt__ (self , other ):
209
- # type: (Union[int, float, Timestamp, Duration] ) -> bool
208
+ # type: (TimestampDurationTypes ) -> bool
210
209
# Allow comparisons between Duration and Timestamp values.
211
210
if not isinstance (other , Duration ):
212
211
other = Timestamp .of (other )
213
212
return self .micros < other .micros
214
213
214
+ def __gt__ (self , other ):
215
+ # type: (TimestampDurationTypes) -> bool
216
+ return not (self < other or self == other )
217
+
218
+ def __le__ (self , other ):
219
+ # type: (TimestampDurationTypes) -> bool
220
+ return self < other or self == other
221
+
222
+ def __ge__ (self , other ):
223
+ # type: (TimestampDurationTypes) -> bool
224
+ return not self < other
225
+
215
226
def __hash__ (self ):
216
227
return hash (self .micros )
217
228
@@ -252,7 +263,6 @@ def __mod__(self, other):
252
263
common_urns .constants .MAX_TIMESTAMP_MILLIS .constant )* 1000 )
253
264
254
265
255
- @functools .total_ordering
256
266
class Duration (object ):
257
267
"""Represents a second duration with microsecond granularity.
258
268
@@ -344,12 +354,24 @@ def __ne__(self, other):
344
354
return not self == other
345
355
346
356
def __lt__ (self , other ):
347
- # type: (Union[int, float, Duration, Timestamp] ) -> bool
357
+ # type: (TimestampDurationTypes ) -> bool
348
358
# Allow comparisons between Duration and Timestamp values.
349
359
if not isinstance (other , Timestamp ):
350
360
other = Duration .of (other )
351
361
return self .micros < other .micros
352
362
363
+ def __gt__ (self , other ):
364
+ # type: (TimestampDurationTypes) -> bool
365
+ return not (self < other or self == other )
366
+
367
+ def __le__ (self , other ):
368
+ # type: (TimestampDurationTypes) -> bool
369
+ return self < other or self == other
370
+
371
+ def __ge__ (self , other ):
372
+ # type: (TimestampDurationTypes) -> bool
373
+ return not self < other
374
+
353
375
def __hash__ (self ):
354
376
return hash (self .micros )
355
377
0 commit comments