Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create NODE_UNIXTIME macros

  • Loading branch information...
commit 2f46540d3037e1b91d0c86d00a19cf031a19b1b6 1 parent ba6c5e3
@ry ry authored
Showing with 11 additions and 8 deletions.
  1. +3 −4 src/file.cc
  2. +1 −1  src/net.cc
  3. +4 −0 src/node.h
  4. +3 −3 src/timer.cc
View
7 src/file.cc
@@ -58,7 +58,6 @@ EIOPromise::Create (void)
return promise;
}
-#define NODE_UNIXTIME(t) v8::Date::New(1000*static_cast<double>(t))
int
EIOPromise::After (eio_req *req)
{
@@ -106,9 +105,9 @@ EIOPromise::After (eio_req *req)
stats->Set(SIZE_SYMBOL, Integer::New(s->st_size)); /* total size, in bytes */
stats->Set(BLKSIZE_SYMBOL, Integer::New(s->st_blksize)); /* blocksize for filesystem I/O */
stats->Set(BLOCKS_SYMBOL, Integer::New(s->st_blocks)); /* number of blocks allocated */
- stats->Set(ATIME_SYMBOL, NODE_UNIXTIME(s->st_atime)); /* time of last access */
- stats->Set(MTIME_SYMBOL, NODE_UNIXTIME(s->st_mtime)); /* time of last modification */
- stats->Set(CTIME_SYMBOL, NODE_UNIXTIME(s->st_ctime)); /* time of last status change */
+ stats->Set(ATIME_SYMBOL, NODE_UNIXTIME_V8(s->st_atime)); /* time of last access */
+ stats->Set(MTIME_SYMBOL, NODE_UNIXTIME_V8(s->st_mtime)); /* time of last modification */
+ stats->Set(CTIME_SYMBOL, NODE_UNIXTIME_V8(s->st_ctime)); /* time of last status change */
argc = 1;
argv[0] = stats;
break;
View
2  src/net.cc
@@ -328,7 +328,7 @@ Connection::SetTimeout (const Arguments& args)
Connection *connection = ObjectWrap::Unwrap<Connection>(args.This());
assert(connection);
- float timeout = (float)(args[0]->IntegerValue()) / 1000;
+ float timeout = NODE_V8_UNIXTIME(args[0]);
connection->SetTimeout(timeout);
View
4 src/node.h
@@ -11,6 +11,10 @@
namespace node {
+/* Converts a unixtime to V8 Date */
+#define NODE_UNIXTIME_V8(t) v8::Date::New(1000*static_cast<double>(t))
+#define NODE_V8_UNIXTIME(v) ((double)((v)->IntegerValue())/1000.0);
+
#define NODE_DEFINE_CONSTANT(target, constant) \
(target)->Set(v8::String::NewSymbol(#constant), \
v8::Integer::New(constant))
View
6 src/timer.cc
@@ -51,7 +51,7 @@ Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorI
assert(timer);
assert(property == REPEAT_SYMBOL);
- timer->watcher_.repeat = (double)(value->IntegerValue()) / 1000;
+ timer->watcher_.repeat = NODE_V8_UNIXTIME(value);
}
void
@@ -91,8 +91,8 @@ Timer::Start (const Arguments& args)
if (args.Length() != 2)
return ThrowException(String::New("Bad arguments"));
- ev_tstamp after = (double)(args[0]->IntegerValue()) / 1000.0;
- ev_tstamp repeat = (double)(args[1]->IntegerValue()) / 1000.0;
+ ev_tstamp after = NODE_V8_UNIXTIME(args[0]);
+ ev_tstamp repeat = NODE_V8_UNIXTIME(args[1]);
ev_timer_init(&timer->watcher_, Timer::OnTimeout, after, repeat);
timer->watcher_.data = timer;
Please sign in to comment.
Something went wrong with that request. Please try again.