Skip to content

Commit

Permalink
Add Compat.Dates for standard library Dates (#413)
Browse files Browse the repository at this point in the history
* Add Compat.Dates for standard library Dates

* Refactor deprecated parametic syntax
  • Loading branch information
omus authored and TotalVerb committed Nov 23, 2017
1 parent 0e01338 commit 3cd0bc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ Currently, the `@compat` macro supports the following syntaxes:
Compat.DelimitedFiles` are provided on versions older than 0.7, where these are not yet
part of the standard library. ([#23931])

* `using Compat.Dates` is provided on versions older than 0.7, where this library is not
yet a part of the standard library. ([#24459])

## Module Aliases

* In 0.6, some 0.5 iterator functions have been moved to the `Base.Iterators`
Expand Down Expand Up @@ -357,4 +360,5 @@ includes this fix. Find the minimum version from there.
[#24047]: https://github.com/JuliaLang/julia/issues/24047
[#24282]: https://github.com/JuliaLang/julia/issues/24282
[#24372]: https://github.com/JuliaLang/julia/issues/24372
[#24459]: https://github.com/JuliaLang/julia/issues/24459
[#24657]: https://github.com/JuliaLang/julia/issues/24657
6 changes: 6 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ else
import Test, SharedArrays, Mmap, DelimitedFiles
end

if VERSION < v"0.7.0-DEV.2575"
const Dates = Base.Dates
else
import Dates
end

# 0.7.0-DEV.1993
@static if !isdefined(Base, :EqualTo)
if VERSION >= v"0.6.0"
Expand Down
12 changes: 11 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,8 @@ cm359() = @__MODULE__

# PR 21378
let
import Compat: Dates

# https://en.wikipedia.org/wiki/Swatch_Internet_Time
eval(Expr(
:type, false,
Expand All @@ -657,7 +659,7 @@ let
Dates.toms(b::Beat) = Dates.value(b) * 86400
Dates._units(b::Beat) = " beat" * (abs(Dates.value(b)) == 1 ? "" : "s")
Base.promote_rule(::Type{Dates.Day}, ::Type{Beat}) = Dates.Millisecond
Base.convert{T<:Dates.Millisecond}(::Type{T}, b::Beat) = T(Dates.toms(b))
Base.convert(::Type{Dates.Millisecond}, b::Beat) = Dates.Millisecond(Dates.toms(b))

@test Beat(1000) == Dates.Day(1)
@test Beat(1) < Dates.Day(1)
Expand Down Expand Up @@ -847,6 +849,14 @@ module Test23876
@test isdefined(Mmap, :mmap)
end

# 0.7
module Test24459
using Compat
using Compat.Test
using Compat.Dates
@test isdefined(@__MODULE__, :Dates)
end

let a = [0,1,2,3,0,1,2,3]
@test findfirst(equalto(3), [1,2,4,1,2,3,4]) == 6
@test findfirst(!equalto(1), [1,2,4,1,2,3,4]) == 2
Expand Down

0 comments on commit 3cd0bc6

Please sign in to comment.