-
Notifications
You must be signed in to change notification settings - Fork 286
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
feat: impl Date API #639
feat: impl Date API #639
Conversation
0999e56
to
342d740
Compare
a716bcc
to
f538442
Compare
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.
Looks good! Just a few minor comments.
853a345
to
aef0f86
Compare
aef0f86
to
9131811
Compare
Hey peeps. Any news on this one? Having it would be really helpful in our team. Thanks! |
@arthrarnld It's a work in progress. We're still discussing the best way to handle an out of range time. Let us know if you have any thoughts! If you need this feature now, it can be implemented outside of Neon. fn global_date<'a, C: Context<'a>>(cx: &mut C) -> JsResult<'a, JsFunction> {
cx.global()
.get(cx, "Date")?
.downcast::<JsFunction>()
.or_throw(cx)
}
fn create_date<'a, C: Context<'a>>(
cx: &mut C,
n: f64,
) -> JsResult<'a, JsObject> {
let date = global_date(cx)?;
let args = vec![cx.number(n)];
date.construct(cx, args)
}
// Doesn't really validate that it's a date, just that it has a `now()` function
// that returns a `number`. Could validate with `isPrototypeOf`, but probably not worth it.
fn date_value<'a, C: Context<'a>>(
cx: &mut C,
o: Handle<JsObject>,
) -> NeonResult<f64> {
let now = o.get(cx, "now")?.downcast::<JsFunction>().or_throw(cx)?;
let args = Vec::<Handle<JsValue>>::with_capacity(0);
let res = now.call(cx, o, args)?.downcast::<JsNumber>().or_throw(cx)?;
Ok(res.value())
} |
1e5ae76
to
072d5bf
Compare
5818563
to
352737e
Compare
e73c716
to
24ab88e
Compare
f21e5e3
to
7a5ae29
Compare
4f10550
to
22a7ea9
Compare
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.
@amilajack This looks great! Before merging, let's decide whether we want this feature flagged or not prior to merging the RFC.
Implements neon-bindings/rfcs#18
JsDate::new
JsDate::new_lossy
JsDate::try_new
JsDate::is_date
JsDate::is_valid