Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-opcua-date-time

Package Overview
Dependencies
Maintainers
1
Versions
130
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-date-time - npm Package Compare versions

Comparing version 2.6.0-alpha.1 to 2.6.1

11

dist/date_time.d.ts

@@ -6,2 +6,9 @@ export declare class DateWithPicoseconds extends Date {

export declare const offsetFactor1601: number[];
/**
*
* @param date {Date}
* @param picoseconds {Number} : represent the portion of the date that cannot be managed by the javascript Date object
*
* @returns {[high,low]}
*/
export declare function bn_dateToHundredNanoSecondFrom1601(date: Date, picoseconds: number): any;

@@ -17,2 +24,6 @@ export declare function bn_dateToHundredNanoSecondFrom1601Excess(date: Date, picoseconds: number): number;

}
/**
*
* @return PreciseClock
*/
export declare function getCurrentClockWithJavascriptDate(): PreciseClock;

@@ -19,0 +30,0 @@ export declare function installPeriodicClockAdjustmement(): void;

79

dist/date_time.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMinDate = exports.minOPCUADate = exports.coerceClock = exports.getCurrentClock = exports.uninstallPeriodicClockAdjustmement = exports.installPeriodicClockAdjustmement = exports.getCurrentClockWithJavascriptDate = exports.bn_hundredNanoSecondFrom1601ToDate = exports.bn_dateToHundredNanoSecondFrom1601Excess = exports.bn_dateToHundredNanoSecondFrom1601 = exports.offsetFactor1601 = exports.DateWithPicoseconds = void 0;
/**
* @module node-opcua-date-time
*/
const long = require("long");

@@ -10,2 +13,3 @@ const node_opcua_assert_1 = require("node-opcua-assert");

this.picoseconds = 0;
// tslint:disable:variable-name
this.high_low = [0, 0];

@@ -32,2 +36,43 @@ }

const factorLong = long.fromNumber(factor, true);
// Extracted from OpcUA Spec v1.02 : part 6:
//
// 5.2.2.5 DateTime
// A DateTime value shall be encoded as a 64-bit signed integer (see Clause 5.2.2.2) which represents
// the number of 100 nanosecond intervals since January 1, 1601 (UTC) .
// Not all DevelopmentPlatforms will be able to represent the full range of dates and times that can be
// represented with this DataEncoding. For example, the UNIX time_t structure only has a 1 second
// resolution and cannot represent dates prior to 1970. For this reason, a number of rules shall be
// applied when dealing with date/time values that exceed the dynamic range of a DevelopmentPlatform.
//
// These rules are:
// a) A date/time value is encoded as 0 if either
// 1) The value is equal to or earlier than 1601-01-01 12:00AM.
// 2) The value is the earliest date that can be represented with the DevelopmentPlatform‟s encoding.
//
// b) A date/time is encoded as the maximum value for an Int64 if either
// 1) The value is equal to or greater than 9999-01-01 11:59:59PM,
// 2) The value is the latest date that can be represented with the DevelopmentPlatform‟s encoding.
//
// c) A date/time is decoded as the earliest time that can be represented on the platform if either
// 1) The encoded value is 0,
// 2) The encoded value represents a time earlier than the earliest time that can be
// represented with the DevelopmentPlatform‟s encoding.
//
// d) A date/time is decoded as the latest time that can be represented on the platform if either
// 1) The encoded value is the maximum value for an Int64,
// 2) The encoded value represents a time later than the latest time that can be represented with the
// DevelopmentPlatform‟s encoding.
//
// These rules imply that the earliest and latest times that can be represented on a given platform are
// invalid date/time values and should be treated that way by Applications.
// A decoder shall truncate the value if a decoder encounters a DateTime value with a resolution that is
// greater than the resolution supported on the DevelopmentPlatform.
//
/**
*
* @param date {Date}
* @param picoseconds {Number} : represent the portion of the date that cannot be managed by the javascript Date object
*
* @returns {[high,low]}
*/
function bn_dateToHundredNanoSecondFrom1601(date, picoseconds) {

@@ -38,4 +83,8 @@ node_opcua_assert_1.assert(date instanceof Date);

}
const t = date.getTime();
// note : The value returned by the getTime method is the number
// of milliseconds since 1 January 1970 00:00:00 UTC.
//
const t = date.getTime(); // number of milliseconds since since 1 January 1970 00:00:00 UTC.
const excess100nanosecond = (picoseconds !== undefined) ? Math.floor(picoseconds / 100000) : 0;
// value_64 = (t + offset ) * factor;
const tL = long.fromNumber(t, false);

@@ -49,2 +98,3 @@ const a = tL.add(offsetLong).multiply(factorLong).add(excess100nanosecond);

function bn_dateToHundredNanoSecondFrom1601Excess(date, picoseconds) {
// 100 nano seconds = 100 x 1000 picoseconds
return (picoseconds !== undefined && picoseconds !== null) ? picoseconds % 100000 : 0;

@@ -55,7 +105,10 @@ }

node_opcua_assert_1.assert(low !== undefined);
const l = new long(low, high, true);
// value_64 / factor - offset = t
const l = new long(low, high, /*unsigned*/ true);
const value1 = l.div(factor).toNumber() - offset;
const date = new Date(value1);
// enrich the date
const excess100nanoInPico = l.mod(10000).mul(100000).toNumber();
date.high_low = [high, low];
// picosecond will contains un-decoded 100 nanoseconds => 10 x 100 nanoseconds = 1 microsecond
date.picoseconds = excess100nanoInPico + ((picoseconds !== undefined) ? picoseconds : 0);

@@ -67,7 +120,11 @@ return date;

let lastPicoseconds = 0;
const smallTickPicosecond = 1000 * 100;
const smallTickPicosecond = 1000 * 100; // 100 nano second in picoseconds
/**
*
* @return PreciseClock
*/
function getCurrentClockWithJavascriptDate() {
const now = new Date();
if (lastNowDate && now.getTime() === lastNowDate.getTime()) {
lastPicoseconds += smallTickPicosecond;
lastPicoseconds += smallTickPicosecond; // add 100-nano-second which is the resolution of OPCUA DateTime
}

@@ -86,2 +143,5 @@ else {

let refTime = Date.now();
// update refTime now and then to make sure that we don't miss
// any system time adjustment here such as a NTP clock event
// see #651
let timerId;

@@ -99,3 +159,3 @@ let timerInstallationCount = 0;

refTime = Date.now();
}, 30000);
}, 30000 /* every 30 seconds */);
}

@@ -116,11 +176,18 @@ exports.installPeriodicClockAdjustmement = installPeriodicClockAdjustmement;

};
// make sure we get a pointer to the actual process.hrtime,
// just in case it get overridden by some library (such as sinon)
const hrtime = process.hrtime;
const setTimeout_chek = setTimeout;
/*kWithProcessHRTime*/
function getCurrentClock() {
if (setTimeout_chek !== setTimeout) {
// is fake sinon clock being used ?
// in this case hrtime is not working
return getCurrentClockWithJavascriptDate();
}
gClock.tick = hrtime(origin);
gClock.tick = hrtime(origin); // [seconds, nanoseconds]
const milliseconds = gClock.tick[0] * 1000 + Math.floor(gClock.tick[1] / 1000000) + refTime;
const picoseconds = (gClock.tick[1] % 1000000) * 1000;
// display drift in seconds :
// console.log(gClock.tick[0] - Math.floor((Date.now()-refTime) / 1000));
gClock.timestamp = new Date(milliseconds);

@@ -127,0 +194,0 @@ gClock.picoseconds = picoseconds;

@@ -5,6 +5,17 @@ import { BinaryStream, OutputBinaryStream } from "node-opcua-binary-stream";

export declare function randomDateTime(): Date;
/**
*
* @param date {Date}
* @param picoseconds {null} {number of picoseconds to improve javascript date... }
* @param stream {BinaryStream}
*/
export declare function encodeHighAccuracyDateTime(date: Date | null, picoseconds: number, stream: OutputBinaryStream): void;
export declare function encodeDateTime(date: Date | null, stream: OutputBinaryStream): void;
/**
*
* @param stream
* @returns {Date}
*/
export declare function decodeDateTime(stream: BinaryStream): DateWithPicoseconds;
export declare const decodeHighAccuracyDateTime: typeof decodeDateTime;
export declare function coerceDateTime(value: any): Date;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.coerceDateTime = exports.decodeHighAccuracyDateTime = exports.decodeDateTime = exports.encodeDateTime = exports.encodeHighAccuracyDateTime = exports.randomDateTime = exports.isValidDateTime = void 0;
/**
* @module node-opcua-date-time
*/
const node_opcua_assert_1 = require("node-opcua-assert");
const date_time_1 = require("./date_time");
// Date(year, month [, day, hours, minutes, seconds, ms])
function isValidDateTime(value) {

@@ -10,3 +14,12 @@ return value instanceof Date;

exports.isValidDateTime = isValidDateTime;
/**
* return a random integer value in the range of min inclusive and max exclusive
* @method getRandomInt
* @param min
* @param max
* @return {*}
* @private
*/
function getRandomInt(min, max) {
// note : Math.random() returns a random number between 0 (inclusive) and 1 (exclusive):
return Math.floor(Math.random() * (max - min)) + min;

@@ -19,2 +32,8 @@ }

exports.randomDateTime = randomDateTime;
/**
*
* @param date {Date}
* @param picoseconds {null} {number of picoseconds to improve javascript date... }
* @param stream {BinaryStream}
*/
function encodeHighAccuracyDateTime(date, picoseconds, stream) {

@@ -41,2 +60,7 @@ if (date === null) {

exports.encodeDateTime = encodeDateTime;
/**
*
* @param stream
* @returns {Date}
*/
function decodeDateTime(stream) {

@@ -43,0 +67,0 @@ const lo = stream.readInteger();

@@ -0,2 +1,5 @@

/**
* @module node-opcua-date-time
*/
export * from "./date_time";
export * from "./encode_decode";

5

dist/index.js

@@ -11,6 +11,9 @@ "use strict";

for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
}
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module node-opcua-date-time
*/
__exportStar(require("./date_time"), exports);
__exportStar(require("./encode_decode"), exports);
//# sourceMappingURL=index.js.map

@@ -5,3 +5,3 @@ {

"types": "./dist/index.d.ts",
"version": "2.6.0-alpha.1",
"version": "2.6.1",
"description": "pure nodejs OPCUA SDK - module -date-time",

@@ -15,3 +15,3 @@ "scripts": {

"long": "^4.0.0",
"node-opcua-assert": "^2.6.0-alpha.1",
"node-opcua-assert": "^2.6.1",
"underscore": "^1.10.2"

@@ -22,4 +22,4 @@ },

"bignumber.js": "^9.0.0",
"node-opcua-benchmarker": "^2.6.0-alpha.1",
"node-opcua-binary-stream": "^2.6.0-alpha.1",
"node-opcua-benchmarker": "^2.6.1",
"node-opcua-binary-stream": "^2.6.1",
"should": "^13.2.3"

@@ -42,3 +42,3 @@ },

"homepage": "http://node-opcua.github.io/",
"gitHead": "becfcbe561410100413321e3f7f3913c6f75b837"
"gitHead": "15f0c0f83232fc63310dc04fea187048c7a01e4b"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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