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.
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? |
nekevss
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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. |
|
Added some tests now! And all of them passed, but not sure if this is correct. Thanks for the feedback! |
There was a problem hiding this comment.
One nit related to the lint failure.
Also for cargo fmt failure, sometimes you need to run cargo fmt --all to format the tests. You probably ran cargo fmt, which formatted the code but missed the tests. So running cargo fmt --all should get the tests. 😄
src/builtins/core/date.rs
Outdated
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[cfg(all(test, feature = "tzdb"))] |
There was a problem hiding this comment.
nit: the feature configuration shouldn't be here I think. You should be able to configure specific tests. With #[cfg(feature = "tzdb"] above the specific tests. I think references can be found in other test modules.
…temporal into impl-to-zoned-date-time
|
Try to run the command, but didn't get any errors. Anyhow, updated it now. However there seems to be an error on line 82 for me, which comes from another merge. |
|
So run |
nekevss
left a comment
There was a problem hiding this comment.
LGTM! This should be good to go once the formatting is fixed.
Thanks for working on this!
|
Nice! Tried running the command now. Hope it worked! |
|
Looks great! Thanks for putting all the work into this! 😄 |
Related to boa-dev#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 ](https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype.tozoneddatetime) In kahoots with @brageh01

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