Navigation Menu

Skip to content

Commit

Permalink
Fill the "date" field of generated messages in microseconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 8, 2015
1 parent cc9ded1 commit 9039ce3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/droonga-protocol/connection.js
Expand Up @@ -11,6 +11,7 @@ var util = require('util');
var EventEmitter = require('events').EventEmitter;
var fluent = require('fluent-logger');
var Q = require('q');
var microtime = require('microtime');

var FluentReceiver = require('./receiver').FluentReceiver;
var ConsoleLogger = require('../console-logger').ConsoleLogger;
Expand Down Expand Up @@ -170,7 +171,16 @@ function getCurrentTime() {
// The method toISOString() returns a GMT (ex. 2013-01-10T08:34:41.252Z)
// on node. However, a local time (ex. 2013-01-10T17:34:41.252+09:00) is
// more helpful for debugging. We should use it in the feature...
return new Date().toISOString();

var nowStruct = microtime.nowStruct();
var seconds = nowStruct[0];
var microseconds = nowStruct[1];

var date = new Date((seconds * 1000) + (microseconds / 1000));
var isoString = date.toISOString();
var subsecondsPart = ('000000' + microseconds).substr(-6);
var isoStringWithMicroseconds = isoString.replace(/\.\d+Z$/, '.' + subsecondsPart + 'Z');
return isoStringWithMicroseconds;
}

function toPositiveInteger(number) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"less-middleware": ">=0.2",
"uber-cache": ">=2.0.0",
"method-override": "*",
"microtime": "*",
"msgpack": "*",
"q": "*",
"serf-rpc": "*",
Expand Down

0 comments on commit 9039ce3

Please sign in to comment.