From 0c0d6cca5d3793eaf6321ef0577afd6ce594a9b5 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Wed, 22 Nov 2017 07:10:46 -0800 Subject: [PATCH] move Dates to stdlib (#24459) * wip move Dates to stdlib * hack around libgit2 being in Base * unde beautiful hack and reimplement unix2datetime in LibGit2 --- base/deprecated.jl | 124 +---------- base/exports.jl | 1 - base/libgit2/signature.jl | 20 +- base/number.jl | 4 +- base/sysimg.jl | 5 +- doc/make.jl | 6 +- doc/src/manual/dates.md | 16 +- doc/src/stdlib/.gitignore | 1 + doc/src/stdlib/base.md | 1 - doc/src/stdlib/dates.md | 194 ------------------ stdlib/Dates/docs/src/index.md | 194 ++++++++++++++++++ {base/dates => stdlib/Dates/src}/Dates.jl | 1 + {base/dates => stdlib/Dates/src}/accessors.jl | 0 {base/dates => stdlib/Dates/src}/adjusters.jl | 39 ++-- .../dates => stdlib/Dates/src}/arithmetic.jl | 1 + .../dates => stdlib/Dates/src}/conversions.jl | 0 stdlib/Dates/src/deprecated.jl | 41 ++++ {base/dates => stdlib/Dates/src}/io.jl | 0 {base/dates => stdlib/Dates/src}/parse.jl | 0 {base/dates => stdlib/Dates/src}/periods.jl | 0 {base/dates => stdlib/Dates/src}/query.jl | 0 {base/dates => stdlib/Dates/src}/ranges.jl | 0 {base/dates => stdlib/Dates/src}/rounding.jl | 0 {base/dates => stdlib/Dates/src}/types.jl | 0 .../dates => stdlib/Dates/test}/accessors.jl | 7 + .../dates => stdlib/Dates/test}/adjusters.jl | 9 +- .../dates => stdlib/Dates/test}/arithmetic.jl | 7 + .../Dates/test}/conversions.jl | 7 + {test/dates => stdlib/Dates/test}/io.jl | 7 + {test/dates => stdlib/Dates/test}/periods.jl | 7 + {test/dates => stdlib/Dates/test}/query.jl | 7 + {test/dates => stdlib/Dates/test}/ranges.jl | 12 ++ {test/dates => stdlib/Dates/test}/rounding.jl | 8 + stdlib/Dates/test/runtests.jl | 17 ++ {test/dates => stdlib/Dates/test}/types.jl | 7 + test/channels.jl | 1 + test/choosetests.jl | 13 +- test/compile.jl | 2 +- test/core.jl | 3 + test/nullable.jl | 3 +- test/ranges.jl | 2 + test/threads.jl | 2 + 42 files changed, 397 insertions(+), 372 deletions(-) delete mode 100644 doc/src/stdlib/dates.md create mode 100644 stdlib/Dates/docs/src/index.md rename {base/dates => stdlib/Dates/src}/Dates.jl (99%) rename {base/dates => stdlib/Dates/src}/accessors.jl (100%) rename {base/dates => stdlib/Dates/src}/adjusters.jl (89%) rename {base/dates => stdlib/Dates/src}/arithmetic.jl (99%) rename {base/dates => stdlib/Dates/src}/conversions.jl (100%) create mode 100644 stdlib/Dates/src/deprecated.jl rename {base/dates => stdlib/Dates/src}/io.jl (100%) rename {base/dates => stdlib/Dates/src}/parse.jl (100%) rename {base/dates => stdlib/Dates/src}/periods.jl (100%) rename {base/dates => stdlib/Dates/src}/query.jl (100%) rename {base/dates => stdlib/Dates/src}/ranges.jl (100%) rename {base/dates => stdlib/Dates/src}/rounding.jl (100%) rename {base/dates => stdlib/Dates/src}/types.jl (100%) rename {test/dates => stdlib/Dates/test}/accessors.jl (99%) rename {test/dates => stdlib/Dates/test}/adjusters.jl (99%) rename {test/dates => stdlib/Dates/test}/arithmetic.jl (99%) rename {test/dates => stdlib/Dates/test}/conversions.jl (99%) rename {test/dates => stdlib/Dates/test}/io.jl (99%) rename {test/dates => stdlib/Dates/test}/periods.jl (99%) rename {test/dates => stdlib/Dates/test}/query.jl (99%) rename {test/dates => stdlib/Dates/test}/ranges.jl (98%) rename {test/dates => stdlib/Dates/test}/rounding.jl (99%) create mode 100644 stdlib/Dates/test/runtests.jl rename {test/dates => stdlib/Dates/test}/types.jl (99%) diff --git a/base/deprecated.jl b/base/deprecated.jl index f05f28b10c117..49c06ba592219 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 ( @@ -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) @@ -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) @@ -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 @@ -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 @@ -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)) @@ -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) @@ -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 @@ -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 @@ -2195,17 +2094,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 diff --git a/base/exports.jl b/base/exports.jl index 72dc7c7112062..2855c72738a0a 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -6,7 +6,6 @@ export Pkg, LibGit2, StackTraces, - Dates, Sys, Libc, Libdl, diff --git a/base/libgit2/signature.jl b/base/libgit2/signature.jl index fb099efb07d38..3804d81a23bd3 100644 --- a/base/libgit2/signature.jl +++ b/base/libgit2/signature.jl @@ -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 diff --git a/base/number.jl b/base/number.jl index b3336751a3f63..18bee75b761cd 100644 --- a/base/number.jl +++ b/base/number.jl @@ -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 ``` """ @@ -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 ``` """ diff --git a/base/sysimg.jl b/base/sysimg.jl index 0a3963d4872a2..0892a35b4a001 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -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 @@ -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) diff --git a/doc/make.jl b/doc/make.jl index a7b5bdeed75f0..bd02e1b0e59c1 100644 --- a/doc/make.jl +++ b/doc/make.jl @@ -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") @@ -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 = [ @@ -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, diff --git a/doc/src/manual/dates.md b/doc/src/manual/dates.md index 7281fb412ba18..7764fdbc26d4c 100644 --- a/doc/src/manual/dates.md +++ b/doc/src/manual/dates.md @@ -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), @@ -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 @@ -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 diff --git a/doc/src/stdlib/.gitignore b/doc/src/stdlib/.gitignore index 46adf75aa1777..e04ac81b650d4 100644 --- a/doc/src/stdlib/.gitignore +++ b/doc/src/stdlib/.gitignore @@ -6,4 +6,5 @@ profile.md base64.md filewatching.md crc32c.md +dates.md diff --git a/doc/src/stdlib/base.md b/doc/src/stdlib/base.md index c65875e8be06b..cb34c7bfd9120 100644 --- a/doc/src/stdlib/base.md +++ b/doc/src/stdlib/base.md @@ -89,7 +89,6 @@ primitive type ## Base Modules ```@docs Base.BLAS -Base.Dates Base.Distributed Base.Docs Base.Iterators diff --git a/doc/src/stdlib/dates.md b/doc/src/stdlib/dates.md deleted file mode 100644 index 55c2edab749f1..0000000000000 --- a/doc/src/stdlib/dates.md +++ /dev/null @@ -1,194 +0,0 @@ -# [Dates and Time](@id stdlib-dates) - -## Dates and Time Types - -```@docs -Base.Dates.Period -Base.Dates.CompoundPeriod -Base.Dates.Instant -Base.Dates.UTInstant -Base.Dates.TimeType -Base.Dates.DateTime -Base.Dates.Date -Base.Dates.Time -``` - -## Dates Functions - -All Dates functions are defined in the `Dates` module; note that only the `Date`, `DateTime`, -and `now` functions are exported; to use all other `Dates` functions, you'll need to prefix each -function call with an explicit `Dates.`, e.g. `Dates.dayofweek(dt)`. Alternatively, you can write -`using Base.Dates` to bring all exported functions into `Main` to be used without the `Dates.` -prefix. - -```@docs -Base.Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64) -Base.Dates.DateTime(::Base.Dates.Period...) -Base.Dates.DateTime(::Function, ::Any...) -Base.Dates.DateTime(::Base.Dates.TimeType) -Base.Dates.DateTime(::AbstractString, ::AbstractString) -Base.Dates.format(::Base.Dates.TimeType, ::AbstractString) -Base.Dates.DateFormat -Base.Dates.@dateformat_str -Base.Dates.DateTime(::AbstractString, ::Base.Dates.DateFormat) -Base.Dates.Date(::Int64, ::Int64, ::Int64) -Base.Dates.Date(::Base.Dates.Period...) -Base.Dates.Date(::Function, ::Any, ::Any, ::Any) -Base.Dates.Date(::Base.Dates.TimeType) -Base.Dates.Date(::AbstractString, ::AbstractString) -Base.Dates.Date(::AbstractString, ::Base.Dates.DateFormat) -Base.Dates.Time(::Int64::Int64, ::Int64, ::Int64, ::Int64, ::Int64) -Base.Dates.Time(::Base.Dates.TimePeriod...) -Base.Dates.Time(::Function, ::Any...) -Base.Dates.Time(::Base.Dates.DateTime) -Base.Dates.now() -Base.Dates.now(::Type{Base.Dates.UTC}) -Base.eps -``` - -### Accessor Functions - -```@docs -Base.Dates.year -Base.Dates.month -Base.Dates.week -Base.Dates.day -Base.Dates.hour -Base.Dates.minute -Base.Dates.second -Base.Dates.millisecond -Base.Dates.microsecond -Base.Dates.nanosecond -Base.Dates.Year(::Base.Dates.TimeType) -Base.Dates.Month(::Base.Dates.TimeType) -Base.Dates.Week(::Base.Dates.TimeType) -Base.Dates.Day(::Base.Dates.TimeType) -Base.Dates.Hour(::DateTime) -Base.Dates.Minute(::DateTime) -Base.Dates.Second(::DateTime) -Base.Dates.Millisecond(::DateTime) -Base.Dates.Microsecond(::Dates.Time) -Base.Dates.Nanosecond(::Dates.Time) -Base.Dates.yearmonth -Base.Dates.monthday -Base.Dates.yearmonthday -``` - -### Query Functions - -```@docs -Base.Dates.dayname -Base.Dates.dayabbr -Base.Dates.dayofweek -Base.Dates.dayofmonth -Base.Dates.dayofweekofmonth -Base.Dates.daysofweekinmonth -Base.Dates.monthname -Base.Dates.monthabbr -Base.Dates.daysinmonth -Base.Dates.isleapyear -Base.Dates.dayofyear -Base.Dates.daysinyear -Base.Dates.quarterofyear -Base.Dates.dayofquarter -``` - -### Adjuster Functions - -```@docs -Base.trunc(::Base.Dates.TimeType, ::Type{Base.Dates.Period}) -Base.Dates.firstdayofweek -Base.Dates.lastdayofweek -Base.Dates.firstdayofmonth -Base.Dates.lastdayofmonth -Base.Dates.firstdayofyear -Base.Dates.lastdayofyear -Base.Dates.firstdayofquarter -Base.Dates.lastdayofquarter -Base.Dates.tonext(::Base.Dates.TimeType, ::Int) -Base.Dates.toprev(::Base.Dates.TimeType, ::Int) -Base.Dates.tofirst -Base.Dates.tolast -Base.Dates.tonext(::Function, ::Base.Dates.TimeType) -Base.Dates.toprev(::Function, ::Base.Dates.TimeType) -``` - -### Periods - -```@docs -Base.Dates.Period(::Any) -Base.Dates.CompoundPeriod(::Vector{<:Base.Dates.Period}) -Base.Dates.default -``` - -### Rounding Functions - -`Date` and `DateTime` values can be rounded to a specified resolution (e.g., 1 month or 15 minutes) -with `floor`, `ceil`, or `round`. - -```@docs -Base.floor(::Base.Dates.TimeType, ::Base.Dates.Period) -Base.ceil(::Base.Dates.TimeType, ::Base.Dates.Period) -Base.round(::Base.Dates.TimeType, ::Base.Dates.Period, ::RoundingMode{:NearestTiesUp}) -``` - -Most `Period` values can also be rounded to a specified resolution: - -```@docs -Base.floor(::Base.Dates.ConvertiblePeriod, ::T) where T <: Base.Dates.ConvertiblePeriod -Base.ceil(::Base.Dates.ConvertiblePeriod, ::Base.Dates.ConvertiblePeriod) -Base.round(::Base.Dates.ConvertiblePeriod, ::Base.Dates.ConvertiblePeriod, ::RoundingMode{:NearestTiesUp}) -``` - -The following functions are not exported: - -```@docs -Base.Dates.floorceil -Base.Dates.epochdays2date -Base.Dates.epochms2datetime -Base.Dates.date2epochdays -Base.Dates.datetime2epochms -``` - -### Conversion Functions - -```@docs -Base.Dates.today -Base.Dates.unix2datetime -Base.Dates.datetime2unix -Base.Dates.julian2datetime -Base.Dates.datetime2julian -Base.Dates.rata2datetime -Base.Dates.datetime2rata -``` - -### Constants - -Days of the Week: - -| Variable | Abbr. | Value (Int) | -|:----------- |:----- |:----------- | -| `Monday` | `Mon` | 1 | -| `Tuesday` | `Tue` | 2 | -| `Wednesday` | `Wed` | 3 | -| `Thursday` | `Thu` | 4 | -| `Friday` | `Fri` | 5 | -| `Saturday` | `Sat` | 6 | -| `Sunday` | `Sun` | 7 | - -Months of the Year: - -| Variable | Abbr. | Value (Int) | -|:----------- |:----- |:----------- | -| `January` | `Jan` | 1 | -| `February` | `Feb` | 2 | -| `March` | `Mar` | 3 | -| `April` | `Apr` | 4 | -| `May` | `May` | 5 | -| `June` | `Jun` | 6 | -| `July` | `Jul` | 7 | -| `August` | `Aug` | 8 | -| `September` | `Sep` | 9 | -| `October` | `Oct` | 10 | -| `November` | `Nov` | 11 | -| `December` | `Dec` | 12 | diff --git a/stdlib/Dates/docs/src/index.md b/stdlib/Dates/docs/src/index.md new file mode 100644 index 0000000000000..d0c833779e082 --- /dev/null +++ b/stdlib/Dates/docs/src/index.md @@ -0,0 +1,194 @@ +# [Dates and Time](@id stdlib-dates) + +Functionality to handle time and dates are defined in the standard library module `Dates`. +You'll need to import the module using `import Dates` and prefix each +function call with an explicit `Dates.`, e.g. `Dates.dayofweek(dt)`. Alternatively, You can write +`using Dates` to bring all exported functions into `Main` to be used without the `Dates.` +prefix. + +## Dates and Time Types + +```@docs +Dates.Period +Dates.CompoundPeriod +Dates.Instant +Dates.UTInstant +Dates.TimeType +Dates.DateTime +Dates.Date +Dates.Time +``` + +## Dates Functions + +```@docs +Dates.DateTime(::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64, ::Int64) +Dates.DateTime(::Dates.Period...) +Dates.DateTime(::Function, ::Any...) +Dates.DateTime(::Dates.TimeType) +Dates.DateTime(::AbstractString, ::AbstractString) +Dates.format +Dates.DateFormat +Dates.@dateformat_str +Dates.DateTime(::AbstractString, ::Dates.DateFormat) +Dates.Date(::Int64, ::Int64, ::Int64) +Dates.Date(::Dates.Period...) +Dates.Date(::Function, ::Any, ::Any, ::Any) +Dates.Date(::Dates.TimeType) +Dates.Date(::AbstractString, ::AbstractString) +Dates.Date(::AbstractString, ::Dates.DateFormat) +Dates.Time(::Int64::Int64, ::Int64, ::Int64, ::Int64, ::Int64) +Dates.Time(::Dates.TimePeriod...) +Dates.Time(::Function, ::Any...) +Dates.Time(::Dates.DateTime) +Dates.now() +Dates.now(::Type{Dates.UTC}) +Base.eps +``` + +### Accessor Functions + +```@docs +Dates.year +Dates.month +Dates.week +Dates.day +Dates.hour +Dates.minute +Dates.second +Dates.millisecond +Dates.microsecond +Dates.nanosecond +Dates.Year(::Dates.TimeType) +Dates.Month(::Dates.TimeType) +Dates.Week(::Dates.TimeType) +Dates.Day(::Dates.TimeType) +Dates.Hour(::DateTime) +Dates.Minute(::DateTime) +Dates.Second(::DateTime) +Dates.Millisecond(::DateTime) +Dates.Microsecond(::Dates.Time) +Dates.Nanosecond(::Dates.Time) +Dates.yearmonth +Dates.monthday +Dates.yearmonthday +``` + +### Query Functions + +```@docs +Dates.dayname +Dates.dayabbr +Dates.dayofweek +Dates.dayofmonth +Dates.dayofweekofmonth +Dates.daysofweekinmonth +Dates.monthname +Dates.monthabbr +Dates.daysinmonth +Dates.isleapyear +Dates.dayofyear +Dates.daysinyear +Dates.quarterofyear +Dates.dayofquarter +``` + +### Adjuster Functions + +```@docs +Base.trunc(::Dates.TimeType, ::Type{Dates.Period}) +Dates.firstdayofweek +Dates.lastdayofweek +Dates.firstdayofmonth +Dates.lastdayofmonth +Dates.firstdayofyear +Dates.lastdayofyear +Dates.firstdayofquarter +Dates.lastdayofquarter +Dates.tonext(::Dates.TimeType, ::Int) +Dates.toprev(::Dates.TimeType, ::Int) +Dates.tofirst +Dates.tolast +Dates.tonext(::Function, ::Dates.TimeType) +Dates.toprev(::Function, ::Dates.TimeType) +``` + +### Periods + +```@docs +Dates.Period(::Any) +Dates.CompoundPeriod(::Vector{<:Dates.Period}) +Dates.default +``` + +### Rounding Functions + +`Date` and `DateTime` values can be rounded to a specified resolution (e.g., 1 month or 15 minutes) +with `floor`, `ceil`, or `round`. + +```@docs +Base.floor(::Dates.TimeType, ::Dates.Period) +Base.ceil(::Dates.TimeType, ::Dates.Period) +Base.round(::Dates.TimeType, ::Dates.Period, ::RoundingMode{:NearestTiesUp}) +``` + +Most `Period` values can also be rounded to a specified resolution: + +```@docs +Base.floor(::Dates.ConvertiblePeriod, ::T) where T <: Dates.ConvertiblePeriod +Base.ceil(::Dates.ConvertiblePeriod, ::Dates.ConvertiblePeriod) +Base.round(::Dates.ConvertiblePeriod, ::Dates.ConvertiblePeriod, ::RoundingMode{:NearestTiesUp}) +``` + +The following functions are not exported: + +```@docs +Dates.floorceil +Dates.epochdays2date +Dates.epochms2datetime +Dates.date2epochdays +Dates.datetime2epochms +``` + +### Conversion Functions + +```@docs +Dates.today +Dates.unix2datetime +Dates.datetime2unix +Dates.julian2datetime +Dates.datetime2julian +Dates.rata2datetime +Dates.datetime2rata +``` + +### Constants + +Days of the Week: + +| Variable | Abbr. | Value (Int) | +|:----------- |:----- |:----------- | +| `Monday` | `Mon` | 1 | +| `Tuesday` | `Tue` | 2 | +| `Wednesday` | `Wed` | 3 | +| `Thursday` | `Thu` | 4 | +| `Friday` | `Fri` | 5 | +| `Saturday` | `Sat` | 6 | +| `Sunday` | `Sun` | 7 | + +Months of the Year: + +| Variable | Abbr. | Value (Int) | +|:----------- |:----- |:----------- | +| `January` | `Jan` | 1 | +| `February` | `Feb` | 2 | +| `March` | `Mar` | 3 | +| `April` | `Apr` | 4 | +| `May` | `May` | 5 | +| `June` | `Jun` | 6 | +| `July` | `Jul` | 7 | +| `August` | `Aug` | 8 | +| `September` | `Sep` | 9 | +| `October` | `Oct` | 10 | +| `November` | `Nov` | 11 | +| `December` | `Dec` | 12 | diff --git a/base/dates/Dates.jl b/stdlib/Dates/src/Dates.jl similarity index 99% rename from base/dates/Dates.jl rename to stdlib/Dates/src/Dates.jl index 44ed2aefa7972..6001e4d60d28b 100644 --- a/base/dates/Dates.jl +++ b/stdlib/Dates/src/Dates.jl @@ -48,6 +48,7 @@ include("adjusters.jl") include("rounding.jl") include("io.jl") include("parse.jl") +include("deprecated.jl") export Period, DatePeriod, TimePeriod, Year, Month, Week, Day, Hour, Minute, Second, Millisecond, diff --git a/base/dates/accessors.jl b/stdlib/Dates/src/accessors.jl similarity index 100% rename from base/dates/accessors.jl rename to stdlib/Dates/src/accessors.jl diff --git a/base/dates/adjusters.jl b/stdlib/Dates/src/adjusters.jl similarity index 89% rename from base/dates/adjusters.jl rename to stdlib/Dates/src/adjusters.jl index 44c66ac695994..4687b22badad5 100644 --- a/base/dates/adjusters.jl +++ b/stdlib/Dates/src/adjusters.jl @@ -202,8 +202,7 @@ function adjust(df::DateFunction, start, step, limit) throw(ArgumentError("Adjustment limit reached: $limit iterations")) end -function adjust(func::Function, start; step::Period=Day(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:adjust, func, "func,start", negate) +function adjust(func::Function, start; step::Period=Day(1), limit::Int=10000) return adjust(DateFunction(func, start), start, step, limit) end @@ -232,8 +231,7 @@ Stacktrace: [...] ``` """ -function Date(func::Function, y, m=1, d=1; step::Period=Day(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:Date, func, "func,y,m,d", negate) +function Date(func::Function, y, m=1, d=1; step::Period=Day(1), limit::Int=10000) return adjust(DateFunction(func, Date(y, m, d)), Date(y, m, d), step, limit) end @@ -259,24 +257,19 @@ Stacktrace: """ DateTime(::Function, args...) -function DateTime(func::Function, y, m=1; step::Period=Day(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:DateTime, func, "func,y,m", negate) +function DateTime(func::Function, y, m=1; step::Period=Day(1), limit::Int=10000) return adjust(DateFunction(func, DateTime(y, m)), DateTime(y, m), step, limit) end -function DateTime(func::Function, y, m, d; step::Period=Hour(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:DateTime, func, "func,y,m,d", negate) +function DateTime(func::Function, y, m, d; step::Period=Hour(1), limit::Int=10000) return adjust(DateFunction(func, DateTime(y)), DateTime(y, m, d), step, limit) end -function DateTime(func::Function, y, m, d, h; step::Period=Minute(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:DateTime, func, "func,y,m,d,h", negate) +function DateTime(func::Function, y, m, d, h; step::Period=Minute(1), limit::Int=10000) return adjust(DateFunction(func, DateTime(y)), DateTime(y, m, d, h), step, limit) end -function DateTime(func::Function, y, m, d, h, mi; step::Period=Second(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:DateTime, func, "func,y,m,d,h,mi", negate) +function DateTime(func::Function, y, m, d, h, mi; step::Period=Second(1), limit::Int=10000) return adjust(DateFunction(func, DateTime(y)), DateTime(y, m, d, h, mi), step, limit) end -function DateTime(func::Function, y, m, d, h, mi, s; step::Period=Millisecond(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:DateTime, func, "func,y,m,d,h,mi,s", negate) +function DateTime(func::Function, y, m, d, h, mi, s; step::Period=Millisecond(1), limit::Int=10000) return adjust(DateFunction(func, DateTime(y)), DateTime(y, m, d, h, mi, s), step, limit) end @@ -310,20 +303,16 @@ Stacktrace: """ Time(::Function, args...) -function Time(func::Function, h, mi=0; step::Period=Second(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:Time, func, "func,h,mi", negate) +function Time(func::Function, h, mi=0; step::Period=Second(1), limit::Int=10000) return adjust(DateFunction(func, Time(h, mi)), Time(h, mi), step, limit) end -function Time(func::Function, h, mi, s; step::Period=Millisecond(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:Time, func, "func,h,mi,s", negate) +function Time(func::Function, h, mi, s; step::Period=Millisecond(1), limit::Int=10000) return adjust(DateFunction(func, Time(h, mi, s)), Time(h, mi, s), step, limit) end -function Time(func::Function, h, mi, s, ms; step::Period=Microsecond(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:Time, func, "func,h,mi,s,ms", negate) +function Time(func::Function, h, mi, s, ms; step::Period=Microsecond(1), limit::Int=10000) return adjust(DateFunction(func, Time(h, mi, s, ms)), Time(h, mi, s, ms), step, limit) end -function Time(func::Function, h, mi, s, ms, us; step::Period=Nanosecond(1), negate=nothing, limit::Int=10000) - func = deprecate_negate(:Time, func, "func,h,mi,s,ms,us", negate) +function Time(func::Function, h, mi, s, ms, us; step::Period=Nanosecond(1), limit::Int=10000) return adjust(DateFunction(func, Time(h, mi, s, ms, us)), Time(h, mi, s, ms, us), step, limit) end @@ -354,8 +343,7 @@ Adjusts `dt` by iterating at most `limit` iterations by `step` increments until returns `true`. `func` must take a single `TimeType` argument and return a [`Bool`](@ref). `same` allows `dt` to be considered in satisfying `func`. """ -function tonext(func::Function, dt::TimeType; step::Period=Day(1), negate=nothing, limit::Int=10000, same::Bool=false) - func = deprecate_negate(:tonext, func, "func,dt", negate) +function tonext(func::Function, dt::TimeType; step::Period=Day(1), limit::Int=10000, same::Bool=false) return adjust(DateFunction(func, dt), same ? dt : dt + step, step, limit) end @@ -375,8 +363,7 @@ Adjusts `dt` by iterating at most `limit` iterations by `step` increments until returns `true`. `func` must take a single `TimeType` argument and return a [`Bool`](@ref). `same` allows `dt` to be considered in satisfying `func`. """ -function toprev(func::Function, dt::TimeType; step::Period=Day(-1), negate=nothing, limit::Int=10000, same::Bool=false) - func = deprecate_negate(:toprev, func, "func,dt", negate) +function toprev(func::Function, dt::TimeType; step::Period=Day(-1), limit::Int=10000, same::Bool=false) return adjust(DateFunction(func, dt), same ? dt : dt + step, step, limit) end diff --git a/base/dates/arithmetic.jl b/stdlib/Dates/src/arithmetic.jl similarity index 99% rename from base/dates/arithmetic.jl rename to stdlib/Dates/src/arithmetic.jl index 028a5fa6ff20a..c1c1a623533b7 100644 --- a/base/dates/arithmetic.jl +++ b/stdlib/Dates/src/arithmetic.jl @@ -54,6 +54,7 @@ function (+)(dt::DateTime, z::Month) mm = monthwrap(m, value(z)); ld = daysinmonth(ny, mm) return DateTime(ny, mm, d <= ld ? d : ld, hour(dt), minute(dt), second(dt), millisecond(dt)) end + function (+)(dt::Date, z::Month) y,m,d = yearmonthday(dt) ny = yearwrap(y, m, value(z)) diff --git a/base/dates/conversions.jl b/stdlib/Dates/src/conversions.jl similarity index 100% rename from base/dates/conversions.jl rename to stdlib/Dates/src/conversions.jl diff --git a/stdlib/Dates/src/deprecated.jl b/stdlib/Dates/src/deprecated.jl new file mode 100644 index 0000000000000..e048d9eeee043 --- /dev/null +++ b/stdlib/Dates/src/deprecated.jl @@ -0,0 +1,41 @@ +# 0.7 deprecations + +import Base.colon +import Base.range + +# deprecate remaining vectorized methods from Dates +@deprecate( + DateTime(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH), + DateTime.(Y, f; locale=locale) ) +@deprecate( + DateTime(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateTimeFormat), + DateTime.(Y, df) ) +@deprecate( + Date(Y::AbstractArray{<:AbstractString}, f::AbstractString; locale::Locale=ENGLISH), + Date.(Y, f; locale=locale) ) +@deprecate( + Date(Y::AbstractArray{<:AbstractString}, df::DateFormat=ISODateFormat), + Date.(Y, df) ) +@deprecate( + format(Y::AbstractArray{<:TimeType}, f::AbstractString; locale::Locale=ENGLISH), + format.(Y, f; locale=locale) ) +@deprecate( + format(Y::AbstractArray{T}, df::DateFormat=default_format(T)) where {T<:TimeType}, + format.(Y, df) ) + +@deprecate +(a::GeneralPeriod, b::StridedArray{<:GeneralPeriod}) broadcast(+, a, b) +@deprecate +(a::StridedArray{<:GeneralPeriod}, b::GeneralPeriod) broadcast(+, a, b) +@deprecate -(a::GeneralPeriod, b::StridedArray{<:GeneralPeriod}) broadcast(-, a, b) +@deprecate -(a::StridedArray{<:GeneralPeriod}, b::GeneralPeriod) broadcast(-, a, b) + +# #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:Day(1):stop +@deprecate colon(start::T, stop::T) where {T<:Date} start:Day(1):stop +@deprecate colon(start::T, stop::T) where {T<:Time} start:Second(1):stop + +@deprecate range(start::DateTime, len::Integer) range(start, Day(1), len) +@deprecate range(start::Date, len::Integer) range(start, Day(1), len) + diff --git a/base/dates/io.jl b/stdlib/Dates/src/io.jl similarity index 100% rename from base/dates/io.jl rename to stdlib/Dates/src/io.jl diff --git a/base/dates/parse.jl b/stdlib/Dates/src/parse.jl similarity index 100% rename from base/dates/parse.jl rename to stdlib/Dates/src/parse.jl diff --git a/base/dates/periods.jl b/stdlib/Dates/src/periods.jl similarity index 100% rename from base/dates/periods.jl rename to stdlib/Dates/src/periods.jl diff --git a/base/dates/query.jl b/stdlib/Dates/src/query.jl similarity index 100% rename from base/dates/query.jl rename to stdlib/Dates/src/query.jl diff --git a/base/dates/ranges.jl b/stdlib/Dates/src/ranges.jl similarity index 100% rename from base/dates/ranges.jl rename to stdlib/Dates/src/ranges.jl diff --git a/base/dates/rounding.jl b/stdlib/Dates/src/rounding.jl similarity index 100% rename from base/dates/rounding.jl rename to stdlib/Dates/src/rounding.jl diff --git a/base/dates/types.jl b/stdlib/Dates/src/types.jl similarity index 100% rename from base/dates/types.jl rename to stdlib/Dates/src/types.jl diff --git a/test/dates/accessors.jl b/stdlib/Dates/test/accessors.jl similarity index 99% rename from test/dates/accessors.jl rename to stdlib/Dates/test/accessors.jl index 319b30da42345..a2b487470e696 100644 --- a/test/dates/accessors.jl +++ b/stdlib/Dates/test/accessors.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module AccessorsTest + +using Dates +using Test + @testset "yearmonthday/yearmonth/monthday" begin # yearmonthday is the opposite of totaldays # taking Rata Die Day # and returning proleptic Gregorian date @@ -213,3 +218,5 @@ end @test Dates.microsecond.(tr) == repmat([5], 10) @test Dates.nanosecond.(tr) == repmat([6], 10) end + +end diff --git a/test/dates/adjusters.jl b/stdlib/Dates/test/adjusters.jl similarity index 99% rename from test/dates/adjusters.jl rename to stdlib/Dates/test/adjusters.jl index fbbcd314f57c9..771578eaf0639 100644 --- a/test/dates/adjusters.jl +++ b/stdlib/Dates/test/adjusters.jl @@ -1,4 +1,9 @@ -# This file is a part of Julia. License is MIT: https://julialang.org/license +#This file is a part of Julia. License is MIT: https://julialang.org/license + +module AdjustersTest + +using Test +using Dates #trunc dt = Dates.Date(2012, 12, 21) @@ -473,3 +478,5 @@ r = filter(x->Dates.second(x) == 5, Dates.Time(0):Dates.Second(1):Dates.Time(10) @test length(r) == 600 @test first(r) == Dates.Time(0, 0, 5) @test last(r) == Dates.Time(9, 59, 5) + +end diff --git a/test/dates/arithmetic.jl b/stdlib/Dates/test/arithmetic.jl similarity index 99% rename from test/dates/arithmetic.jl rename to stdlib/Dates/test/arithmetic.jl index 6b5b25c2ed1cc..78d8d0f5dda46 100644 --- a/test/dates/arithmetic.jl +++ b/stdlib/Dates/test/arithmetic.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module ArithmeticTest + +using Test +using Dates + @testset "Time arithmetic" begin a = Dates.Time(23, 59, 59) b = Dates.Time(11, 59, 59) @@ -458,3 +463,5 @@ end @test_throws MethodError (Dates.Hour(1) + Dates.Minute(1)) - t3 end end + +end diff --git a/test/dates/conversions.jl b/stdlib/Dates/test/conversions.jl similarity index 99% rename from test/dates/conversions.jl rename to stdlib/Dates/test/conversions.jl index da807791cb85a..0368f9f8e7a18 100644 --- a/test/dates/conversions.jl +++ b/stdlib/Dates/test/conversions.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module ConversionTests + +using Test +using Dates + @testset "conversion to/from UNIX" begin # Test conversion to and from unix @test Dates.unix2datetime(Dates.datetime2unix(DateTime(2000, 1, 1))) == DateTime(2000, 1, 1) @@ -117,3 +122,5 @@ end @test Dates.microsecond(t) == 0 @test Dates.nanosecond(t) == 0 end + +end diff --git a/test/dates/io.jl b/stdlib/Dates/test/io.jl similarity index 99% rename from test/dates/io.jl rename to stdlib/Dates/test/io.jl index e9059e1b590ff..63620a5c31505 100644 --- a/test/dates/io.jl +++ b/stdlib/Dates/test/io.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module IOTests + +using Test +using Dates + @testset "string/show representation of Date" begin @test string(Dates.Date(1, 1, 1)) == "0001-01-01" # January 1st, 1 AD/CE @test sprint(show, Dates.Date(1, 1, 1)) == "0001-01-01" @@ -487,3 +492,5 @@ end @test_throws ArgumentError Dates.Time("10:33:51", DateFormat("YYYY-MM-DD HH:MM:SS")) # Time can't hold year/month/day end end + +end diff --git a/test/dates/periods.jl b/stdlib/Dates/test/periods.jl similarity index 99% rename from test/dates/periods.jl rename to stdlib/Dates/test/periods.jl index 5b83287ac4e8e..85a3b05a6ba16 100644 --- a/test/dates/periods.jl +++ b/stdlib/Dates/test/periods.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module PeriodsTest + +using Dates +using Test + @testset "basic arithmetic" begin @test -Dates.Year(1) == Dates.Year(-1) @test Dates.Year(1) > Dates.Year(0) @@ -415,3 +420,5 @@ end @test hash(y) == hash(z) end end + +end diff --git a/test/dates/query.jl b/stdlib/Dates/test/query.jl similarity index 99% rename from test/dates/query.jl rename to stdlib/Dates/test/query.jl index 42a666584a5e5..c8c591c46cdeb 100644 --- a/test/dates/query.jl +++ b/stdlib/Dates/test/query.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module QueryTests + +using Test +using Dates + Jan = Dates.DateTime(2013, 1, 1) # Tuesday Feb = Dates.DateTime(2013, 2, 2) # Saturday Mar = Dates.DateTime(2013, 3, 3) # Sunday @@ -206,3 +211,5 @@ end @test Dates.dayofquarter(Dates.DateTime(2014, 9, 30)) == 92 @test Dates.dayofquarter(Dates.DateTime(2014, 12, 31)) == 92 end + +end diff --git a/test/dates/ranges.jl b/stdlib/Dates/test/ranges.jl similarity index 98% rename from test/dates/ranges.jl rename to stdlib/Dates/test/ranges.jl index 576f5efd7e7de..fbf4aa6ec71fe 100644 --- a/test/dates/ranges.jl +++ b/stdlib/Dates/test/ranges.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module RangesTest + +using Test +using Dates + let for T in (Dates.Date, Dates.DateTime) f1 = T(2014); l1 = T(2013, 12, 31) @@ -549,3 +554,10 @@ a = Dates.Time(23, 1, 1) @test all(x->sort(x) == (step(x) < zero(step(x)) ? reverse(x) : x), drs) @test all(x->step(x) < zero(step(x)) ? issorted(reverse(x)) : issorted(x), drs) + +@test !(1 in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05)) +@test !(Complex(1, 0) in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05)) +@test !(π in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05)) +@test !("a" in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05)) + +end diff --git a/test/dates/rounding.jl b/stdlib/Dates/test/rounding.jl similarity index 99% rename from test/dates/rounding.jl rename to stdlib/Dates/test/rounding.jl index b12d1a757a992..e95bf9a36e9d6 100644 --- a/test/dates/rounding.jl +++ b/stdlib/Dates/test/rounding.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module RoundingTests + +using Test +using Dates + @testset "conversion to and from the rounding epoch (ISO 8601 year 0000)" begin @test Dates.epochdays2date(-1) == Dates.Date(-1, 12, 31) @test Dates.epochdays2date(0) == Dates.Date(0, 1, 1) @@ -218,3 +223,6 @@ end end end end + +end + diff --git a/stdlib/Dates/test/runtests.jl b/stdlib/Dates/test/runtests.jl new file mode 100644 index 0000000000000..2a88315345d62 --- /dev/null +++ b/stdlib/Dates/test/runtests.jl @@ -0,0 +1,17 @@ +module DateTests + +using Test +using Dates + +include("accessors.jl") +include("adjusters.jl") +include("query.jl") +include("periods.jl") +include("ranges.jl") +include("rounding.jl") +include("types.jl") +include("io.jl") +include("arithmetic.jl") +include("conversions.jl") + +end diff --git a/test/dates/types.jl b/stdlib/Dates/test/types.jl similarity index 99% rename from test/dates/types.jl rename to stdlib/Dates/test/types.jl index 9810305204081..1f78f92e56643 100644 --- a/test/dates/types.jl +++ b/stdlib/Dates/test/types.jl @@ -1,5 +1,10 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +module TypesTest + +using Test +using Dates + # Date internal algorithms @testset "totaldays" begin @test Dates.totaldays(0, 2, 28) == -307 @@ -217,3 +222,5 @@ end @test a != b @test Dates.Date(Dates.DateTime(Dates.Date(2012, 7, 1))) == Dates.Date(2012, 7, 1) end + +end diff --git a/test/channels.jl b/test/channels.jl index 8a65ced7cd40a..d6ed03a0d8387 100644 --- a/test/channels.jl +++ b/test/channels.jl @@ -198,6 +198,7 @@ for N in [0,10] end # Testing timedwait on multiple channels +using Dates @sync begin rr1 = Channel(1) rr2 = Channel(1) diff --git a/test/choosetests.jl b/test/choosetests.jl index cfb0a3d08a6f0..e2196d2b3fbe5 100644 --- a/test/choosetests.jl +++ b/test/choosetests.jl @@ -31,7 +31,7 @@ function choosetests(choices = []) "linalg", "subarray", "core", "inference", "worlds", "keywordargs", "numbers", "subtype", "printf", "char", "strings", "triplequote", "unicode", "intrinsics", - "dates", "dict", "hashing", "iobuffer", "staged", "offsetarray", + "dict", "hashing", "iobuffer", "staged", "offsetarray", "arrayops", "tuple", "reduce", "reducedim", "random", "abstractarray", "intfuncs", "simdloop", "vecelement", "sparse", "bitarray", "copy", "math", "fastmath", "functional", "iterators", @@ -78,16 +78,6 @@ function choosetests(choices = []) tests = testnames end - datestests = ["dates/accessors", "dates/adjusters", "dates/query", - "dates/periods", "dates/ranges", "dates/rounding", "dates/types", - "dates/io", "dates/arithmetic", "dates/conversions"] - if "dates" in skip_tests - filter!(x -> (x != "dates" && !(x in datestests)), tests) - elseif "dates" in tests - # specifically selected case - filter!(x -> x != "dates", tests) - prepend!(tests, datestests) - end unicodetests = ["unicode/UnicodeError", "unicode/utf8proc", "unicode/utf8"] if "unicode" in skip_tests @@ -108,7 +98,6 @@ function choosetests(choices = []) prepend!(tests, stringtests) end - sparsetests = ["sparse/sparse", "sparse/sparsevector", "sparse/higherorderfns"] if Base.USE_GPL_LIBS append!(sparsetests, ["sparse/umfpack", "sparse/cholmod", "sparse/spqr"]) diff --git a/test/compile.jl b/test/compile.jl index 8a736f1cf7cd3..4aacb40506489 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -218,7 +218,7 @@ try [:Base, :Core, Foo2_module, FooBase_module, :Main, :Test]), # plus modules included in the system image Dict(s => Base.module_uuid(Base.root_module(s)) for s in - [:DelimitedFiles,:Mmap,:Base64])) + [:DelimitedFiles, :Mmap, :Base64, :Dates])) @test discard_module.(deps) == deps1 @test current_task()(0x01, 0x4000, 0x30031234) == 2 diff --git a/test/core.jl b/test/core.jl index c1fc395e2541d..c5d5a44578a48 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3306,6 +3306,7 @@ end @test Tuple{Int} === Tuple{Int, Vararg{Integer, 0}} # issue #12003 +using Dates const DATE12003 = DateTime(1917,1,1) failure12003(dt=DATE12003) = Dates.year(dt) @test isa(failure12003(), Integer) @@ -4939,6 +4940,7 @@ mutable struct Sgnd <: Signed v::Int end using Test +using Dates @test_throws ErrorException abs(Sgnd(1)) #12007 io = IOBuffer() @test_throws ErrorException show(io, Sgnd(1)) #12007 @@ -5482,6 +5484,7 @@ end module UnionOptimizations using Test +using Dates const boxedunions = [Union{}, Union{String, Void}] const unboxedunions = [Union{Int8, Void}, diff --git a/test/nullable.jl b/test/nullable.jl index fcc180ccc907a..b3f8b82c7d95e 100644 --- a/test/nullable.jl +++ b/test/nullable.jl @@ -388,6 +388,7 @@ end @test isequal(convert(Nullable, "a"), Nullable("a")) @test isequal(convert(Nullable, Nullable("a")), Nullable("a")) +using Dates @test promote_type(Nullable{Int}, Int) === Nullable{Int} @test promote_type(Nullable{Union{}}, Int) === Nullable{Int} @test promote_type(Nullable{Float64}, Nullable{Int}) === Nullable{Float64} @@ -398,7 +399,7 @@ end @test Base.promote_op(-, Nullable{Int}, Nullable{Int}) == Nullable{Int} @test Base.promote_op(+, Nullable{Float64}, Nullable{Int}) == Nullable{Float64} @test Base.promote_op(-, Nullable{Float64}, Nullable{Int}) == Nullable{Float64} -@test Base.promote_op(-, Nullable{DateTime}, Nullable{DateTime}) == Nullable{Base.Dates.Millisecond} +@test Base.promote_op(-, Nullable{DateTime}, Nullable{DateTime}) == Nullable{Dates.Millisecond} # tests for istypeequal (which uses filter, broadcast) @test istypeequal(Nullable(0), Nullable(0)) diff --git a/test/ranges.jl b/test/ranges.jl index c665fe920676a..cdbf74f9a73b4 100644 --- a/test/ranges.jl +++ b/test/ranges.jl @@ -1,5 +1,7 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license +using Dates + # Compare precision in a manner sensitive to subnormals, which lose # precision compared to widening. function cmp_sn(w, hi, lo, slopbits=0) diff --git a/test/threads.jl b/test/threads.jl index 278fa9181c445..7c5b541a7364c 100644 --- a/test/threads.jl +++ b/test/threads.jl @@ -347,6 +347,8 @@ for T in (Int32, Int64, Float32, Float64) @test varmax[] === T(maximum(1:nloops)) @test varmin[] === T(0) end + +using Dates for period in (0.06, Dates.Millisecond(60)) let async = Base.AsyncCondition(), t c = Condition()