diff --git a/src/Persefone.jl b/src/Persefone.jl index ad32aef3a8e66814209fc56b7ab69397b74c40c8..093a63a2878cc8d795f76eefa7f447f0af407225 100644 --- a/src/Persefone.jl +++ b/src/Persefone.jl @@ -116,6 +116,11 @@ import Base./ # enable division with different length/area unit types /(x::S,y::T) where {S<:Area, T<:Area} = (upreferred(x)/m²) / (upreferred(y)/m²) /(x::S,y::T) where {S<:Mass, T<:Mass} = (upreferred(x)/g) / (upreferred(y)/g) +## Utility type and function for working wth recurring dates +const AnnualDate = Tuple{Int64,Int64} +function thisyear(ad::AnnualDate, model::SimulationModel) = Date(year(model.date), ad...) +function nextyear(ad::AnnualDate, model::SimulationModel) = Date(year(model.date)+Year(1), ad...) + """ SimulationModel diff --git a/src/nature/macros.jl b/src/nature/macros.jl index add747c36c4ee0a725625a78f5bfb8d8276d7312..54e3bef8ac70098a2d26f6552a3449ddf3605f5a 100644 --- a/src/nature/macros.jl +++ b/src/nature/macros.jl @@ -492,3 +492,22 @@ macro follow(leader, distance) :(followanimal!($(esc(:self)), $(esc(leader)), $(esc(:model)), $(esc(distance)))) end +""" + @thisyear(annualdate) + +Construct a date object referring to the current model year from an AnnualDate +(== Tuple{Int64,Int64}). +""" +macro thisyear(annualdate) + :(thisyear($(esc(annualdate)), $(esc(:model)))) +end + +""" + @nextyear(annualdate) + +Construct a date object referring to the next year in the model from an AnnualDate +(== Tuple{Int64,Int64}). +""" +macro nextyear(annualdate) + :(nextyear($(esc(annualdate)), $(esc(:model)))) +end