Commit a9273d13 authored by Michel Juillard's avatar Michel Juillard
Browse files

Improve SimplePeriod

parent b5abcea7
......@@ -2,3 +2,6 @@ name = "Periods"
uuid = "0c1d1a06-9168-427d-90e3-b4d73349562f"
authors = ["michel "]
version = "0.1.0"
[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
module Periods
using Dates
abstract type AbstractPeriod end
include("SimplePeriods.jl")
......
......@@ -5,19 +5,44 @@ struct Period <: AbstractPeriod
frequency::Frequency
end
function Period(year, subperiod, frequency)
function Period(arg1::Integer, frequency::Frequency)
if frequency == Year
ordinal = year - 1970
ordinal = arg1 - 19070
elseif frequency == Undated
ordinal - arg1
else
error("Frequency $frequency needs more than one argument")
end
Period(ordinal, frequency)
end
function Period(arg1::Integer, arg2::Integer, frequency::Frequency)
if frequency == Year
ordinal = arg1 - 1970
elseif frequency == Semester
@assert(subperiod in 1:2)
ordinal = 2*(year - 1970) + subperiod - 1
@assert(arg2 in 1:2)
ordinal = 2*(arg1 - 1970) + arg2 - 1
elseif frequency == Quarter
@assert(subperiod in 1:4)
ordinal = 4*(year - 1970) + subperiod - 1
@assert(arg2 in 1:4)
ordinal = 4*(arg1 - 1970) + arg2 - 1
elseif frequency == Month
@assert(subperiod in 1:12)
ordinal = 12*(year - 1970) + subperiod - 1
ordinal = 12*(arg1 - 1970) + arg2 - 1
elseif frequency == Week
ordinal = week1970(year, week)
ordinal = week1970(arg1, arg2)
elseif frequency == Undated
ordinal = arg1
end
Period(ordinal, frequency)
end
function Period(arg1, arg2, arg3, frequency)
if frequency == Day
return Period(arg1, arg2, arg3)
else
return Period(arg1, arg2, frequency)
end
end
Period(year::Integer, month::Integer, day::Integer) = (Date(year, month, day).value, Day)
Period(d::Date) = (d.value, Day)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment