Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
No longer exporting parse and tryparse
Browse files Browse the repository at this point in the history
More recent Julia versions already have these method signatures defined
  • Loading branch information
omus committed May 26, 2017
1 parent b49b6dc commit 4e05fe3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 27 deletions.
7 changes: 5 additions & 2 deletions src/DateParser.jl
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/extract.jl
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions src/parser.jl
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/util.jl
Expand Up @@ -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

"""
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
@@ -1,4 +1,4 @@
using DateParser
import DateParser: parse, tryparse
using Base.Test

using Base.Dates
Expand Down

0 comments on commit 4e05fe3

Please sign in to comment.