Skip to content

Commit

Permalink
reduce method ambiguities
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Mar 1, 2024
1 parent 5fe7b78 commit caa90b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/datetime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This type implements the calendar defined as "$($calendar)".
return DT{T,Val(origin)}(args...)
end

function $CFDateTime(t,units::AbstractString)
function $CFDateTime(t::Union{Number,Tuple},units::AbstractString)
origintuple, factor, exponent = _timeunits(Tuple,units)
instant = Period(t,factor,exponent)
dt = $CFDateTime{typeof(instant),Val(origintuple)}(instant)
Expand All @@ -80,7 +80,7 @@ This type implements the calendar defined as "$($calendar)".
$CFDateTime(y::Integer,args::Vararg{<:Integer,N}; kwargs...) where N = $CFDateTime(Int64,y,args...; kwargs...)


function $CFDateTime(p::Period,origintuple)
function $CFDateTime(p::Period,origintuple::Tuple)
$CFDateTime{typeof(p),Val(origintuple)}(p)
end

Expand Down Expand Up @@ -218,6 +218,7 @@ function -(dt1::DateTime,dt2::AbstractCFDateTime)
end

-(dt::AbstractCFDateTime::Period) = dt + (-Δ)
-(dt::AbstractCFDateTime::Dates.CompoundPeriod) = dt + (-Δ)
-(dt::AbstractCFDateTime,Δ) = dt + (-Δ)

function ==(dt1::AbstractCFDateTime,dt2::AbstractCFDateTime)
Expand Down Expand Up @@ -261,3 +262,7 @@ end
function show(io::IO,dt::T) where T <: AbstractCFDateTime
write(io, string(typeof(dt)), "(",string(dt),")")
end


# Missing support
(-)(x::AbstractCFDateTime, y::Missing) = missing
5 changes: 5 additions & 0 deletions src/period.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ Dates.Millisecond(p::CFTime.Period{T, Val{1}(), Val{-3}()}) where T =
function isless(p1::Period,p2::Period)
return Dates.value(p1 - p2) < 0
end


# Missing support
(==)(x::Period, y::Missing) = missing
(==)(x::Missing, y::Period) = missing
2 changes: 1 addition & 1 deletion test/test_resolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ daysinmonth(DateTimeStandard,1582,10)
daysinmonth(dt)

DT = DateTimeStandard
import CFTime: DateTimeStandard, _pad3, unwrap, _factor, _exponent, _type
import CFTime: DateTimeStandard, unwrap, _factor, _exponent, _type



Expand Down

0 comments on commit caa90b4

Please sign in to comment.