Skip to content

Commit 8f97e6e

Browse files
omustkelman
authored andcommitted
Cleanup function signatures using DateLocale (#21011)
1 parent 4eb8c06 commit 8f97e6e

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

base/dates/io.jl

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ default_format(::Type{DateTime}) = ISODateTimeFormat
386386
default_format(::Type{Date}) = ISODateFormat
387387

388388
### API
389+
390+
const Locale = Union{DateLocale, String}
391+
389392
"""
390393
DateTime(dt::AbstractString, format::AbstractString; locale="english") -> DateTime
391394
@@ -396,8 +399,9 @@ This method creates a `DateFormat` object each time it is called. If you are par
396399
date strings of the same format, consider creating a [`DateFormat`](@ref) object once and using
397400
that as the second argument instead.
398401
"""
399-
DateTime(dt::AbstractString, format::AbstractString;
400-
locale::Union{DateLocale, String}=ENGLISH) = parse(DateTime, dt, DateFormat(format, locale))
402+
function DateTime(dt::AbstractString, format::AbstractString; locale::Locale=ENGLISH)
403+
parse(DateTime, dt, DateFormat(format, locale))
404+
end
401405

402406
"""
403407
DateTime(dt::AbstractString, df::DateFormat) -> DateTime
@@ -416,8 +420,9 @@ Construct a `Date` object by parsing a `dt` date string following the pattern gi
416420
`format` string. Follows the same conventions as
417421
`DateTime(::AbstractString, ::AbstractString)`.
418422
"""
419-
Date(dt::AbstractString, format::AbstractString;
420-
locale::Union{DateLocale, String}=ENGLISH) = parse(Date, dt, DateFormat(format, locale))
423+
function Date(dt::AbstractString, format::AbstractString; locale::Locale=ENGLISH)
424+
parse(Date, dt, DateFormat(format, locale))
425+
end
421426

422427
"""
423428
Date(dt::AbstractString, df::DateFormat) -> Date
@@ -476,8 +481,9 @@ generate the string "1996-01-15T00:00:00" you could use `format`: "yyyy-mm-ddTHH
476481
Note that if you need to use a code character as a literal you can use the escape character
477482
backslash. The string "1996y01m" can be produced with the format "yyyy\\ymm\\m".
478483
"""
479-
format(dt::TimeType, f::AbstractString;
480-
locale::Union{DateLocale, String}=ENGLISH) = format(dt, DateFormat(f, locale))
484+
function format(dt::TimeType, f::AbstractString; locale::Locale=ENGLISH)
485+
format(dt, DateFormat(f, locale))
486+
end
481487

482488
# show
483489

@@ -512,22 +518,22 @@ function Base.string(dt::Date)
512518
end
513519

514520
# vectorized
515-
DateTime(Y::AbstractArray{<:AbstractString}, format::AbstractString;
516-
locale::Union{DateLocale, String}=ENGLISH) = DateTime(Y, DateFormat(format, locale))
521+
function DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH)
522+
DateTime(Y, DateFormat(f, locale))
523+
end
517524
function DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat)
518525
return reshape(DateTime[parse(DateTime, y, df) for y in Y], size(Y))
519526
end
520-
Date(Y::AbstractArray{<:AbstractString}, format::AbstractString;
521-
locale::Union{DateLocale, String}=ENGLISH) = Date(Y, DateFormat(format, locale))
527+
function Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH)
528+
Date(Y, DateFormat(f, locale))
529+
end
522530
function Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat)
523531
return reshape(Date[Date(parse(Date, y, df)) for y in Y], size(Y))
524532
end
525533

526-
format(Y::AbstractArray{<:TimeType}, fmt::AbstractString;
527-
locale::Union{DateLocale, String}=ENGLISH) = format(Y, DateFormat(fmt, locale))
528-
function format(Y::AbstractArray{Date}, df::DateFormat=ISODateFormat)
529-
return reshape([format(y, df) for y in Y], size(Y))
534+
function format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH)
535+
format(Y, DateFormat(f, locale))
530536
end
531-
function format(Y::AbstractArray{DateTime}, df::DateFormat=ISODateTimeFormat)
537+
function format{T<:TimeType}(Y::AbstractArray{T}, df::DateFormat=default_format(T))
532538
return reshape([format(y, df) for y in Y], size(Y))
533539
end

0 commit comments

Comments
 (0)