Comparing version 0.5.1 to 0.5.2
@@ -16,3 +16,3 @@ /* | ||
exports.defaultNtpServer = "pool.ntp.org"; | ||
/** | ||
@@ -28,6 +28,13 @@ * Amount of acceptable time to await for a response from the remote server. | ||
* @param {number} port Remote NTP Server port number | ||
* @param {function(Object, Date)} callback(err, date) Async callback for | ||
* @param {function(Object, Date)} callback(err, date) Async callback for | ||
* the result date or eventually error. | ||
*/ | ||
exports.getNetworkTime = function (server, port, callback) { | ||
if (callback === null || typeof callback !== "function") { | ||
return; | ||
} | ||
server = server || exports.defaultNtpServer; | ||
port = port || exports.defaultNtpPort; | ||
var client = dgram.createSocket("udp4"), | ||
@@ -42,3 +49,3 @@ ntpData = new Buffer(48); | ||
var timeout = setTimeout(function() { | ||
var timeout = setTimeout(function () { | ||
client.close(); | ||
@@ -58,3 +65,3 @@ callback("Timeout waiting for NTP response.", null); | ||
client.close(); | ||
// Offset to get to the "Transmit Timestamp" field (time at which the reply | ||
@@ -61,0 +68,0 @@ // departed the server for the client, in 64-bit timestamp format." |
{ | ||
"name": "ntp-client", | ||
"description": "Pure Javascript implementation of the NTP Client Protocol", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"homepage": "https://github.com/moonpyk/node-ntp-client", | ||
@@ -29,6 +29,7 @@ "author": { | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-jshint": "~0.6.0", | ||
"grunt-contrib-nodeunit": "~0.2.0", | ||
"grunt-contrib-watch": "~0.4.0", | ||
"grunt": "~0.4.1" | ||
"nodeunit": "~0.8.1" | ||
}, | ||
@@ -42,2 +43,2 @@ "bin": { | ||
] | ||
} | ||
} |
@@ -28,13 +28,25 @@ /* | ||
// setup here | ||
ntpClient.ntpReplyTimeout = 5000; // Reducing timeout to avoid warnings. | ||
done(); | ||
}; | ||
exports.invalidUsage = function (test) { | ||
test.doesNotThrow(function () { | ||
ntpClient.getNetworkTime(ntpClient.defaultNtpServer, ntpClient.defaultNtpPort); | ||
}); | ||
test.done(); | ||
}; | ||
exports.notBitchyAboutSomeParameters = function (test) { | ||
ntpClient.getNetworkTime(null, null, function (err, date) { | ||
test.ok(date !== null); | ||
test.done(); | ||
}); | ||
}; | ||
exports.validNTPServer = function (test) { | ||
ntpClient.ntpReplyTimeout = 5000; // Reducing timeout to avoid warnings. | ||
ntpClient.getNetworkTime(ntpClient.defaultNtpServer, ntpClient.defaultNtpPort, function (err, date) { | ||
var now = new Date(); | ||
console.log(); | ||
console.log("System reported : %s", now); | ||
console.log("System reported : %s", new Date()); | ||
@@ -41,0 +53,0 @@ test.ok(err === null); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10773
186
5