-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implement toZonedDateTime in PlainDate #192
base: main
Are you sure you want to change the base?
Implement toZonedDateTime in PlainDate #192
Conversation
Thank you for contributing! Yeah, the most difficult part about this is that we can't do a 1-to-1 implementation of the spec because As a good rule of thumb, every time you see something like "if o is an object" or "Get(o, 'property')", assume those calculations are made by the engine, and try to receive a struct or an enum as a parameter instead. |
In this case, you should just take an |
Agree with the comments above. For further reference to a similar method implementation wise if you'd like to see how this was handled elsewhere in the library, feel free to check out |
Updated the code now. Think im closer to a somewhat solution now. Would appricate some feedback! @jedel1043 @nekevss . Thanks! |
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 good start so far! I've left a few comments on points that could be improved.
My general recommendation is try and follow steps by coupling the code together with the commented steps (see duration for an example). I believe most of the internals used in these steps do exist in the codebase, so using the specification steps as a guide can be incredibly useful.
This method is a bit tricky as steps 1-4 require engine specific details, but we can guarantee they are completed by the types of the function args, so the real starting point, as already identified, is step 5.
Updated now! Little bit hard to test since the api needs to work correctly. I think? |
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.
Looking closer, I left a handful of things I noticed when looking.
When working with rust, it's useful to use the compiler and cargo to help you.
I'd recommend running:
cargo fmt -all
, cargo clippy --no-default-features
, and cargo clippy --all-features --all-targets
The compiler errors and lints can help massively when working on some code. Also, we use those commands in our CI, so it is needed to pass CI too.
src/builtins/core/date.rs
Outdated
}; | ||
|
||
// 7. Return ! CreateTemporalZonedDateTime(epochNs, timeZone, temporalDate.[[Calendar]]). | ||
Self::try_new(epoch_ns.0, self.calendar.clone(), tz) |
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.
issue: missing bracket to close function
src/builtins/compiled/date.rs
Outdated
impl Date { | ||
|
||
/// Converts a `Date` to a `ZonedDateTime` in the UTC time zone. | ||
pub fn to_zoned_date_time (self, time_zone: &str) -> TemporalResult<crate::ZonedDateTime> { |
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.
issue: function signature here should be the same as to_zoned_date_time_with_provider
.
Also, it looks like there is a space after the function name. Although, I'm not entirely sure whether that may affect anything.
src/builtins/compiled/date.rs
Outdated
let provider = TZ_PROVIDER | ||
.lock() | ||
.map_err(|_| TemporalError::general("Unable to acquire lock"))?; | ||
self.to_zoned_date_time_with_provider(time_zone, &*provider) |
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.
issue: to_zoned_date_time_with_provider
is called with the wrong args.
self.to_zoned_date_time_with_provider(time_zone, plain_time, &*provider)
src/builtins/core/date.rs
Outdated
// c. If ISODateTimeWithinLimits(isoDateTime) is false, throw a RangeError exception. | ||
// d. Let epochNs be ? GetEpochNanosecondsFor(timeZone, isoDateTime, compatible). | ||
let epoch_ns = if let Some(time) = plain_time { | ||
let temporal_time = Time::new_unchecked(time)?; |
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.
issue: I'm not entirely sure what the time is referring to here. But it should be unneeded.
You should be able to access PlainTime
's iso field by using time.iso
in line 685.
src/builtins/compiled/date.rs
Outdated
@@ -0,0 +1,12 @@ | |||
use crate::{builtins::TZ_PROVIDER, TemporalError, TemporalResult, Date}; | |||
|
|||
impl Date { |
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.
issue: wrong struct name on the impl block -> PlainDate
Ah, currently Due the current default |
The code compilies now! But all the test fails :(. My expirence with rust is slim to zero, so i was wondering what the best practice is to debug the code. For now i've tried to insert code in the functions, but it don't get printed in the terminal. I want to see the value of a variable at a certain point. I've heard with some others and they decided to create their own test. Is this the optimal way? Thanks again! |
If you use rust-analyzer on VSCode, you can pretty easily hit the "debug" label on any test and it should put you on a debugger environment. |
Related to #148
First time contributer, not sure if is correct. Tought this might be a good place to get some feedback while showcasing the code.
Struggling to choose type for the item and how to check if it is an object.
Thanks for the feedback!
Link to method
In kahoots with @brageh01