Defining the date ranges
Julia allows us to define ranges of dates to express continuous periods of time. For example, we could represent the whole year as the range of days between January 1 and December 31:
julia> year_2019 = Date(2019, 1, 1):Day(1):Date(2019,12,31)
2019-01-01:1 day:2019-12-31
We have created a date range with a step of one day—so 365
items, since 2019 is not a leap year:
julia> typeof(year_2019) StepRange{Date,Day} julia> size(year_2019) (365,)
We can instantiate the actual Date
objects using the aptly named collect
function:
julia> collect(year_2019)
365-element Array{Date,1}:
2019-01-01
2019-01-02
2019-01-03
# output truncated
Also, of course, we can access the elements by index as follows:
julia> year_2019[100] # day 100
2019-04-10
It's also possible to define ranges with other steps, such as monthly intervals:
julia> year_2019 = Date(2019, 1, 1):Month(1):Date(2019,12,31) 2019-01-01:1 month:2019-12-01 julia> collect(year_2019) # First day...