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

src/epoch.rs: fix gh 187 #188

Merged
merged 4 commits into from
Dec 7, 2022
Merged

Conversation

gwbres
Copy link
Collaborator

@gwbres gwbres commented Dec 6, 2022

  • fix conversion from and to elapsed weeks

Signed-off-by: Guillaume W. Bres guillaume.bressaix@gmail.com

@gwbres
Copy link
Collaborator Author

gwbres commented Dec 6, 2022

Hello Chris,

with the following src/epoch.rs modifications, I can unlock reciprocal tests of every time_of_week existing tests.

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2022

Codecov Report

Base: 80.63% // Head: 80.37% // Decreases project coverage by -0.26% ⚠️

Coverage data is based on head (5ec7c80) compared to base (aa1ea21).
Patch coverage: 68.29% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
- Coverage   80.63%   80.37%   -0.27%     
==========================================
  Files          10       10              
  Lines        2794     2792       -2     
==========================================
- Hits         2253     2244       -9     
- Misses        541      548       +7     
Impacted Files Coverage Δ
src/weekday.rs 83.54% <ø> (ø)
src/epoch.rs 87.57% <68.29%> (-0.39%) ⬇️
src/timescale.rs 90.90% <0.00%> (-2.03%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

src/epoch.rs Outdated
// remove previously determined nb of weeks
// get residual nanoseconds
let nanoseconds = total_nanoseconds
- weeks * NANOSECONDS_PER_DAY as i128 * Weekday::DAYS_PER_WEEK_I64 as i128;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when working with self.to_duration().to_unit(x) i'm always facing rounding issues right here.
So I decided to move to total_nanoseconds() ..

@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Dec 6, 2022 via email

@gwbres
Copy link
Collaborator Author

gwbres commented Dec 6, 2022

In general, I try to avoid operations on i128 because that's a very big
type and will be very slow on embedded systems (most are 32 bit, so it
needs four registers per operation).

Yeah I know, that is why I was trying something like this

2253     #[must_use]
2254     /// Converts this epoch into the time of week, represented as a rolling week counter into that time scale
2255     /// and the number of nanoseconds elapsed in current week (since closest Sunday midnight).
2256     /// This is usually how GNSS receivers describe a timestamp.
2257     pub fn to_time_of_week(&self) -> (u32, u64) {
2258         let days = self.to_duration().to_unit(Unit::Day);
2260         // nb of weeks
2261         let weeks = days / Weekday::DAYS_PER_WEEK;
2262         // nanoseconds within current week
2263         //   is total number of nanoseconds
2264         //   - number of nanoseconds contained in whole days
2264         let nanoseconds = self.to_duration().to_unit(Unit::Nanosecond) //total
2265             - weeks /7.0 /24.0 /3600.0 /1.0E9; // remove those already contained in whole "weeks"
2267         (weeks.trunc() as u32, nanoseconds as u64)
2268     }

src/timescale.rs Outdated
@@ -121,6 +121,14 @@ impl TimeScale {
Self::TT | Self::TAI | Self::UTC => J1900_REF_EPOCH,
}
}

pub const fn ref_weekday(&self) -> Weekday {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this,
since the current proposal does not use it

- fix conversion from and to elapsed weeks

Signed-off-by: Guillaume W. Bres <guillaume.bressaix@gmail.com>
Also renamed `ts` to `time_scale` in function parameters (does not affect API)

Signed-off-by: Christopher Rabotin <christopher.rabotin@gmail.com>
Signed-off-by: Christopher Rabotin <christopher.rabotin@gmail.com>
Signed-off-by: Christopher Rabotin <christopher.rabotin@gmail.com>
@ChristopherRabotin ChristopherRabotin merged commit 783af30 into nyx-space:master Dec 7, 2022
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.

from_time_of_week is not the reciprocate of to_time_of_week when the reference epoch is J1900
3 participants