Browse Source

Create NODE_UNIXTIME macros

v0.7.4-release
Ryan 16 years ago
parent
commit
2f46540d30
  1. 7
      src/file.cc
  2. 2
      src/net.cc
  3. 4
      src/node.h
  4. 6
      src/timer.cc

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;

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);

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))

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;

Loading…
Cancel
Save