Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Nov 5, 2024
1 parent 67199aa commit a567090
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/datetime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ end

function units(dt::AbstractCFDateTime{T,Torigintuple}) where {T,Torigintuple}
return string(units(dt.instant)," since ",
datetuple_to_string(unwrap(Torigintuple)))
format_datetuple(unwrap(Torigintuple)))
end

+(dt::AbstractCFDateTime,p::Union{Dates.TimePeriod,Dates.Day}) = dt + convert(CFTime.Period,p)
Expand Down Expand Up @@ -253,7 +253,7 @@ function chop0(timetuple,minlen=0)
end
end

function datetuple_to_string(timetuple::Tuple)
function format_datetuple(timetuple::Tuple)
y,mo,d,rest... = pad_ymd(timetuple)

io = IOBuffer()
Expand Down Expand Up @@ -287,7 +287,7 @@ end


function string(dt::T) where T <: AbstractCFDateTime
return datetuple_to_string(chop0(datetuple(dt),6))
return format_datetuple(chop0(datetuple(dt),6))
end

function show(io::IO,dt::T) where T <: AbstractCFDateTime
Expand Down
10 changes: 7 additions & 3 deletions src/period.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function units(p::Period{T,Tfactor,Texponent}) where {T,Tfactor,Texponent}
end
end

return string(unwrap(factor)," × 10^",unwrap(exponent)," s")
return string(unwrap(Tfactor)," × 10^",unwrap(Texponent)," s")
end


Expand Down Expand Up @@ -244,11 +244,15 @@ end
Dates.Millisecond(Int64(p.duration))

@inline function Dates.Millisecond(p::Period)
Dates.Millisecond(convert(CFTime.Period{Int64,Val{1}(),Val{-3}()},p))
Dates.Millisecond(convert(Period{Int64,Val{1}(),Val{-3}()},p))
end

@inline function Dates.Second(p::Period)
Dates.Second(convert(CFTime.Period{Int64,Val{1}(),Val{0}()},p))
Dates.Second(convert(Period{Int64,Val{1}(),Val{0}()},p))
end

@inline function Dates.Second(p::Period{T,Val{1}(),Val{0}()}) where T
Dates.Second(p.duration)
end

function isless(p1::Period,p2::Period)
Expand Down
4 changes: 4 additions & 0 deletions test/test_resolution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ show(io,p1)
str = String(take!(io))
@test occursin("1 second",str)
@test occursin("1 second",string(p1))
@test occursin("second",CFTime.units(p1))
@test Dates.Second(p1) === Dates.Second(1)
@test Dates.Millisecond(p1) === Dates.Millisecond(1000)

# unknown Period
p1 = Period(1000,1,-21) # 1000 zeptosecond = 1 attosecond
@test p1 == Period(1,:attosecond)
@test occursin("-21",string(p1))
@test occursin("-21",CFTime.units(p1))

# decode dates

Expand Down

0 comments on commit a567090

Please sign in to comment.