Skip to content

Commit

Permalink
wip move Dates to stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Nov 6, 2017
1 parent d929f0b commit 9d466fe
Show file tree
Hide file tree
Showing 40 changed files with 378 additions and 373 deletions.
124 changes: 6 additions & 118 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,6 @@ end
# base/complex.jl
@dep_vectorize_1arg Complex round
@dep_vectorize_1arg Complex float
# base/dates/*.jl
for f in (:unix2datetime, :rata2datetime, :julian2datetime) # base/dates/conversions.jl
@eval Dates Base.@dep_vectorize_1arg Real $f
end
for f in (
# base/dates/accessors.jl
:year, :month, :day, :week, :dayofmonth, :yearmonth, :monthday, :yearmonthday,
# base/dates/adjusters.jl
:firstdayofweek, :lastdayofweek, :firstdayofmonth,
:lastdayofmonth, :firstdayofyear, :lastdayofyear,
:firstdayofquarter, :lastdayofquarter,
# base/dates/query.jl
:dayname, :dayabbr, :dayofweek, :dayofweekofmonth,
:daysofweekinmonth, :monthname, :monthabbr, :daysinmonth,
:isleapyear, :dayofyear, :daysinyear, :quarterofyear, :dayofquarter,
)
@eval Dates Base.@dep_vectorize_1arg Dates.TimeType $f
end
for f in (
:hour, :minute, :second, :millisecond, # base/dates/accessors.jl
:Date, :datetime2unix, :datetime2rata, :datetime2julian, # base/dates/conversions.jl
)
@eval Dates Base.@dep_vectorize_1arg Dates.DateTime $f
end
@eval Dates Base.@dep_vectorize_1arg Dates.Date Datetime # base/dates/conversions.jl

# Deprecate @vectorize_2arg-vectorized functions from...
for f in (
Expand Down Expand Up @@ -477,19 +452,6 @@ end
@deprecate takebuf_array take!
@deprecate takebuf_string(b) String(take!(b))

# #19288
@eval Base.Dates begin
function recur(fun::Function, dr::StepRange{<:TimeType}; negate::Bool=false, limit::Int=10000)
Base.depwarn("Dates.recur is deprecated, use filter instead.",:recur)
if negate
filter(x -> !fun(x), dr)
else
filter(fun, dr)
end
end
recur(fun::Function, start::T, stop::T; step::Period=Day(1), negate::Bool=false, limit::Int=10000) where {T<:TimeType} = recur(fun, start:step:stop; negate=negate)
end

# Index conversions revamp; #19730
function getindex(A::LogicalIndex, i::Int)
depwarn("getindex(A::LogicalIndex, i) is deprecated; use iteration or index into the result of `collect(A)` instead.", :getindex)
Expand Down Expand Up @@ -790,12 +752,6 @@ import .Math: clamp
@deprecate rem(A::Number, B::AbstractArray) rem.(A, B)
@deprecate rem(A::AbstractArray, B::Number) rem.(A, B)

# Deprecate manually vectorized div, mod, and % methods for dates
@deprecate div(X::StridedArray{P}, y::P) where {P<:Dates.Period} div.(X, y)
@deprecate div(X::StridedArray{<:Dates.Period}, y::Integer) div.(X, y)
@deprecate (%)(X::StridedArray{P}, y::P) where {P<:Dates.Period} X .% y
@deprecate mod(X::StridedArray{P}, y::P) where {P<:Dates.Period} mod.(X, y)

# Deprecate manually vectorized mod methods in favor of compact broadcast syntax
@deprecate mod(B::BitArray, x::Bool) mod.(B, x)
@deprecate mod(x::Bool, B::BitArray) mod.(x, B)
Expand Down Expand Up @@ -993,19 +949,6 @@ end

@deprecate EachLine(stream, ondone) EachLine(stream, ondone=ondone)

# These conversions should not be defined, see #19896
@deprecate convert(::Type{T}, x::Dates.Period) where {T<:Number} convert(T, Dates.value(x))
@deprecate convert(::Type{T}, x::Real) where {T<:Dates.Period} T(x)
@deprecate convert(::Type{R}, x::Dates.DateTime) where {R<:Real} R(Dates.value(x))
@deprecate convert(::Type{R}, x::Dates.Date) where {R<:Real} R(Dates.value(x))
@deprecate convert(::Type{Dates.DateTime}, x::Real) Dates.DateTime(Dates.Millisecond(x))
@deprecate convert(::Type{Dates.Date}, x::Real) Dates.Date(Dates.Day(x))

function colon(start::T, stop::T) where T<:Dates.Period
depwarn("$start:$stop is deprecated, use $start:$T(1):$stop instead.", :colon)
colon(start, T(1), stop)
end

# LibGit2 refactor (#19839)
@eval Base.LibGit2 begin
Base.@deprecate_binding Oid GitHash
Expand All @@ -1030,20 +973,6 @@ end
Base.cat(repo::GitRepo, spec::Union{AbstractString,AbstractGitHash}) = cat(repo, GitBlob, spec)
end

# when this deprecation is deleted, remove all calls to it, and all
# negate=nothing keyword arguments, from base/dates/adjusters.jl
@eval Dates function deprecate_negate(f, func, sig, negate)
if negate === nothing
return func
else
msg = "$f($sig; negate=$negate) is deprecated, use $f("
negate && (msg *= "!")
msg *= "$sig) instead."
Base.depwarn(msg, f)
return negate ? !func : func
end
end

# TODO: remove `:typealias` from BINDING_HEADS in base/docs/Docs.jl
# TODO: remove `'typealias` case in expand-table in julia-syntax.scm

Expand Down Expand Up @@ -1169,17 +1098,6 @@ end
@deprecate_binding LinearSlow IndexCartesian false
@deprecate_binding linearindexing IndexStyle false

# #20876
@eval Base.Dates begin
function Base.Dates.parse(x::AbstractString, df::DateFormat)
Base.depwarn(string(
"`Dates.parse(x::AbstractString, df::DateFormat)` is deprecated, use ",
"`sort!(filter!(el -> isa(el, Dates.Period), Dates.parse_components(x, df), rev=true, lt=Dates.periodisless)` ",
" instead."), :parse)
sort!(filter!(el -> isa(el, Period), parse_components(x, df)), rev=true, lt=periodisless)
end
end

# #19635
for fname in (:ones, :zeros)
@eval @deprecate ($fname)(T::Type, arr) ($fname)(T, size(arr))
Expand Down Expand Up @@ -1354,6 +1272,12 @@ export conv, conv2, deconv, filt, filt!, xcorr
@deprecate_moved watch_file "FileWatching" true true
@deprecate_moved FileMonitor "FileWatching" true true

@deprecate_binding Dates nothing true ", run `using Dates` instead"
@deprecate_moved DateTime "Dates" true true
@deprecate_moved DateFormat "Dates" true true
@eval @deprecate_moved $(Symbol("@dateformat_str")) "Dates" true true
@deprecate_moved now "Dates" true true

# PR #21709
@deprecate cov(x::AbstractVector, corrected::Bool) cov(x, corrected=corrected)
@deprecate cov(x::AbstractMatrix, vardim::Int, corrected::Bool) cov(x, vardim, corrected=corrected)
Expand Down Expand Up @@ -1480,26 +1404,6 @@ for op in (:exp, :exp2, :exp10, :log, :log2, :log10,
@eval @deprecate ($op)(x::AbstractSparseVector{<:Number,<:Integer}) ($op).(x)
end

# deprecate remaining vectorized methods from Base.Dates
@eval Dates @deprecate(
DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH),
DateTime.(Y, f; locale=locale) )
@eval Dates @deprecate(
DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat),
DateTime.(Y, df) )
@eval Dates @deprecate(
Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH),
Date.(Y, f; locale=locale) )
@eval Dates @deprecate(
Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat),
Date.(Y, df) )
@eval Dates @deprecate(
format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH),
format.(Y, f; locale=locale) )
@eval Dates @deprecate(
format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where {T<:TimeType},
format.(Y, df) )

# PR #22182
@deprecate is_apple Sys.isapple
@deprecate is_bsd Sys.isbsd
Expand Down Expand Up @@ -1715,11 +1619,6 @@ import .Iterators.enumerate
@deprecate -(a::Number, b::AbstractArray) broadcast(-, a, b)
@deprecate -(a::AbstractArray, b::Number) broadcast(-, a, b)

@deprecate +(a::Dates.GeneralPeriod, b::StridedArray{<:Dates.GeneralPeriod}) broadcast(+, a, b)
@deprecate +(a::StridedArray{<:Dates.GeneralPeriod}, b::Dates.GeneralPeriod) broadcast(+, a, b)
@deprecate -(a::Dates.GeneralPeriod, b::StridedArray{<:Dates.GeneralPeriod}) broadcast(-, a, b)
@deprecate -(a::StridedArray{<:Dates.GeneralPeriod}, b::Dates.GeneralPeriod) broadcast(-, a, b)

# PR #23640
# when this deprecation is deleted, remove all calls to it, and replace all keywords of:
# `payload::Union{CredentialPayload,Nullable{<:AbstractCredentials}}` with
Expand Down Expand Up @@ -2073,17 +1972,6 @@ end
# issue #24167
@deprecate EnvHash EnvDict

# #24258
# Physical units define an equivalence class: there is no such thing as a step of "1" (is
# it one day or one second or one nanosecond?). So require the user to specify the step
# (in physical units).
@deprecate colon(start::T, stop::T) where {T<:DateTime} start:Dates.Day(1):stop
@deprecate colon(start::T, stop::T) where {T<:Date} start:Dates.Day(1):stop
@deprecate colon(start::T, stop::T) where {T<:Dates.Time} start:Dates.Second(1):stop

@deprecate range(start::DateTime, len::Integer) range(start, Dates.Day(1), len)
@deprecate range(start::Date, len::Integer) range(start, Dates.Day(1), len)

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export
Pkg,
LibGit2,
StackTraces,
Dates,
Sys,
Libc,
Libdl,
Expand Down
4 changes: 2 additions & 2 deletions base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ julia> one(3.7)
julia> one(Int)
1
julia> one(Dates.Day(1))
julia> import Dates; one(Dates.Day(1))
1
```
"""
Expand All @@ -285,7 +285,7 @@ while `oneunit` is dimensionful (of the same type as `x`, or of type `T`).
julia> oneunit(3.7)
1.0
julia> oneunit(Dates.Day)
julia> import Dates; oneunit(Dates.Day)
1 day
```
"""
Expand Down
5 changes: 1 addition & 4 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,6 @@ include("libgit2/libgit2.jl")
# package manager
include("pkg/pkg.jl")

# dates
include("dates/Dates.jl")
import .Dates: Date, DateTime, DateFormat, @dateformat_str, now

# sparse matrices, vectors, and sparse linear algebra
include("sparse/sparse.jl")
using .SparseArrays
Expand Down Expand Up @@ -473,6 +469,7 @@ unshift!(Base._included_files, (@__MODULE__, joinpath(@__DIR__, "sysimg.jl")))
# load some stdlib packages but don't put their names in Main
Base.require(:DelimitedFiles)
Base.require(:Test)
Base.require(:Dates)

empty!(LOAD_PATH)

Expand Down
6 changes: 4 additions & 2 deletions doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ if Sys.iswindows()
cp_q("../stdlib/Profile/docs/src/index.md", "src/stdlib/profile.md")
cp_q("../stdlib/Base64/docs/src/index.md", "src/stdlib/base64.md")
cp_q("../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md")
cp_q("../stdlib/Dates/docs/src/index.md", "src/stdlib/dates.md")
else
symlink_q("../../../stdlib/DelimitedFiles/docs/src/index.md", "src/stdlib/delimitedfiles.md")
symlink_q("../../../stdlib/Test/docs/src/index.md", "src/stdlib/test.md")
Expand All @@ -36,6 +37,7 @@ else
symlink_q("../../../stdlib/Profile/docs/src/index.md", "src/stdlib/profile.md")
symlink_q("../../../stdlib/Base64/docs/src/index.md", "src/stdlib/base64.md")
symlink_q("../../../stdlib/FileWatching/docs/src/index.md", "src/stdlib/filewatching.md")
symlink_q("../../../stdlib/Dates/docs/src/index.md", "src/stdlib/dates.md")
end

const PAGES = [
Expand Down Expand Up @@ -143,11 +145,11 @@ const PAGES = [
],
]

using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching
using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, Dates

makedocs(
build = joinpath(pwd(), "_build/html/en"),
modules = [Base, Core, BuildSysImg, DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching],
modules = [Base, Core, BuildSysImg, DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, Dates],
clean = false,
doctest = "doctest" in ARGS,
linkcheck = "linkcheck" in ARGS,
Expand Down
16 changes: 8 additions & 8 deletions doc/src/manual/dates.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Date and DateTime

```@meta
CurrentModule = Base.Dates
CurrentModule = Dates
```

The `Dates` module provides two types for working with dates: [`Date`](@ref) and [`DateTime`](@ref),
Expand Down Expand Up @@ -144,14 +144,14 @@ julia> dt2 = Date(2000,2,1)
julia> dump(dt)
Date
instant: Base.Dates.UTInstant{Base.Dates.Day}
periods: Base.Dates.Day
instant: Dates.UTInstant{Dates.Day}
periods: Dates.Day
value: Int64 734562
julia> dump(dt2)
Date
instant: Base.Dates.UTInstant{Base.Dates.Day}
periods: Base.Dates.Day
instant: Dates.UTInstant{Dates.Day}
periods: Dates.Day
value: Int64 730151
julia> dt > dt2
Expand Down Expand Up @@ -240,12 +240,12 @@ One may also access the underlying `UTInstant` or integer value:
```jldoctest tdate
julia> dump(t)
Date
instant: Base.Dates.UTInstant{Base.Dates.Day}
periods: Base.Dates.Day
instant: Dates.UTInstant{Dates.Day}
periods: Dates.Day
value: Int64 735264
julia> t.instant
Base.Dates.UTInstant{Base.Dates.Day}(735264 days)
Dates.UTInstant{Dates.Day}(735264 days)
julia> Dates.value(t)
735264
Expand Down
1 change: 0 additions & 1 deletion doc/src/stdlib/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ primitive type
## Base Modules
```@docs
Base.BLAS
Base.Dates
Base.Distributed
Base.Docs
Base.Iterators
Expand Down
Loading

0 comments on commit 9d466fe

Please sign in to comment.