Skip to content

Commit 4d08df7

Browse files
committed
Add Date::New time point unit test
1 parent 5ecb616 commit 4d08df7

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

napi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#endif // NAPI_HAS_THREADS
2020
#include <string>
2121
#include <vector>
22+
#if __cplusplus >= 201103L
23+
#include <chrono>
24+
#endif
2225

2326
// VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known
2427
// good version)

test/date.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#if __cplusplus >= 201103L
2+
#include <chrono>
3+
#endif
4+
15
#include "napi.h"
26

37
using namespace Napi;
@@ -11,6 +15,13 @@ Value CreateDate(const CallbackInfo& info) {
1115
return Date::New(info.Env(), input);
1216
}
1317

18+
#if __cplusplus >= 201103L
19+
Value CreateDateFromTimePoint(const CallbackInfo& info) {
20+
auto input = std::chrono::system_clock::time_point{};
21+
return Date::New(info.Env(), input);
22+
}
23+
#endif
24+
1425
Value IsDate(const CallbackInfo& info) {
1526
Date input = info[0].As<Date>();
1627

@@ -35,6 +46,7 @@ Value OperatorValue(const CallbackInfo& info) {
3546
Object InitDate(Env env) {
3647
Object exports = Object::New(env);
3748
exports["CreateDate"] = Function::New(env, CreateDate);
49+
exports["CreateDateFromTimePoint"] = Function::New(env, CreateDate);
3850
exports["IsDate"] = Function::New(env, IsDate);
3951
exports["ValueOf"] = Function::New(env, ValueOf);
4052
exports["OperatorValue"] = Function::New(env, OperatorValue);

test/date.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function test (binding) {
1212
OperatorValue
1313
} = binding.date;
1414
assert.deepStrictEqual(CreateDate(0), new Date(0));
15+
assert.deepStrictEqual(CreateDateFromTimePoint(), new Date(0));
1516
assert.strictEqual(IsDate(new Date(0)), true);
1617
assert.strictEqual(ValueOf(new Date(42)), 42);
1718
assert.strictEqual(OperatorValue(new Date(42)), true);

0 commit comments

Comments
 (0)