From 46c57112e17dade986046fdb4b7bedc550bfbe54 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 10:51:47 +0200 Subject: [PATCH 1/6] Updated `Duration` docstrings --- docs/src/api.md | 1 + src/duration.jl | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/src/api.md b/docs/src/api.md index 3bbde6b..304373f 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -19,6 +19,7 @@ find_dayinyear ### Duration ```@docs Duration +value ``` ### Types diff --git a/src/duration.jl b/src/duration.jl index 1267844..414c6d0 100644 --- a/src/duration.jl +++ b/src/duration.jl @@ -3,11 +3,36 @@ Duration{T} <: Number A `Duration` represents a period of time, split into an integer number of seconds and a -fractional part. +fractional part for increased precision. ### Fields - `seconds`: The integer number of seconds. - `fraction`: The fractional part of the duration, where `T` is a subtype of `Number`. + +--- + + Duration(seconds::Number) + +Create a `Duration` object from a number of seconds. The type of the fractional part will +be inferred from the type of the input argument. + +--- + + Duration{T}(seconds::Number) + +Create a `Duration` object from a number of seconds with the fractional part of type `T`. + +### Examples +```julia-repl +julia> d = Duration(10.783) +Duration{Float64}(10, 0.7829999999999995) + +julia> value(d) +10.783 + +julia> d = Duration{BigFloat64}(10.3) +Duration{BigFloat}(10, 0.300000000000000710542735760100185871124267578125) +``` """ struct Duration{T} <: Number seconds::Int @@ -24,6 +49,12 @@ function Duration(seconds::T) where {T <: Number} end ftype(::Duration{T}) where T = T + +""" + value(d::Duration) + +Return the duration `d`, in seconds. +""" value(d::Duration{T}) where T = d.seconds + d.fraction # --- From e60d819bfb7b797366db82a24f2c39d717b6faf4 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 10:54:38 +0200 Subject: [PATCH 2/6] Updated leapsecond description --- docs/src/tutorials/t01_epochs.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/src/tutorials/t01_epochs.md b/docs/src/tutorials/t01_epochs.md index 69d10c3..6dc09c1 100644 --- a/docs/src/tutorials/t01_epochs.md +++ b/docs/src/tutorials/t01_epochs.md @@ -92,7 +92,9 @@ The [`Epoch`](@ref) type supports a limited subset of basic mathematical and log e1 = Epoch(90.0, TT) e2 = Epoch(50.0, TT) -e1 - e2 +Δe = e1 - e2 + +value(Δe) e3 = Epoch(40, TAI) e1 - e3 @@ -163,7 +165,8 @@ eTAI = convert(TAI, e) A special remark must be made on the conversion between TAI and UTC. The offset between these two timescales is defined by a leap seconds, which are introduced to keep the UTC time scale within 0.9 seconds from UT1. Since the rotation of the Earth is irregular, it is not possible to predict when a new leap second will be introduced in the future. -The latest NAIF's leap second kernel ([LSK](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk)) is embedded within `Tempo` as a package artifact, which will be manually updated each time a new kernel is released, so that the user effort is minimised. Indeed, transforming an [`Epoch`](@ref) from a generic timescale to UTC is a simple as: +A leapsecond table is embedded within `Tempo` and will be manually updated each time a new +leapsecond is introduced, so that the effort required from the user side is minimised. Indeed, transforming an [`Epoch`](@ref) from a generic timescale to UTC is a simple as: ```@repl init e = Epoch(90.0, TT) From ca555e05f11332dd3ae70ea1bcc9a1d4d2b14855 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 10:58:54 +0200 Subject: [PATCH 3/6] Generalised path for Windows --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index b154da1..ca5689e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,5 +3,5 @@ using ERFA using Test @testset "Tempo.jl" verbose = true begin - include("Tempo/Tempo.jl") + include(joinpath("Tempo", "Tempo.jl")) end; From d31607f6ae5c18844f10dfe645bb3d9cd124ae61 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 11:01:48 +0200 Subject: [PATCH 4/6] Improved style --- src/Tempo.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Tempo.jl b/src/Tempo.jl index 4e8751d..193f1e7 100644 --- a/src/Tempo.jl +++ b/src/Tempo.jl @@ -38,18 +38,22 @@ include("offset.jl") export TIMESCALES, @timescale, add_timescale!, TimeSystem, timescale_alias, timescale_name, timescale_id + include("scales.jl") export Date, Time, year, month, day, find_dayinyear, j2000, j2000s,j2000c, hour, minute, second, DateTime + include("datetime.jl") include("origin.jl") -export Duration, value +export Duration, value + include("duration.jl") export Epoch, j2000, j2000s, j2000c, doy, timescale, value + include("epoch.jl") # Package precompilation routines From 4dadcd12c0192fca3c219722d5989981ea26af63 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 11:02:02 +0200 Subject: [PATCH 5/6] Removed duplicate function --- docs/src/api.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/src/api.md b/docs/src/api.md index 304373f..3bbde6b 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -19,7 +19,6 @@ find_dayinyear ### Duration ```@docs Duration -value ``` ### Types From 3e224983d4e3f119b6757fa3db8b79ac264ceb75 Mon Sep 17 00:00:00 2001 From: MicheleCeresoli Date: Thu, 1 Aug 2024 11:02:26 +0200 Subject: [PATCH 6/6] Added documentation on duration --- docs/src/tutorials/t01_epochs.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/tutorials/t01_epochs.md b/docs/src/tutorials/t01_epochs.md index 6dc09c1..7ed5ce7 100644 --- a/docs/src/tutorials/t01_epochs.md +++ b/docs/src/tutorials/t01_epochs.md @@ -99,7 +99,9 @@ value(Δe) e3 = Epoch(40, TAI) e1 - e3 ``` -Notice that this operation can be performed only if the two epochs are defined on the same timescale. +Notice that this operation can be performed only if the two epochs are defined on the same timescale. When computing the difference between two epochs, the result is returned in the +form of a [`Duration`](@ref) object. The [`value`](@ref) can then be used to retrieve the +actual number of seconds it represents. Epochs can also be shifted forward and backwards in time by adding or subtracting an arbitrary number of seconds: ```@repl init