Skip to content

Commit 012349b

Browse files
authored
Merge pull request #39169 from JuliaLang/dpa/compoundperiod-periods
Add the public `Dates.periods` function for getting the `Vector` of `Period`s that comprise a `CompoundPeriod`
2 parents c487dd0 + dd8b43e commit 012349b

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Standard library changes
6868

6969
#### Dates
7070

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

7273
#### Statistics
7374

stdlib/Dates/docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ Dates.Period(::Any)
747747
Dates.CompoundPeriod(::Vector{<:Dates.Period})
748748
Dates.value
749749
Dates.default
750+
Dates.periods
750751
```
751752

752753
### Rounding Functions

stdlib/Dates/src/periods.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ struct CompoundPeriod <: AbstractTime
196196
end
197197
end
198198

199+
"""
200+
Dates.periods(::CompoundPeriod) -> Vector{Period}
201+
202+
Return the `Vector` of `Period`s that comprise the given `CompoundPeriod`.
203+
"""
204+
periods(x::CompoundPeriod) = x.periods
205+
199206
"""
200207
CompoundPeriod(periods) -> CompoundPeriod
201208

stdlib/Dates/test/periods.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ end
366366
@test isequal(d - h, 2d - 2h - 1d + 1h)
367367
@test sprint(show, y + m) == string(y + m)
368368
@test convert(Dates.CompoundPeriod, y) + m == y + m
369+
@test Dates.periods(convert(Dates.CompoundPeriod, y)) == convert(Dates.CompoundPeriod, y).periods
369370
end
370371
@testset "compound period simplification" begin
371372
# reduce compound periods into the most basic form

0 commit comments

Comments
 (0)