Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensible and fast date parsing #20952

Merged
merged 12 commits into from
Mar 16, 2017
15 changes: 8 additions & 7 deletions base/dates/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ end
genvar(t::DataType) = Symbol(lowercase(string(Base.datatype_name(t))))

"""
tryparsenext_core(str::AbstractString, pos::Int, len::Int, df::DateFormat)
tryparsenext_core(str::AbstractString, pos::Int, len::Int, df::DateFormat, raise=false)

Parses the string according to the directives within the DateFormat. Parsing will start at
character index `pos` and will stop when all directives are used or we have parsed up to the
end of the string (`len`).
character index `pos` and will stop when all directives are used or we have parsed up to,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there shouldn't be a comma at the end of the line here

the end of the string, `len`. If the provided string cannot be parsed an exception will be
thrown only if `raise` is true.

Returns a 3-element tuple `(values, pos, num_parsed)`:
* `values::Nullable{Tuple}`: A tuple which contains a values for each `DatePart` within the
`DateFormat` in the order in which the occur. If the string ends before we finish parsing
* `values::Nullable{Tuple}`: A tuple which contains a value for each `DatePart` within the
`DateFormat` in the order in which they occur. If the string ends before we finish parsing
all the directives the missing values will be filled in with default values.
* `pos::Int`: The character index at which parsing stopped.
* `num_parsed::Int`: The number of values which were parsed and stored within `values`.
Expand Down Expand Up @@ -110,14 +111,14 @@ Returns a 3-element tuple `(values, pos, num_parsed)`:
end

"""
tryparsenext_internal(::Type{<:TimeType}, str::AbstractString, pos::Int, len::Int, df::DateFormat)
tryparsenext_internal(::Type{<:TimeType}, str, pos, len, df::DateFormat, raise=false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should raise also be described here?


Parses the string according to the directives within the DateFormat. The specified TimeType
type determines the type of and order of tokens returned. If the given DateFormat or string
does not provide a required token a default value will be used.

Returns a 2-element tuple `(values, pos)`:
* `values::Nullable{Tuple}`: A tuple which contains a values for each token as specified by
* `values::Nullable{Tuple}`: A tuple which contains a value for each token as specified by
the passed in type.
* `pos::Int`: The character index at which parsing stopped.
"""
Expand Down