Socket
Socket
Sign inDemoInstall

exact-time

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exact-time - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

12

browser.js

@@ -5,6 +5,6 @@ 'use strict';

var fetchHeadDate = url => new Promise((resolve, reject) => {
var fetchHeadDate = (host, path) => new Promise((resolve, reject) => {
{
const xhr = new global.XMLHttpRequest();
xhr.open('HEAD', url);
xhr.open('HEAD', host + path);
xhr.send();

@@ -18,6 +18,8 @@ xhr.onerror = () => reject(xhr.statusText);

}
});
})
// Use google server to retrieve the exact date and time
const SERVER_URL = 'https://www.googleapis.com/discovery/v1/apis?fields=';
const SERVER_HOST = '//www.googleapis.com';
const SERVER_PATH = '/discovery/v1/apis?fields=';
// Resync if more than an hour has passed

@@ -40,3 +42,3 @@ const TIME_BETWEEN_REQ = 36 * 1e5;

lastRequestTime = Date.now();
return fetchHeadDate(SERVER_URL)
return fetchHeadDate(SERVER_HOST, SERVER_PATH)
// take net delay into account

@@ -43,0 +45,0 @@ .then(date => Date.parse(date) + (Date.now() - lastRequestTime))

@@ -5,6 +5,6 @@ 'use strict';

var fetchHeadDate = url => new Promise((resolve, reject) => {
var fetchHeadDate = (host, path) => new Promise((resolve, reject) => {
{
const http = require('http');
const req = http.request({ host: url, method: 'HEAD' }, res => {
const req = http.request({ host: host, path: path, method: 'HEAD' }, res => {
resolve(res.headers.date);

@@ -19,6 +19,8 @@ });

}
});
})
// Use google server to retrieve the exact date and time
const SERVER_URL = 'https://www.googleapis.com/discovery/v1/apis?fields=';
const SERVER_HOST = '//www.googleapis.com';
const SERVER_PATH = '/discovery/v1/apis?fields=';
// Resync if more than an hour has passed

@@ -41,3 +43,3 @@ const TIME_BETWEEN_REQ = 36 * 1e5;

lastRequestTime = Date.now();
return fetchHeadDate(SERVER_URL)
return fetchHeadDate(SERVER_HOST, SERVER_PATH)
// take net delay into account

@@ -44,0 +46,0 @@ .then(date => Date.parse(date) + (Date.now() - lastRequestTime))

{
"name": "exact-time",
"version": "0.0.2",
"version": "0.0.3",
"description": "Get the exact date and time with ease",

@@ -33,7 +33,7 @@ "main": "node.js",

"devDependencies": {
"rollup": "^0.41.6",
"rollup-plugin-replace": "^1.1.1",
"sinon": "^2.2.0",
"standard": "^10.0.2",
"tap": "^10.3.2"
"rollup": "^0.53.0",
"rollup-plugin-replace": "^2.0.0",
"sinon": "^4.1.3",
"standard": "^10.0.3",
"tap": "^11.0.1"
},

@@ -40,0 +40,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc