0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/js-native-api/test_date/test.js
Jarrod Connolly 13b1aafe87 n-api: implement date object
Implements `napi_create_date()` as well as `napi_is_date()` to
allow working with JavaScript Date objects.

PR-URL: https://github.com/nodejs/node/pull/25917
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-28 17:43:37 -05:00

22 lines
736 B
JavaScript

'use strict';
const common = require('../../common');
// This tests the date-related n-api calls
const assert = require('assert');
const test_date = require(`./build/${common.buildType}/test_date`);
const dateTypeTestDate = test_date.createDate(1549183351);
assert.strictEqual(test_date.isDate(dateTypeTestDate), true);
assert.strictEqual(test_date.isDate(new Date(1549183351)), true);
assert.strictEqual(test_date.isDate(2.4), false);
assert.strictEqual(test_date.isDate('not a date'), false);
assert.strictEqual(test_date.isDate(undefined), false);
assert.strictEqual(test_date.isDate(null), false);
assert.strictEqual(test_date.isDate({}), false);
assert.strictEqual(test_date.getDateValue(new Date(1549183351)), 1549183351);