-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #639 from neon-bindings/feat/date-api
feat: impl Date API
- Loading branch information
Showing
11 changed files
with
362 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use std::mem::MaybeUninit; | ||
use crate::napi::bindings as napi; | ||
use crate::raw::{Env, Local}; | ||
|
||
/// Create a new date object | ||
/// | ||
/// # Safety | ||
/// | ||
/// `env` is a raw pointer. Please ensure it points to a napi_env that is valid for the current context. | ||
pub unsafe fn new_date(env: Env, value: f64) -> Local { | ||
let mut local = MaybeUninit::zeroed(); | ||
let status = napi::create_date(env, value, local.as_mut_ptr()); | ||
assert_eq!(status, napi::Status::Ok); | ||
local.assume_init() | ||
} | ||
|
||
/// Get the value of a date object | ||
/// | ||
/// # Safety | ||
/// | ||
/// `env` is a raw pointer. Please ensure it points to a napi_env that is valid for the current context. | ||
/// `Local` must be an NAPI value associated with the given `Env` | ||
pub unsafe fn value(env: Env, p: Local) -> f64 { | ||
let mut value = 0.0; | ||
let status = napi::get_date_value(env, p, &mut value as *mut _); | ||
assert_eq!(status, napi::Status::Ok); | ||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.