SimplePeriods.jl 672 Bytes
Newer Older
Michel Juillard's avatar
Michel Juillard committed
1
2
@enum Frequency Year Semester Quarter Month Week Business Day

MichelJuillard's avatar
update    
MichelJuillard committed
3
struct Period
Michel Juillard's avatar
Michel Juillard committed
4
5
6
7
    ordinal::Int64
    frequency::Frequency
end

MichelJuillard's avatar
update    
MichelJuillard committed
8
function Period(year, subperiod, frequency) <: AbstractPeriod
Michel Juillard's avatar
Michel Juillard committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    if frequency == Year
        ordinal = year - 1970
    elseif frequency == Semester
        @assert(subperiod in 1:2)
        ordinal = 2*(year - 1970) + subperiod - 1
    elseif frequency == Quarter
        @assert(subperiod in 1:4)
        ordinal = 4*(year - 1970) + subperiod - 1
    elseif frequency == Month
        @assert(subperiod in 1:12)
        ordinal = 12*(year - 1970) + subperiod - 1
    elseif frequency == Week
        ordinal = week1970(year, week)
    end
end