-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Refactor Epoch to its own time scale #241
Conversation
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Ok i fixed several issues by auto deriving NB: it is considered bad practice to implement I moved to auto derivation for Eq and Hash. As far as PartialEq and Cmp ops go, we still implement ourselves, because we need to convert to identical time scales for an exact duration comparison |
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a superb start and exactly what I had envisioned!
src/epoch.rs
Outdated
tai_epoch.with_time_scale(TimeScale::TDB) | ||
} | ||
ts => { | ||
// first convert back to TAI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's correct. If I understand this correctly, it means that only ET and TDB have a different "tick" rate then the other time scales, i.e. one second in {TAI, UTC, GPS, GST, TT, ...} is one second in all of the other time scales, apart for TDB and ET. I think that is correct.
Co-authored-by: Chris <ChristopherRabotin@users.noreply.github.com>
Co-authored-by: Chris <ChristopherRabotin@users.noreply.github.com>
OK so most errors come from faulty From_gregorian and Compute_to_gregorian functions. I think I'm on the right track for Self::from_gregorian to which we now must add a notion of time scale. In V3, everything is referenced to TAI_J1900. So we have += 1900 hardcoded at some point, in from_gregorian(). |
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Sorry I dropped the ball on this, I totally forgot you were working on it. Let me see what I can do. |
Removed deprecated module
Update copyright
I think there is a bug in the Gregorian initialization because it does account for the hour in the reference epoch. The gregorian initialization and formatter should account for the reference epoch of the time scale.
The tests are nearly there, but I think that the one test that fails actually shows an error nested deep in the code, and I can't seem to figure out how to fix it yet. The conversion from a J1900 referenced epoch to a J2000 epoch is wrong by twelve hours. It so happens that the difference between these two references is indeed twelve hours: J1900 starts a noon but J2000 starts at midnight. What I don't understand is that the computation to/from ET/TDB (which are J2000 based) is correct according to all of the validation test cases. But when we compute the Gregorian time, the twelve hour difference is visible. So I don't know what is going on. |
Thank you for your time, I'll take a look into this next week end, see you |
@gwbres I might be able to pick up this work in September. Have you had time to review the issue I found ? I really hope that it's me misunderstanding something because the code is very close to being complete if the time difference is not a bug. |
Thanks for all your help here, I'll run the tests locally soon. Are the UTC and GNSS time scales nearly working? I can handle the TT, ET, TDB. |
This is due to the Display and Debug implementations. Although I would be OK with a diffrent debug behavior, I don't think the current Display behavior is right. What is your opinion on that ? it's confusing when dealing with a specific time scale, to see something expressed in UTC
Hard to say. For me, the following needs to be solved :
|
I'm happy changing the behavior of For the What's the issue with PartialEq ? I think that this makes sense, no?
|
Reverting to that state (now) |
Signed-off-by: Guillaume W. Bres <guillaume.bres@bertin.group>
I just don't see why having a case specific to Leap Seconds, 266 if self.time_scale.uses_leap_seconds() != other.time_scale.uses_leap_seconds() {
267 if self.time_scale.uses_leap_seconds() {
268 self.to_time_scale(other.time_scale).duration == other.duration
269 } else {
270 self.duration == other.to_time_scale(self.time_scale).duration
271 }
272 } else {
273 // Otherwise it does not matter
// --> this can manage the leap seconds
274 self.duration == other.to_time_scale(self.time_scale).duration
275 } |
I think that is a great idea |
Signed-off-by: Guillaume W. Bres <guillaume.bres@bertin.group>
Sorry some of my modifications yesterday were wrong. I reverted everything to the best state we had.. My understanding is, we're correct on compute_gregorian, and almost correct in maybe_from_gregorian(). |
Signed-off-by: Guillaume W. Bres <guillaume.bres@bertin.group>
Signed-off-by: Guillaume W. Bres <guillaume.bres@bertin.group>
{:?} for an Epoch now shows the duration in the associated timescale. Signed-off-by: Guillaume W. Bres <guillaume.bres@bertin.group>
I just pushed a commit that modifies the std::fmt::Debug behavior for Epoch. It now prints the duration in the associated time scale. I think it's a very good idea you had and we should not forget it. std::fmt::Display is the one intended for the end user. |
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Hello @ChristopherRabotin Can you please review what's being tested in tests/epoch.rs There is something terribly wrong with this test, either how it's designed or how it's operated. How can a duration ("from_dur") built from a different timescale, be the same as a UTC duration. I just pushed a commit that modifies the PartialEq behavior (see Epoch::PartialEq), and this test is the only one that used to pass, now fails due to that modification. Might be a good thing ? Any chances to make progress on this topic in the near future? |
I think that this test is obsolete now with the new design: it used to be important because we would convert from the initialization time scale to TAI every time, so the test would make sure that if we initialized at Epoch X in time scale T, when it was converted to TAI and then requested back in T, then the same epoch X would be returned. I think this test can be deleted now. |
I'm OK with the changes to PartialEq. The previous implementation was trying to be clever, but maybe the better use case is to ask the user to convert both epochs to the same time scale before comparing them. |
Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
@gwbres I have a bit more clarity on my schedule, and I think I can pick up the work on this in February. I've also been thinking more about this, and I now think that this change can be (and should be) merged into the same 3.x version of hifitime. Although in theory any changes to the enums are considered breaking changes, I think it's unlikely that users perform a What do you think? |
It sounds good to me. #[derive(PartialEq)]
pub struct Epoch {
Duration,
TimeScale would return true when dur(a) == dur(b) && timescale(a) == timescale(b). |
Good reminder!
…On Wed, Jan 3, 2024, 15:02 gwbres ***@***.***> wrote:
It sounds good to me.
The only thing to be careful with this new definition, is the Eq operator.
Auto derivation is not possible because auto derivation :
#[derive(PartialEq)]pub struct Epoch {
Duration,
TimeScale
would return true when dur(a) == dur(b) && timescale(a) == timescale(b).
This behavior is very wrong because it is possible to represent the same
"time" with different durations in different timescale.
I'm very used to working with GPST for example, let's take the Midnight
UTC example, GPST is late by the amount of leap second, so midnight UTC and
23:59:23 GPST are the same instant.
Conclusion : Eq needs to be manually implemented and requires the
conversion into a common timescale
—
Reply to this email directly, view it on GitHub
<#241 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEZV2BGFZPLV7XPK5AE2ATYMXIQ7AVCNFSM6AAAAAAYRXUYJKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZWGAZDSMRYGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I don't know if continuing this branch is the way to go, it is one possibility. |
This should not have been closed ! I didn't expect that delete the 4.0.0-dev branch would close this PR. Can you re-open it directly against |
Sure, I will take care of this in the next few days
Guillaume W. Bres
Software engineer
***@***.***>
Le sam. 13 janv. 2024 à 19:48, Chris ***@***.***> a écrit :
… This should not have been closed ! I didn't expect that delete the
4.0.0-dev branch would close this PR. Can you re-open it directly against
master?
—
Reply to this email directly, view it on GitHub
<#241 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABXPAQYRORBFLEM4BUW6VI3YOLJG5AVCNFSM6AAAAAAYRXUYJKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJQGY4TOOJYGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Trying to see how complex answering to #237 would be.
Epoch::j1900_duration
Epoch::to_time_scale
: follow naming conventionsEpoch::with_time_scale
is just a construction helper (follows naming conventions too)rhs.to_time_scale(self.ts)
so the computation is feasiblecmp
andeq
ops, but i'm not sure it really makes sense to go this far.Maybe strict equality/comparison between both self.duration and self.ts is enough. Right now, the current code produces a funny behavior where .eq() fails for two identical datetimes:
Epoch::to_time_scale(TimeScale::TDB)
and other time scales that need to refer to J2000 may not be feasible if we come from a datetime that is not past J2000 (i marked aTODO
)Epoch::maybe_from_gregorian
possibly broken, although I kept the previous logic and it should be closed to workingEpoch::compute_gregorian
, used all over the place, might no longer work because self is no longer referenced to J1900