quinnj / Datetime.jl

A Date and DateTime implementation for Julia; Now deprecated in favor of https://github.com/quinnj/Dates.jl
Other
20 stars 15 forks source link

date(format, datestring) method mentioned but not available #36

Closed jiahao closed 10 years ago

jiahao commented 10 years ago

Here is a Chinese date in the common Western calendar:

julia> date("2009年12月01日")
ERROR: Can't parse Date, please use date(format,datestring)
 in date at /Users/jiahao/.julia/Datetime/src/Datetime.jl:155

julia> methods(date)
#10 methods for generic function "date":
date(x::DateTime{C<:Calendar,T<:Offsets}) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:61
date(y::Int64) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:138
date(y::Int64,m::Int64) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:138
date(y::Int64,m::Int64,d::Int64) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:138
date{C<:Calendar}(y::Int64,m::Int64,d::Int64,cal::Type{C<:Calendar}) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:138
date(y::Union(Period,Real)) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:139
date(y::Union(Period,Real),m::Union(Period,Real)) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:139
date(y::Union(Period,Real),m::Union(Period,Real),d::Union(Period,Real)) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:139
date{C<:Calendar}(y::Union(Period,Real),m::Union(Period,Real),d::Union(Period,Real),cal::Type{C<:Calendar}) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:139
date(s::String) at /Users/jiahao/.julia/Datetime/src/Datetime.jl:146

Currently, it seems that the only way you can parse this correctly is with

 Datetime.dt2string(Datetime.DateTimeFormat("yyyy年mm月dd日"), "2009年12月01日")
quinnj commented 10 years ago

This is also available in the Base PR.

quinnj commented 10 years ago

Though this case is interesting because currently only a single separator is support for separating Date or Time fields. I think this can be remedied though, so I'll look into it.

quinnj commented 10 years ago

Ok, I've been working on this and the Base PR now handles this case. Do you have some more variants on the above I can add to our tests?

quinnj commented 10 years ago

New Date parsing machinery is available in the dev branch. ed8123ede2e316a181a781ecd54fd735657b6cd8