diff --git a/src/core/utils.jl b/src/core/utils.jl index 358d9b8d9def38b198907f20bc614ad5a3662cb4..ddffe480275f34dc7980a58753a2e05f7faf53cb 100644 --- a/src/core/utils.jl +++ b/src/core/utils.jl @@ -47,6 +47,10 @@ end 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 AnnualDate(date::Date) = AnnualDate(month(date), day(date)) Base.convert(::Type{AnnualDate}, ad::Date) = AnnualDate(ad) diff --git a/src/world/landscape.jl b/src/world/landscape.jl index 762ea8b11941d3c54fa67dca97876155f8f5e159..afbc6d7a8e416588627ee42236625f66a7fda827 100644 --- a/src/world/landscape.jl +++ b/src/world/landscape.jl @@ -22,7 +22,7 @@ mutable struct Pixel 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 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 Pixel(landcover::LandCover, fieldid::Union{Missing,Int64}) = diff --git a/test/io_tests.jl b/test/io_tests.jl index 9a28b5d8a182058d189b1e4247ee75336e3e877c..deebec3c249b7df52368432deb209001ec02b525 100644 --- a/test/io_tests.jl +++ b/test/io_tests.jl @@ -113,11 +113,16 @@ end @test 1km / 5 == 200m # AnnualDates birthday::AnnualDate = (August, 21) - christmas::AnnualDate = (December, 24) + christmas::AnnualDate = "24 December" heute = Date(2024, 8, 8) @test christmas - birthday == Day(125) @test birthday - christmas == Day(240) @test birthday > heute @test heute + Week(2) - Day(1) == birthday @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