Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/UTCDates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct UTCDate
seconds::Float64

function UTCDate(
year::Number = 1970, month::Number = 1, day::Number = 1,
year::Number, month::Number, day::Number,
hour::Number = 0, minute::Number = 0, seconds::Number = 0.;
leap_second_table = default_leap_second_table,
)
Expand All @@ -106,8 +106,16 @@ struct UTCDate
return new(year, month, day, hour, minute, seconds)
end

function UTCDate(s::AbstractString)
return convert(UTCDate, s)
function UTCDate(;
year::Number, month::Number, day::Number,
hour::Number = 0, minute::Number = 0, seconds::Number = 0.,
kwargs...,
)
return UTCDate(year, month, day, hour, minute, seconds; kwargs...)
end

function UTCDate(s::AbstractString; kwargs...)
return convert(UTCDate, s; kwargs...)
end

end
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ const gps_epoch = UTCDate(1980, 01, 06, 0, 0, 0)

# TODO: Test for type stability and allocations.

@testset "constructors" begin

# We're just looking for coverage here.
@test_throws "" UTCDate() # Too ambiguous.
@test_throws "" UTCDate(1970) # Too ambiguous.
@test_throws "" UTCDate(1970, 1) # Too ambiguous.
@test UTCDate(1970, 1, 1) isa UTCDate
@test_throws "" UTCDate(;) # Too ambiguous.
@test_throws "" UTCDate(; year = 1970) # Too ambiguous.
@test_throws "" UTCDate(; year = 1970, month = 1) # Too ambiguous.
@test_throws "" UTCDate(; month = 1, day = 2) # Too ambiguous.
@test UTCDate(; year = 1970, month = 1, day = 1) isa UTCDate

end

@testset "known times between dates" begin

gps_wrt_unix = elapsed(; from = unix_epoch, to = gps_epoch)
Expand Down
Loading