Commit 2d00ed14 authored by Michel Juillard's avatar Michel Juillard
Browse files

add operations

parent 6fc8e70e
......@@ -5,4 +5,15 @@ abstract type AbstractPeriod end
include("SimplePeriods.jl")
export Frequency, Period, Year, Semester, Quarter, Month, Week, Day, Undated
import Base.:-
-(p1::AbstractPeriod, p2::AbstractPeriod) = p1.ordinal - p2.ordinal
import Base.:>
>(p1::AbstractPeriod, p2::AbstractPeriod) = p1.ordinal > p2.ordinal
import Base.:<
<(p1::AbstractPeriod, p2::AbstractPeriod) = p1.ordinal < p2.ordinal
import Base.checkindex
checkindex(::Type{Bool}, inds::AbstractUnitRange, p::AbstractPeriod) = checkindex(Bool, inds, p.ordinal)
end # module
......@@ -46,3 +46,11 @@ end
Period(year::Integer, month::Integer, day::Integer) = (Date(year, month, day).value, Day)
Period(d::Date) = (d.value, Day)
import Base.copy
copy(p::Period) = Period(p.ordinal, p.frequency)
import Base.:+
+(p1::Period, k::Integer) = Period(p1.ordinal + k, p1.frequency)
import Base.:-
-(p1::Period, k::Integer) = Period(p1.ordinal - k, p1.frequency)
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