33"""Utilities that deal with blpapi.Datetime data type"""
44
55from __future__ import absolute_import
6+ from __future__ import division
67
78from . import internals
89from . import utils
10+ from .compat import with_metaclass
911
1012import datetime as _dt
1113
1214
15+ @with_metaclass (utils .MetaClassForClassesWithEnums )
1316class FixedOffset (_dt .tzinfo ):
1417 """Time zone information.
1518
@@ -43,29 +46,43 @@ class FixedOffset(_dt.tzinfo):
4346 """
4447
4548 def __init__ (self , offsetInMinutes = 0 ):
46- _dt .tzinfo .__init__ (self )
4749 self .__offset = _dt .timedelta (minutes = offsetInMinutes )
4850
4951 def utcoffset (self , unused ):
5052 return self .__offset
5153
5254 def dst (self , unused ):
53- return FixedOffset . _dt .timedelta (0 )
55+ return _dt .timedelta (0 )
5456
5557 def getOffsetInMinutes (self ):
56- return self .__offset .days * 24 * 60 + self .__offset .seconds / 60
58+ return self .__offset .days * 24 * 60 + self .__offset .seconds // 60
5759
5860 def __hash__ (self ):
5961 """x.__hash__() <==> hash(x)"""
6062 return self .getOffsetInMinutes ()
6163
6264 def __cmp__ (self , other ):
63- """Let the comparison operations work based on the time delta."""
65+ """Let the comparison operations work based on the time delta.
66+ NOTE: (compatibility) this method have no special meaning in python3,
67+ we should use __eq__, __lt__ and __le__ instead. Built-in cmp function
68+ is also gone. This method can be called only from python2."""
6469 return cmp (self .getOffsetInMinutes (), other .getOffsetInMinutes ())
6570
66- # Protect enumeration constant(s) defined in this class and in classes
67- # derived from this class from changes:
68- __metaclass__ = utils .MetaClassForClassesWithEnums
71+ def __eq__ (self , other ):
72+ """Let the equality operator work based on the time delta."""
73+ return self .getOffsetInMinutes () == other .getOffsetInMinutes ()
74+
75+ def __lt__ (self , other ):
76+ """Let the comparison operator work based on the time delta."""
77+ return self .getOffsetInMinutes () < other .getOffsetInMinutes ()
78+
79+ def __le__ (self , other ):
80+ """Let the comparison operator work based on the time delta."""
81+ return self .getOffsetInMinutes () <= other .getOffsetInMinutes ()
82+
83+
84+ # UTC timezone
85+ UTC = FixedOffset (0 )
6986
7087
7188class _DatetimeUtil (object ):
@@ -126,7 +143,7 @@ def convertToBlpapi(dtime):
126143 res .hours = dtime .hour
127144 res .minutes = dtime .minute
128145 res .seconds = dtime .second
129- res .milliSeconds = dtime .microsecond / 1000
146+ res .milliSeconds = dtime .microsecond // 1000
130147 res .parts = internals .DATETIME_DATE_PART | \
131148 internals .DATETIME_TIMEMILLI_PART
132149 elif isinstance (dtime , _dt .date ):
@@ -139,7 +156,7 @@ def convertToBlpapi(dtime):
139156 res .hours = dtime .hour
140157 res .minutes = dtime .minute
141158 res .seconds = dtime .second
142- res .milliSeconds = dtime .microsecond / 1000
159+ res .milliSeconds = dtime .microsecond // 1000
143160 res .parts = internals .DATETIME_TIMEMILLI_PART
144161 else :
145162 raise TypeError ("Datetime could be created only from \
0 commit comments