Skip to content

Commit f387bc6

Browse files
amellnikKristofferC
authored andcommitted
Document Dates.value (#29591)
(cherry picked from commit b7a7002)
1 parent 14ce08c commit f387bc6

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

stdlib/Dates/docs/src/index.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ it could represent, in days, a value of 28, 29, 30, or 31 depending on the year
511511
Or a year could represent 365 or 366 days in the case of a leap year. [`Period`](@ref) types are
512512
simple [`Int64`](@ref) wrappers and are constructed by wrapping any `Int64` convertible type, i.e. `Year(1)`
513513
or `Month(3.0)`. Arithmetic between [`Period`](@ref) of the same type behave like integers, and
514-
limited `Period-Real` arithmetic is available.
514+
limited `Period-Real` arithmetic is available. You can extract the underlying integer with
515+
[`Dates.value`](@ref).
515516

516517
```jldoctest
517518
julia> y1 = Dates.Year(1)
@@ -537,6 +538,9 @@ julia> y3 % y2
537538
538539
julia> div(y3,3) # mirrors integer division
539540
3 years
541+
542+
julia> Dates.value(Dates.Millisecond(10))
543+
10
540544
```
541545

542546
## Rounding
@@ -740,6 +744,7 @@ Dates.toprev(::Function, ::Dates.TimeType)
740744
```@docs
741745
Dates.Period(::Any)
742746
Dates.CompoundPeriod(::Vector{<:Dates.Period})
747+
Dates.value
743748
Dates.default
744749
```
745750

stdlib/Dates/src/periods.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
#Period types
4+
"""
5+
Dates.value(x::Period) -> Int64
6+
7+
For a given period, return the value associated with that period. For example,
8+
`value(Millisecond(10))` returns 10 as an integer.
9+
"""
410
value(x::Period) = x.value
511

612
# The default constructors for Periods work well in almost all cases

0 commit comments

Comments
 (0)