1
- const pydatetime111 = pynew ()
1
+ # We used to use 1/1/1 but pandas.Timestamp is a subclass of datetime and does not include
2
+ # this date, so we use 1970 instead.
3
+ const _base_datetime = DateTime (1970 , 1 , 1 )
4
+ const _base_pydatetime = pynew ()
2
5
3
6
function init_datetime ()
4
- pycopy! (pydatetime111 , pydatetimetype (1 , 1 , 1 ))
7
+ pycopy! (_base_pydatetime , pydatetimetype (1970 , 1 , 1 ))
5
8
end
6
9
7
10
pydate (year, month, day) = pydatetype (year, month, day)
@@ -20,10 +23,10 @@ export pytime
20
23
21
24
pydatetime (year, month, day, _hour= 0 , _minute= 0 , _second= 0 , _microsecond= 0 , _tzinfo= nothing ; hour= _hour, minute= _minute, second= _second, microsecond= _microsecond, tzinfo= _tzinfo, fold= 0 ) = pydatetimetype (year, month, day, hour, minute, second, microsecond, tzinfo, fold= fold)
22
25
function pydatetime (x:: DateTime )
23
- # compute time since 1/1/1
26
+ # compute time since _base_datetime
24
27
# this accounts for fold
25
- d = pytimedeltatype (milliseconds = (x - DateTime ( 1 , 1 , 1 ) ). value)
26
- ans = pydatetime111 + d
28
+ d = pytimedeltatype (milliseconds = (x - _base_datetime ). value)
29
+ ans = _base_pydatetime + d
27
30
pydel! (d)
28
31
return ans
29
32
end
80
83
81
84
function pyconvert_rule_datetime (:: Type{DateTime} , x:: Py )
82
85
pydatetime_isaware (x) && return pyconvert_unconverted ()
83
- # compute the time since 1/1/1
86
+ # compute the time since _base_datetime
84
87
# this accounts for fold
85
- d = x - pydatetime111
88
+ d = x - _base_pydatetime
86
89
days = pyconvert_and_del (Int, d. days)
87
90
seconds = pyconvert_and_del (Int, d. seconds)
88
91
microseconds = pyconvert_and_del (Int, d. microseconds)
89
92
pydel! (d)
90
93
iszero (mod (microseconds, 1000 )) || return pyconvert_unconverted ()
91
- return pyconvert_return (DateTime ( 1 , 1 , 1 ) + Millisecond (div (microseconds, 1000 ) + 1000 * (seconds + 60 * 60 * 24 * days)))
94
+ return pyconvert_return (_base_datetime + Millisecond (div (microseconds, 1000 ) + 1000 * (seconds + 60 * 60 * 24 * days)))
92
95
end
0 commit comments