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

25 implement duration as a subtype of number #26

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

MicheleCeresoli
Copy link
Member

@MicheleCeresoli MicheleCeresoli commented Jul 29, 2024

@andreapasquale94 let's discuss whether these could be usefull changes:

  1. Duration has been made a chlild of Number. The constructors have been reworked to avoid code repetitions. The constructor Duration(sec::Int, frac::T) has been removed since it equals the default type constructor.
  2. Base.convert and Base.promote_rule have been implemented for Duration. Currently Base.convert can be used in two ways (although the first option could be removed):
julia> d = Duration(1)
Duration{Int64}(1, 0)

julia> convert(Float64, d)
Duration{Float64}(1, 0.0)

julia> convert(Duration{Float64}, d)
Duration{Float64}(1, 0.0)
  1. The ftype function has been added to retrieve the type in which the fractional part of the Duration is represented.

  2. Epoch constructors have also been updated to reflect the above changes and avoid code repetitions.

  3. Addition and subtraction implementations of Epoch have been simplified. Additionally, they now properly propagate types. In the previous implementation, summing an epoch of type Epoch{TDB, Float64} with a duration or number of type BigFloat would improperly return an epoch in Float64 representation, leading to a loss in accuracy. Now, the result is expressed using the highest accuracy type (i.e., the one resulting from the promote_rule operation).

  4. The step length operation to generate a range of epochs with a daily step range has been re-implemented. Thus ep1:ep2 now properly works again.

Note that even though Duration is a subtype of Number, all operations that have not been defined, i.e., multiplication and division, will return an error upon execution.

src/duration.jl Outdated Show resolved Hide resolved
@andreapasquale94
Copy link
Member

Apart from those minor comments, I would be happy to merge 👯

@MicheleCeresoli MicheleCeresoli merged commit d51e487 into dev Aug 1, 2024
8 checks passed
@MicheleCeresoli MicheleCeresoli deleted the 25-implement-duration-as-a-subtype-of-number branch August 1, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants