1
1
import Dates: Date, DateTime
2
+ using DateTimes64: DateTime64, pydatetime_string, datetime_from_pystring
2
3
3
4
""" NumPy array protocol type string (typestr) format
4
5
@@ -21,37 +22,7 @@ Base.codepoint(x::ASCIIChar) = UInt8(x)
21
22
Base. show (io:: IO , x:: ASCIIChar ) = print (io, Char (x))
22
23
Base. zero (:: Union{ASCIIChar,Type{ASCIIChar}} ) = ASCIIChar (Base. zero (UInt8))
23
24
24
-
25
- using Dates: Period, TimeType, Date, DateTime, Dates
26
- import Base.==
27
- struct DateTime64{P} <: TimeType
28
- i:: Int64
29
- end
30
- Base. convert (:: Type{Date} ,t:: DateTime64{P} ) where P = Date (1970 )+ P (t. i)
31
- Base. convert (:: Type{DateTime} ,t:: DateTime64{P} ) where P = DateTime (1970 )+ P (t. i)
32
- Base. show (io:: IO ,t:: DateTime64{P} ) where P = print (io," DateTime64[" ,P," ]: " ,string (DateTime (t)))
33
- Base. isless (x:: DateTime64{P} , y:: DateTime64{P} ) where P = isless (x. i, y. i)
34
- == (x:: DateTime64{P} , y:: DateTime64{P} ) where P = x. i == y. i
35
- strpairs = [Dates. Year => " Y" , Dates. Month => " M" , Dates. Week => " W" , Dates. Day=> " D" ,
36
- Dates. Hour => " h" , Dates. Minute => " m" , Dates. Second=> " s" , Dates. Millisecond => " ms" ,
37
- Dates. Microsecond => " us" , Dates. Nanosecond => " ns" ]
38
- const jlperiod = Dict {String,Any} ()
39
- const pdt64string = Dict {Any, String} ()
40
- for p in strpairs
41
- jlperiod[p[2 ]] = p[1 ]
42
- pdt64string[p[1 ]] = p[2 ]
43
- end
44
- Base. convert (:: Type{DateTime64{P}} , t:: Date ) where P = DateTime64 {P} (Dates. value (P (t- Date (1970 ))))
45
- Base. convert (:: Type{DateTime64{P}} , t:: DateTime ) where P = DateTime64 {P} (Dates. value (P (t- DateTime (1970 ))))
46
- Base. convert (:: Type{DateTime64{P}} , t:: DateTime64{Q} ) where {P,Q} = DateTime64 {P} (Dates. value (P (Q (t. i))))
47
- Base. zero (t:: Union{DateTime64, Type{<:DateTime64}} ) = t (0 )
48
25
Base. zero (t:: Union{String, Type{String}} ) = " "
49
- # Base.promote_rule(::Type{<:DateTime64{<:Dates.DatePeriod}}, ::Type{Date}) = Date
50
- # Base.promote_rule(::Type{<:DateTime64{<:Dates.DatePeriod}}, ::Type{DateTime}) = DateTime
51
- # Base.promote_rule(::Type{<:DateTime64{<:Dates.TimePeriod}}, ::Type{Date}) = DateTime
52
- # Base.promote_rule(::Type{<:DateTime64{<:Dates.TimePeriod}}, ::Type{DateTime}) = DateTime
53
-
54
-
55
26
56
27
typestr (t:: Type ) = string (' <' , ' V' , sizeof (t))
57
28
typestr (t:: Type{>:Missing} ) = typestr (Base. nonmissingtype (t))
@@ -63,7 +34,7 @@ typestr(t::Type{<:AbstractFloat}) = string('<', 'f', sizeof(t))
63
34
typestr (:: Type{MaxLengthString{N,UInt32}} ) where N = string (' <' , ' U' , N)
64
35
typestr (:: Type{MaxLengthString{N,UInt8}} ) where N = string (' <' , ' S' , N)
65
36
typestr (:: Type{<:Array} ) = " |O"
66
- typestr (:: Type{<:DateTime64{P}} ) where P = " <M8[ $(pdt64string[P]) ] "
37
+ typestr (t :: Type{<:DateTime64} ) = pydatetime_string (t)
67
38
typestr (:: Type{<:AbstractString} ) = " |O"
68
39
69
40
const typestr_regex = r" ^([<|>])([tbiufcmMOSUV])(\d *)(\[\w +\] )?$"
@@ -107,7 +78,7 @@ function typestr(s::AbstractString, filterlist=nothing)
107
78
end
108
79
if tc == ' M' && ts == 8
109
80
# We have a datetime64 value
110
- return DateTime64{jlperiod[ String (typespec)[ 2 : end - 1 ]]}
81
+ return datetime_from_pystring (s)
111
82
end
112
83
# convert typecode to Char and typesize to Int
113
84
typemap[(tc,ts)]
0 commit comments