Skip to content

Commit

Permalink
Float to Second, Minute, Hour, Day conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Nov 28, 2023
1 parent 97f7ff1 commit 866901a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utility_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ function print_fields(io::IO,A,keys;arrays::Bool=false)
end
end

function Base.convert(::Type{Second},x::Real)
Dates.Second(x::AbstractFloat) = convert(Second,x)
Dates.Minute(x::AbstractFloat) = Second(60x)
Dates.Hour( x::AbstractFloat) = Minute(60x)
Dates.Day( x::AbstractFloat) = Hour(24x)

function Base.convert(::Type{Second},x::AbstractFloat)
xr = round(Int64,x)
@info "Rounding and converting $x to $xr for integer seconds."
return convert(Second,xr)
return Second(xr)
end

function Base.convert(::Type{Second},x::Integer)
Expand Down

0 comments on commit 866901a

Please sign in to comment.