Skip to content

Commit 6dda28f

Browse files
committed
Address review comments; add docs
1 parent 4d08df7 commit 6dda28f

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

doc/date.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ static Napi::Date Napi::Date::New(Napi::Env env, double value);
3737

3838
Returns a new instance of `Napi::Date` object.
3939

40+
### New
41+
42+
Creates a new instance of a `Napi::Date` object.
43+
44+
```cpp
45+
static Napi::Date Napi::Date::New(napi_env env, std::chrono::system_clock::time_point time_point);
46+
```
47+
48+
- `[in] env`: The environment in which to construct the `Napi::Date` object.
49+
- `[in] value`: The point in time, represented by an
50+
`std::chrono::system_clock::time_point`.
51+
52+
Returns a new instance of `Napi::Date` object.
53+
4054
### ValueOf
4155
4256
```cpp

napi-inl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#endif // NAPI_HAS_THREADS
2121
#include <type_traits>
2222
#include <utility>
23-
#if __cplusplus >= 201103L
24-
#include <chrono>
25-
#endif
2623

2724
#if defined(__clang__) || defined(__GNUC__)
2825
#define NAPI_NO_SANITIZE_VPTR __attribute__((no_sanitize("vptr")))
@@ -1202,14 +1199,12 @@ inline Date Date::New(napi_env env, double val) {
12021199
return Date(env, value);
12031200
}
12041201

1205-
#if __cplusplus >= 201103L
12061202
inline Date Date::New(napi_env env, std::chrono::system_clock::time_point tp) {
12071203
using namespace std::chrono;
12081204
auto ms = static_cast<double>(
12091205
duration_cast<milliseconds>(tp.time_since_epoch()).count());
12101206
return Date::New(env, ms);
12111207
}
1212-
#endif
12131208

12141209
inline void Date::CheckCast(napi_env env, napi_value value) {
12151210
NAPI_CHECK(value != nullptr, "Date::CheckCast", "empty value");

napi.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
#if NAPI_HAS_THREADS
1818
#include <mutex>
1919
#endif // NAPI_HAS_THREADS
20+
#include <chrono>
2021
#include <string>
2122
#include <vector>
22-
#if __cplusplus >= 201103L
23-
#include <chrono>
24-
#endif
2523

2624
// VS2015 RTM has bugs with constexpr, so require min of VS2015 Update 3 (known
2725
// good version)
@@ -690,8 +688,8 @@ class Date : public Value {
690688

691689
/// Creates a new Date value from a std::chrono::system_clock::time_point.
692690
static Date New(
693-
napi_env env, ///< Node-API environment
694-
std::chrono::system_clock::time_point tp ///< Time point value
691+
napi_env env, ///< Node-API environment
692+
std::chrono::system_clock::time_point time_point ///< Time point value
695693
);
696694

697695
static void CheckCast(napi_env env, napi_value value);

test/date.cc

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

73
using namespace Napi;
@@ -15,12 +11,10 @@ Value CreateDate(const CallbackInfo& info) {
1511
return Date::New(info.Env(), input);
1612
}
1713

18-
#if __cplusplus >= 201103L
1914
Value CreateDateFromTimePoint(const CallbackInfo& info) {
2015
auto input = std::chrono::system_clock::time_point{};
2116
return Date::New(info.Env(), input);
2217
}
23-
#endif
2418

2519
Value IsDate(const CallbackInfo& info) {
2620
Date input = info[0].As<Date>();
@@ -46,7 +40,8 @@ Value OperatorValue(const CallbackInfo& info) {
4640
Object InitDate(Env env) {
4741
Object exports = Object::New(env);
4842
exports["CreateDate"] = Function::New(env, CreateDate);
49-
exports["CreateDateFromTimePoint"] = Function::New(env, CreateDate);
43+
exports["CreateDateFromTimePoint"] =
44+
Function::New(env, CreateDateFromTimePoint);
5045
exports["IsDate"] = Function::New(env, IsDate);
5146
exports["ValueOf"] = Function::New(env, ValueOf);
5247
exports["OperatorValue"] = Function::New(env, OperatorValue);

test/date.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ function test (binding) {
99
CreateDate,
1010
IsDate,
1111
ValueOf,
12-
OperatorValue
12+
OperatorValue,
13+
CreateDateFromTimePoint
1314
} = binding.date;
1415
assert.deepStrictEqual(CreateDate(0), new Date(0));
1516
assert.deepStrictEqual(CreateDateFromTimePoint(), new Date(0));

0 commit comments

Comments
 (0)