Skip to content

Commit

Permalink
Add Dates.canonicalize(::Period) (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrobinson251 authored Oct 22, 2020
1 parent b6e65f2 commit aaa2e41
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Compat"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.21.0"
version = "3.22.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ changes in `julia`.

## Supported features

* `Dates.canonicalize` can now take a `Period` as an input ([#37391]) (since Compat 3.22)

* Import renaming is available through the `@compat` macro, e.g. `@compat import LinearAlgebra as LA` and
`@compat import LinearAlgebra: cholesky as c, lu as l`. *Note:* Import renaming of macros is not
supported due to differences in parsing behavior ([#37396]). (since Compat 3.21).
Expand Down Expand Up @@ -224,3 +226,4 @@ Note that you should specify the correct minimum version for `Compat` in the
[#29634]: https://github.com/JuliaLang/julia/pull/29634
[#35243]: https://github.com/JuliaLang/julia/pull/35243
[#37396]: https://github.com/JuliaLang/julia/pull/37396
[#37391]: https://github.com/JuliaLang/julia/pull/37391
10 changes: 9 additions & 1 deletion src/Compat.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module Compat

import Dates
using Dates: Period, CompoundPeriod

import LinearAlgebra
using LinearAlgebra: Adjoint, Diagonal, Transpose, UniformScaling, RealHermSymComplexHerm, BLAS

Expand Down Expand Up @@ -787,7 +790,7 @@ if VERSION < v"1.6.0-DEV.15"
end
return line, i
end

function parseall(text::AbstractString; filename="none")
filename = Symbol(filename)
ex = Expr(:toplevel)
Expand All @@ -806,6 +809,11 @@ else
using .Meta: parseatom, parseall
end

# https://github.com/JuliaLang/julia/pull/37391
if VERSION < v"1.6.0-DEV.820"
Dates.canonicalize(p::Period) = Dates.canonicalize(CompoundPeriod(p))
end

include("iterators.jl")
include("deprecated.jl")

Expand Down
16 changes: 15 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Compat
using Dates
using Test
using UUIDs: UUID, uuid1, uuid_version

Expand Down Expand Up @@ -728,7 +729,7 @@ end

ex = Compat.parseall(
raw"""
begin a = 1 end
begin
Expand All @@ -751,6 +752,19 @@ end
)
end

# https://github.com/JuliaLang/julia/pull/37391
@testset "Dates.canonicalize(::Period)" begin
# reduce individual Period into most basic CompoundPeriod
@test Dates.canonicalize(Dates.Nanosecond(1000000)) == Dates.canonicalize(Dates.Millisecond(1))
@test Dates.canonicalize(Dates.Millisecond(1000)) == Dates.canonicalize(Dates.Second(1))
@test Dates.canonicalize(Dates.Second(60)) == Dates.canonicalize(Dates.Minute(1))
@test Dates.canonicalize(Dates.Minute(60)) == Dates.canonicalize(Dates.Hour(1))
@test Dates.canonicalize(Dates.Hour(24)) == Dates.canonicalize(Dates.Day(1))
@test Dates.canonicalize(Dates.Day(7)) == Dates.canonicalize(Dates.Week(1))
@test Dates.canonicalize(Dates.Month(12)) == Dates.canonicalize(Dates.Year(1))
@test Dates.canonicalize(Dates.Minute(24*60*1 + 12*60)) == Dates.canonicalize(Dates.CompoundPeriod([Dates.Day(1),Dates.Hour(12)]))
end

include("iterators.jl")

# Import renaming, https://github.com/JuliaLang/julia/pull/37396,
Expand Down

2 comments on commit aaa2e41

@fredrikekre
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/23463

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.22.0 -m "<description of version>" aaa2e4137f0cbd0e9aa4ec4a437e9ec3d8742e11
git push origin v3.22.0

Please sign in to comment.