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

move Dates to stdlib #24459

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1358,6 +1276,12 @@ export conv, conv2, deconv, filt, filt!, xcorr

@deprecate_moved crc32c "CRC32c" 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 @@ -1484,26 +1408,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 @@ -1719,11 +1623,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 @@ -2185,17 +2084,6 @@ end
@deprecate parse(str::AbstractString, pos::Int, ; kwargs...) Meta.parse(str, pos; kwargs...)
@deprecate_binding ParseError Meta.ParseError

# #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)

@eval LinAlg begin
@deprecate chol!(x::Number, uplo) chol(x) false
end
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
20 changes: 19 additions & 1 deletion base/libgit2/signature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,28 @@ function Base.convert(::Type{GitSignature}, sig::Signature)
return GitSignature(sig_ptr_ptr[])
end

function yearmonthday(days)
z = days + 306; h = 100z - 25; a = fld(h, 3652425); b = a - fld(a, 4)
y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153)
d = c - div(153m - 457, 5); return m > 12 ? (y + 1, m - 12, d) : (y, m, d)
end
lpad0(x) = lpad(x, 2, '0')

function unix2date(t)
UNIXEPOCH = 62135683200000
rata = UNIXEPOCH + round(Int64, Int64(1000) * t)
year, month, day = yearmonthday(fld(rata, 86400000))
secs = t % (24 * 60 * 60)
mins = div(secs, 60)
m, d = lpad0(month), lpad0(day)
h, mi, s = lpad0.(round.(Int, (div(mins, 60), mins % 60, secs % 60)))
return "$year-$m-$d $h:$mi:$s"
end

function Base.show(io::IO, sig::Signature)
print(io, "Name: ", sig.name, ", ")
print(io, "Email: ", sig.email, ", ")
print(io, "Time: ", Dates.unix2datetime(sig.time + 60*sig.time_offset))
print(io, "Time: ", unix2date(sig.time + 60*sig.time_offset))
@printf(io, "%+03i:%02i", divrem(sig.time_offset, 60)...)
end

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)
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

What decides if an stdlib package should be required here or not?

Copy link
Member

Choose a reason for hiding this comment

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

Anyone know the answer here? @JeffBezanson?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

These are to reduce startup/load time.


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 @@ -29,6 +29,7 @@ if Sys.iswindows()
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/CRC32c/docs/src/index.md", "src/stdlib/crc32c.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 @@ -38,6 +39,7 @@ else
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/CRC32c/docs/src/index.md", "src/stdlib/crc32c.md")
symlink_q("../../../stdlib/Dates/docs/src/index.md", "src/stdlib/dates.md")
end

const PAGES = [
Expand Down Expand Up @@ -146,11 +148,11 @@ const PAGES = [
],
]

using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, CRC32c
using DelimitedFiles, Test, Mmap, SharedArrays, Profile, Base64, FileWatching, CRC32c, 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: 1 addition & 0 deletions doc/src/stdlib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ profile.md
base64.md
filewatching.md
crc32c.md
dates.md

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