Skip to content
Snippets Groups Projects
Commit b4f6a32f authored by xo30xoqa's avatar xo30xoqa
Browse files

AnnualDates can be constructed from a string

parent 0d30cead
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,10 @@ end ...@@ -47,6 +47,10 @@ end
AnnualDate(ad::Tuple{Int64,Int64}) = AnnualDate(ad...) AnnualDate(ad::Tuple{Int64,Int64}) = AnnualDate(ad...)
Base.convert(::Type{AnnualDate}, ad::Tuple{Int64,Int64}) = AnnualDate(ad) Base.convert(::Type{AnnualDate}, ad::Tuple{Int64,Int64}) = AnnualDate(ad)
# allow creating AnnualDates from a string of the format "8 August"
AnnualDate(ad::String) = AnnualDate(Date(ad, dateformat"d U"))
Base.convert(::Type{AnnualDate}, ad::String) = AnnualDate(ad)
# Interface with Dates # Interface with Dates
AnnualDate(date::Date) = AnnualDate(month(date), day(date)) AnnualDate(date::Date) = AnnualDate(month(date), day(date))
Base.convert(::Type{AnnualDate}, ad::Date) = AnnualDate(ad) Base.convert(::Type{AnnualDate}, ad::Date) = AnnualDate(ad)
......
...@@ -22,7 +22,7 @@ mutable struct Pixel ...@@ -22,7 +22,7 @@ mutable struct Pixel
fieldid::Union{Missing,Int64} # ID of the farmplot (if any) at this position fieldid::Union{Missing,Int64} # ID of the farmplot (if any) at this position
events::Vector{Management} # management events that have been applied to this pixel events::Vector{Management} # management events that have been applied to this pixel
animals::Vector{Int64} # IDs of animals currently at this position animals::Vector{Int64} # IDs of animals currently at this position
territories::Vector{String} # IDs of animals that claim this pixel as part of their territory territories::Vector{String} # IDs of animals that claim this pixel as part of their territory
end end
Pixel(landcover::LandCover, fieldid::Union{Missing,Int64}) = Pixel(landcover::LandCover, fieldid::Union{Missing,Int64}) =
......
...@@ -113,11 +113,16 @@ end ...@@ -113,11 +113,16 @@ end
@test 1km / 5 == 200m @test 1km / 5 == 200m
# AnnualDates # AnnualDates
birthday::AnnualDate = (August, 21) birthday::AnnualDate = (August, 21)
christmas::AnnualDate = (December, 24) christmas::AnnualDate = "24 December"
heute = Date(2024, 8, 8) heute = Date(2024, 8, 8)
@test christmas - birthday == Day(125) @test christmas - birthday == Day(125)
@test birthday - christmas == Day(240) @test birthday - christmas == Day(240)
@test birthday > heute @test birthday > heute
@test heute + Week(2) - Day(1) == birthday @test heute + Week(2) - Day(1) == birthday
@test length(AnnualDate(heute):birthday) == 14 @test length(AnnualDate(heute):birthday) == 14
# bounds
@test Ps.bounds(3) == 3
@test Ps.bounds(-3) == 0
@test Ps.bounds(20, max=10) == 10
@test Ps.bounds(-3, min=-10) == -3
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment