Skip to content

Commit

Permalink
Add the public Dates.periods function for getting the Vector of `…
Browse files Browse the repository at this point in the history
…Period`s that comprise a `CompoundPeriod`
  • Loading branch information
DilumAluthge committed Jan 10, 2021
1 parent ffa966e commit 6535c23
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
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}
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

0 comments on commit 6535c23

Please sign in to comment.