19
19
)
20
20
TIMEZONE_REGEX = re .compile ("(?P<prefix>[+-])(?P<hours>[0-9]{1,2}):(?P<minutes>[0-9]{1,2})" )
21
21
22
- class datetime :
22
+ class datetime ( object ) :
23
23
"""
24
24
Phony datetime object which mimics the python datetime object,
25
25
but allows for dates that don't exist in the proleptic gregorian calendar.
@@ -44,6 +44,8 @@ def __init__(self,year,month,day,hour=0,minute=0,second=0,dayofwk=-1,dayofyr=1):
44
44
self .dayofyr = dayofyr
45
45
self .second = second
46
46
self .format = '%Y-%m-%d %H:%M:%S'
47
+ self ._immutable = True
48
+
47
49
def strftime (self ,format = None ):
48
50
if format is None :
49
51
format = self .format
@@ -53,6 +55,15 @@ def timetuple(self):
53
55
def __repr__ (self ):
54
56
return self .strftime (self .format )
55
57
58
+ def __hash__ (self ):
59
+ return hash (self .timetuple ())
60
+
61
+ def __setattr__ (self , name , value ):
62
+ if hasattr (self , '_immutable' ):
63
+ raise AttributeError ("attempt to change immutable instance" )
64
+ else :
65
+ object .__setattr__ (self , name , value )
66
+
56
67
def _compare (self , comparison_op , other ):
57
68
if hasattr (other , 'strftime' ):
58
69
return comparison_op (self .strftime ('%Y-%m-%d %H:%M:%S' ),
@@ -78,6 +89,7 @@ def __ge__(self, other):
78
89
return self ._compare (operator .ge , other )
79
90
80
91
92
+
81
93
def JulianDayFromDate (date ,calendar = 'standard' ):
82
94
83
95
"""
0 commit comments