-
-
Notifications
You must be signed in to change notification settings - Fork 497
Expand file tree
/
Copy pathdate.cc
More file actions
45 lines (31 loc) · 1017 Bytes
/
date.cc
File metadata and controls
45 lines (31 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "napi.h"
using namespace Napi;
#if (NAPI_VERSION > 4)
namespace {
Value CreateDate(const CallbackInfo& info) {
double input = info[0].As<Number>().DoubleValue();
return Date::New(info.Env(), input);
}
Value IsDate(const CallbackInfo& info) {
Date input = info[0].As<Date>();
return Boolean::New(info.Env(), input.IsDate());
}
Value ValueOf(const CallbackInfo& info) {
Date input = info[0].As<Date>();
return Number::New(info.Env(), input.ValueOf());
}
Value OperatorValue(const CallbackInfo& info) {
Date input = info[0].As<Date>();
return Boolean::New(info.Env(),
input.ValueOf() == static_cast<double>(input));
}
} // anonymous namespace
Object InitDate(Env env) {
Object exports = Object::New(env);
exports["CreateDate"] = Function::New(env, CreateDate);
exports["IsDate"] = Function::New(env, IsDate);
exports["ValueOf"] = Function::New(env, ValueOf);
exports["OperatorValue"] = Function::New(env, OperatorValue);
return exports;
}
#endif