Skip to content

Commit

Permalink
year0 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Mar 4, 2024
1 parent 72d6ae0 commit eabd31c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ the types `DateTimeStandard` and `DateTimeJulian`.
y, mdHMS... = (Dates.year(origin),Dates.month(origin),Dates.day(origin))
if !_hasyear0(T) && y <= 0
origintuple = (y-1, mdHMS...)
else
origintuple = (y, mdHMS...)
end

p = convert(Period,dt.instant.periods)
Expand Down
5 changes: 4 additions & 1 deletion src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ end
end


@inline _hasyear0(::Type{T}) where T = false
# https://web.archive.org/web/20240304171516/https://unidata.github.io/cftime/api.html
# https://github.com/cf-convention/cf-conventions/issues/298
@inline _hasyear0(::Type{T}) where T <: Union{DateTimeJulian,DateTimeStandard} = false
@inline _hasyear0(::Type{T}) where T <: AbstractCFDateTime = true


"""
Expand Down
4 changes: 1 addition & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#using Pkg; Pkg.activate("CFTime-env",shared=true)


using CFTime
using Test

@testset "Time and calendars" begin
include("test_time.jl")
include("test_resolution.jl")
include("test_query.jl")
include("test_aqua.jl")
end
2 changes: 1 addition & 1 deletion test/test_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ dt = CFTime.reinterpret(DateTimeNoLeap, DateTime(1900,2,28))
@test DateTimeStandard(2000,01,03) > DateTimeStandard(2000,01,02)
@test DateTimeStandard(2000,01,03) DateTimeStandard(2000,01,01)

import CFTime.CFTime: datetuple
import CFTime: datetuple
datetuple(dt::DateTime) = (Dates.year(dt),Dates.month(dt),Dates.day(dt),
Dates.hour(dt),Dates.minute(dt),Dates.second(dt),
Dates.millisecond(dt))
Expand Down

0 comments on commit eabd31c

Please sign in to comment.