-
Notifications
You must be signed in to change notification settings - Fork 9
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
RFC: Date API #18
RFC: Date API #18
Conversation
…t for `value()` for compatibility with N-API. Add an `is_valid()` method for checking if a `Date` value is in the legal range.
@kjvalencik @dherman should this be merged if ready? |
We still have a few open design questions to settle before it's quite ready to merge. Once we do we'll put it into "final comment period" for a week before merging. |
pub const MIN_VALID_VALUE: f64 = -8640000000000000; | ||
pub const MAX_VALID_VALUE: f64 = 8640000000000000; | ||
|
||
pub fn new<'a, C: Context<'a>, V: Into<f64>>(_: &mut S, value: V) -> JsResult<JsDate>; |
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.
I don't think this should be a JsResult
since the Date
API shouldn't throw unless we are already in a throwing state.
I do think it should return an Error
if the value is out of bounds. I don't think it's safe to depend on being able to get the original value back out since that's not part of the contract/spec.
impl JsDate {
/// Produces a _valid_ `Date` or a `DateError`
pub fn new<'a, C: Context<'a>, V: Into<f64>>(_: &mut S, value: V) -> Result<Handle<'a, JsDate>, DateError>;
/// Produces a `Date` which _could_ be invalid
pub fn new_unchecked<'a, C: Context<'a>, V: Into<f64>>(_: &mut S, value: V) -> Handle<'a, JsDate>;
}
enum DateError {
OutOfRangeLow,
OutOfRangeHigh,
}
impl Error for DateError {}
impl<'a> JsResultExt<'a, JsString> for Result<Handle<'a, JsDate>, DateError> {
/// Creates a `RangeError` on error
fn or_throw<'b, C: Context<'b>>(self, cx: &mut C) -> JsResult<'a, JsDate>;
}
pub const MAX_VALID_VALUE: f64 = 8640000000000000; | ||
|
||
pub fn new<'a, C: Context<'a>, V: Into<f64>>(_: &mut S, value: V) -> JsResult<JsDate>; | ||
pub fn value<'a, C: Context<'a>>(self, cx: &mut C) -> f64; |
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.
Note: We should include in the documentation that this could be NaN
.
Should this be closed or merged? cc @kjvalencik @dherman |
@amilajack I've added the "final comment period" label. Let's give it a week and if no issues pop-up we can merge. 👍 |
A simple API for exposing JS Date objects to Rust.
Rendered