diff --git a/src/DateParser.jl b/src/DateParser.jl index 692bf43..2e23801 100644 --- a/src/DateParser.jl +++ b/src/DateParser.jl @@ -3,10 +3,13 @@ module DateParser using Base.Dates using TimeZones -import Base: parse, tryparse +# Note: As of Julia 0.6 the methods `Base.parse(::Type{<:TimeType}, ::AbstractString)` +# already exist and should no longer be exported. We probably want to rename these methods. + +# import Base: parse, tryparse # Re-export from Base with ZonedDateTime, DateTime, and Date -export parse, tryparse +# export parse, tryparse include(VERSION >= v"0.6.0-dev.2307" ? "constants.jl" : "constants-0.5.jl") include("parser.jl") diff --git a/src/extract.jl b/src/extract.jl index 75d24eb..1be9b0e 100644 --- a/src/extract.jl +++ b/src/extract.jl @@ -43,7 +43,7 @@ function extract_tz(str::AbstractString, index::Integer=1; tzmap::Dict{AbstractS if m != nothing fixed_name = m.captures[1] sign = m.captures[2] == "+" ? 1 : -1 - hour, minute = map(d -> d != nothing ? parse(Int, d) : 0, m.captures[3:end]) + hour, minute = map(d -> d != nothing ? Base.parse(Int, d) : 0, m.captures[3:end]) hour < 24 && minute < 60 || error("Timezone offset out of range: $(m.match)") offset = sign * (hour * 3600 + minute * 60) diff --git a/src/parser.jl b/src/parser.jl index 24bc709..b120eb8 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -67,7 +67,7 @@ function DateParts( if length(digit) == 6 # YYMMDD or HHMMSS[.ss] - values = map(d -> parse(Int64, d), [digit[1:2], digit[3:4], digit[5:6]]) + values = map(d -> Base.parse(Int64, d), [digit[1:2], digit[3:4], digit[5:6]]) m = match(r"\G\.(\d+)", str, index) if m != nothing || !isempty(date_values) @@ -85,29 +85,29 @@ function DateParts( elseif length(digit) in (8, 12, 14) # YYYYMMDD[hhmm[ss]] - values = map(d -> parse(Int64, d), [digit[1:4], digit[5:6], digit[7:8]]) + values = map(d -> Base.parse(Int64, d), [digit[1:4], digit[5:6], digit[7:8]]) push!(date_values, values...) push!(date_types, fill(ALL, length(values))...) if length(digit) > 8 - res.hour = parse(Int64, digit[9:10]) - res.minute = parse(Int64, digit[11:12]) + res.hour = Base.parse(Int64, digit[9:10]) + res.minute = Base.parse(Int64, digit[11:12]) if length(digit) > 12 - res.second = parse(Int64, digit[13:14]) + res.second = Base.parse(Int64, digit[13:14]) end end elseif length(digit) == 9 # HHMMSS[mil] - res.hour = parse(Int64, digit[1:2]) - res.minute = parse(Int64, digit[3:4]) - res.second = parse(Int64, digit[5:6]) - res.millisecond = parse(Int64, digit[7:9]) + res.hour = Base.parse(Int64, digit[1:2]) + res.minute = Base.parse(Int64, digit[3:4]) + res.second = Base.parse(Int64, digit[5:6]) + res.millisecond = Base.parse(Int64, digit[7:9]) elseif (m = match(hms_regex, str, index)) != nothing || hint != :none # HH[.MM][ ]h or MM[.SS][ ]m or SS[.ss][ ]s - value = parse(Int64, digit) + value = Base.parse(Int64, digit) # Grab decimal. Note that we still want to get the decimal if we entered # when hint != :none @@ -143,15 +143,15 @@ function DateParts( elseif (m = match(r"\G:(\d+)(?:\:(\d+))?(?:\.(\d+))?", str, index)) != nothing # HH:MM[:SS[.ss]] - res.hour = parse(Int64, digit) + res.hour = Base.parse(Int64, digit) minute, second, decimal = m.captures index = nextind(str, index + endof(m.match) - 1) - res.minute = parse(Int64, minute) + res.minute = Base.parse(Int64, minute) if second != nothing - res.second = parse(Int64, second) + res.second = Base.parse(Int64, second) if decimal != nothing res.millisecond = parse_as_decimal(decimal, 1000) end @@ -161,14 +161,14 @@ function DateParts( elseif (m = match(r"\G([-/.])(?|(\d+)(?(1)\1(\d+|\S+))?|((?:(?!\1)\S)+)(?(1)\1(\d+))?)", str, index)) != nothing # 1998-02-18, 1999/Feb/18, 1999.18.02 - push!(date_values, parse(Int64, digit)) + push!(date_values, Base.parse(Int64, digit)) push!(date_types, ALL) index = nextind(str, index + endof(m.match) - 1) for token in m.captures[2:end] token != nothing || continue if all(isdigit, token) - push!(date_values, parse(Int64, token)) + push!(date_values, Base.parse(Int64, token)) push!(date_types, ALL) elseif (ext = extract_month(token, locale=locale)) != nothing month, _ = ext @@ -181,13 +181,13 @@ function DateParts( elseif (m = match(ampm_regex, str, index)) != nothing # 12am - hour = parse(Int64, digit) + hour = Base.parse(Int64, digit) period = AMPM[locale][lowercase(m["key"])] res.hour = normalize_hour(hour, period) index = nextind(str, index + endof(m.match) - 1) else - value = parse(Int64, digit) + value = Base.parse(Int64, digit) if length(digit) == 3 && isnull(res.millisecond) res.millisecond = value @@ -207,8 +207,8 @@ function DateParts( error("Failed to parse date") end elseif length(digit) == 4 && isnull(res.hour) && isnull(res.minute) - res.hour = parse(Int64, digit[1:2]) - res.minute = parse(Int64, digit[3:4]) + res.hour = Base.parse(Int64, digit[1:2]) + res.minute = Base.parse(Int64, digit[3:4]) elseif !fuzzy error("Failed to parse date") end @@ -227,14 +227,14 @@ function DateParts( if (m = match(r"\G([-/.])(\d+)(?(1)\1(\d+))", str, index)) != nothing # Jan-01[-99] for token in m.captures[2:end] - push!(date_values, parse(Int64, token)) + push!(date_values, Base.parse(Int64, token)) push!(date_types, ALL) end index = nextind(str, index + endof(m.match) - 1) elseif (m = match(pertain_regex, str, index)) != nothing # "Jan of 01": 01 is clearly the year - push!(date_values, parse(Int64, m["year"])) + push!(date_values, Base.parse(Int64, m["year"])) push!(date_types, YEAR) index = nextind(str, index + endof(m.match) - 1) end diff --git a/src/util.jl b/src/util.jl index cfdf7c6..f879d7c 100644 --- a/src/util.jl +++ b/src/util.jl @@ -7,8 +7,8 @@ e.g. parse_as_decimal(\"5\") = 0.5 parse_as_decimal(\"450\") = 0.450 """ function parse_as_decimal(s::AbstractString) - parse(Int64, s) / 10^length(s) - # parse(Float64, string(".", s)) + Base.parse(Int64, s) / 10^length(s) + # Base.parse(Float64, string(".", s)) end """ diff --git a/test/runtests.jl b/test/runtests.jl index feba119..1c2aff0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,4 @@ -using DateParser +import DateParser: parse, tryparse using Base.Test using Base.Dates