Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24 fix v13 documentation #27

Merged
merged 6 commits into from
Aug 1, 2024
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
11 changes: 8 additions & 3 deletions docs/src/tutorials/t01_epochs.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,16 @@ 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
```
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
Expand Down Expand Up @@ -163,7 +167,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)
Expand Down
6 changes: 5 additions & 1 deletion src/Tempo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 32 additions & 1 deletion src/duration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

# ---
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ using ERFA
using Test

@testset "Tempo.jl" verbose = true begin
include("Tempo/Tempo.jl")
include(joinpath("Tempo", "Tempo.jl"))
end;
Loading