Skip to content

Utilize EpochNanoseconds #261

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

JohannesHelleve
Copy link
Contributor

@JohannesHelleve JohannesHelleve commented Apr 16, 2025

Solves #119
Started fresh up the code, one test failing in the instant class still.

Im a commits behind, but wanted to merge when the code was working locally first.

Some things i'm unsure about:

  • When to use borrowed or owned. Used both in different places, but not sure what is optimal.
  • When to use EpochNanoseconds(...) or EpochNanoseconds::try_from(...)?/.unwrap

Thanks!

Let me know if you have any quick comments

@JohannesHelleve
Copy link
Contributor Author

Hm. All the previous commits from my previous branch also got added. Will need to check into that as well.

Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Was taking a look through, and thought I'd leave a couple comments / thoughts that I noticed.

}

/// Creates a new `Instant` from the provided Epoch millisecond value.
pub fn from_epoch_milliseconds(epoch_milliseconds: i64) -> TemporalResult<Self> {
pub fn from_epoch_milliseconds(epoch_milliseconds: EpochNanoseconds) -> TemporalResult<Self> {
Copy link
Member

@nekevss nekevss Apr 18, 2025

Choose a reason for hiding this comment

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

Hmmmmm, I believe this isn't entirely correct since we are dealing with milliseconds vs. nanoseconds. This should probably be left as is or a new EpochMilliseconds primitive type could be introduced with an internal representation of i64.

let nanos = self.get_offset_nanos_for(instant.as_i128(), provider)?;
IsoDateTime::from_epoch_nanos(instant.epoch_nanoseconds(), nanos.to_i64().unwrap_or(0))
let nanos = self.get_offset_nanos_for(instant.epoch_nanoseconds(), provider)?;
IsoDateTime::from_epoch_nanos(instant.epoch_nanoseconds(), nanos.as_i128().to_i64().unwrap_or(0))
Copy link
Member

Choose a reason for hiding this comment

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

thought: I think to_i64 could be implemented directly on EpochNanoseconds as a method. We're already doing the bound check, so it could be a nice addition from an ergonomics perspective.

@JohannesHelleve
Copy link
Contributor Author

Not so well with git so not sure to do with that mistake.

Updated from your feedback. Thanks!

Added the helper method.

Altered a test, but should have the same functionality?

Copy link
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Hey! Sorry for the delayed review on this. To be honest, I'm not entirely sure what to make of this PR (and not because there is anything necessarily wrong with it) at least until we have built out the provider crate a bit more thoroughly. I'm fairly convinced that using EpochNanoseconds more thoroughly is a good thing, but I'm not entirely sure to what degree currently.

I think this may be soft blocked until we are a bit further into the process of setting up the provider crate and have a better idea of what should live where.

I left some comments explaining my general thoughts.

@@ -43,6 +43,10 @@ impl EpochNanoseconds {
pub fn as_i128(&self) -> i128 {
self.0
}

pub fn as_i64(&self) -> i64 {
Copy link
Member

Choose a reason for hiding this comment

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

Hmmmmm, I think this needs to be an Option<i64>. It's be a while so I could be misremembering, but I believe the max nanoseconds exceeds an i64.

@@ -66,14 +66,14 @@ pub trait TimeZoneProvider {
fn get_named_tz_offset_nanoseconds(
&self,
identifier: &str,
epoch_nanoseconds: i128,
epoch_nanoseconds: EpochNanoseconds,
Copy link
Member

Choose a reason for hiding this comment

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

thought: I'm a little concerned about adding the EpochNanoseconds to the TimeZoneProvider trait.

Mostly because the current plan is to move TimeZoneProvider out of temporal_rs. So tying in a temporal_rs type to the TimeZoneProvider's interface creates a small problem of what should be done with EpochNanoseconds when the trait is moved. 😕

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