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

Add the public Dates.periods function for getting the Vector of Periods that comprise a CompoundPeriod #39169

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Standard library changes

#### Dates

* The `Dates.periods` function can be used to get the `Vector` of `Period`s that comprise a `CompoundPeriod` ([#39169]).

#### Statistics

Expand Down
1 change: 1 addition & 0 deletions stdlib/Dates/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ Dates.Period(::Any)
Dates.CompoundPeriod(::Vector{<:Dates.Period})
Dates.value
Dates.default
Dates.periods
```

### Rounding Functions
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Dates/src/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ struct CompoundPeriod <: AbstractTime
end
end

"""
periods(::CompoundPeriod) -> Vector{Period}
DilumAluthge marked this conversation as resolved.
Show resolved Hide resolved

Return the `Vector` of `Period`s that comprise the given `CompoundPeriod`.
"""
periods(x::CompoundPeriod) = x.periods

"""
CompoundPeriod(periods) -> CompoundPeriod

Expand Down
1 change: 1 addition & 0 deletions stdlib/Dates/test/periods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ end
@test isequal(d - h, 2d - 2h - 1d + 1h)
@test sprint(show, y + m) == string(y + m)
@test convert(Dates.CompoundPeriod, y) + m == y + m
@test Dates.periods(convert(Dates.CompoundPeriod, y)) == convert(Dates.CompoundPeriod, y).periods
end
@testset "compound period simplification" begin
# reduce compound periods into the most basic form
Expand Down