@sasjs/utils 2.40.1 → 2.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/conversion/convertJsDateToSasDate.d.ts +12 -0
- package/conversion/convertJsDateToSasDate.js +34 -0
- package/conversion/convertJsDateToSasDate.js.map +1 -0
- package/conversion/convertSasDateToJsDate.d.ts +12 -0
- package/conversion/convertSasDateToJsDate.js +33 -0
- package/conversion/convertSasDateToJsDate.js.map +1 -0
- package/package.json +1 -1
- package/utils/index.d.ts +1 -1
- package/utils/index.js +6 -12
- package/utils/index.js.map +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a JavaScript date object to a SAS Date or Datetime, given the logic below:
|
|
3
|
+
*
|
|
4
|
+
* A JS Date contains the number of _milliseconds_ since 01/01/1970
|
|
5
|
+
* A SAS Date contains the number of _days_ since 01/01/1960
|
|
6
|
+
* A SAS Datetime contains the number of _seconds_ since 01/01/1960
|
|
7
|
+
*
|
|
8
|
+
* @param jsDate JS Date to be converted. The type is instance of `Date`
|
|
9
|
+
* @param unit Unit in which to return the SAS Date / datetime, eg `sasdate | sasdatetime`
|
|
10
|
+
* @returns SAS Date value based on `unit` param
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertJsDateToSasDate: (jsDate: Date, unit: 'sasdate' | 'sasdatetime') => number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertJsDateToSasDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a JavaScript date object to a SAS Date or Datetime, given the logic below:
|
|
6
|
+
*
|
|
7
|
+
* A JS Date contains the number of _milliseconds_ since 01/01/1970
|
|
8
|
+
* A SAS Date contains the number of _days_ since 01/01/1960
|
|
9
|
+
* A SAS Datetime contains the number of _seconds_ since 01/01/1960
|
|
10
|
+
*
|
|
11
|
+
* @param jsDate JS Date to be converted. The type is instance of `Date`
|
|
12
|
+
* @param unit Unit in which to return the SAS Date / datetime, eg `sasdate | sasdatetime`
|
|
13
|
+
* @returns SAS Date value based on `unit` param
|
|
14
|
+
*/
|
|
15
|
+
var convertJsDateToSasDate = function (jsDate, unit) {
|
|
16
|
+
var valueInMilliseconds = new Date(Date.UTC(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate(), jsDate.getHours(), jsDate.getMinutes(), jsDate.getSeconds())).valueOf();
|
|
17
|
+
var msInDay = 24 * 60 * 60 * 1000;
|
|
18
|
+
var msInTenYears = 315619200000; //calculating is not guaranteed to give the correct value, as this is parsed with: new Date(Date.UTC(1960, 0, 1)).getTime()
|
|
19
|
+
var ms1960 = valueInMilliseconds + msInTenYears;
|
|
20
|
+
switch (unit) {
|
|
21
|
+
case 'sasdate': {
|
|
22
|
+
// always in days from 1960
|
|
23
|
+
var valueInDays = ms1960 / msInDay;
|
|
24
|
+
valueInDays = Math.floor(valueInDays);
|
|
25
|
+
return valueInDays;
|
|
26
|
+
}
|
|
27
|
+
case 'sasdatetime': {
|
|
28
|
+
// always in seconds from 1960
|
|
29
|
+
return ms1960 / 1000;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
exports.convertJsDateToSasDate = convertJsDateToSasDate;
|
|
34
|
+
//# sourceMappingURL=convertJsDateToSasDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertJsDateToSasDate.js","sourceRoot":"","sources":["../../src/conversion/convertJsDateToSasDate.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACI,IAAM,sBAAsB,GAAG,UACpC,MAAY,EACZ,IAA+B;IAE/B,IAAM,mBAAmB,GAAG,IAAI,IAAI,CAClC,IAAI,CAAC,GAAG,CACN,MAAM,CAAC,WAAW,EAAE,EACpB,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,OAAO,EAAE,EAChB,MAAM,CAAC,QAAQ,EAAE,EACjB,MAAM,CAAC,UAAU,EAAE,EACnB,MAAM,CAAC,UAAU,EAAE,CACpB,CACF,CAAC,OAAO,EAAE,CAAA;IAEX,IAAM,OAAO,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA;IACnC,IAAM,YAAY,GAAG,YAAY,CAAA,CAAC,2HAA2H;IAE7J,IAAM,MAAM,GAAG,mBAAmB,GAAG,YAAY,CAAA;IAEjD,QAAQ,IAAI,EAAE;QACZ,KAAK,SAAS,CAAC,CAAC;YACd,2BAA2B;YAC3B,IAAI,WAAW,GAAG,MAAM,GAAG,OAAO,CAAA;YAElC,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;YAErC,OAAO,WAAW,CAAA;SACnB;QACD,KAAK,aAAa,CAAC,CAAC;YAClB,8BAA8B;YAC9B,OAAO,MAAM,GAAG,IAAI,CAAA;SACrB;KACF;AACH,CAAC,CAAA;AAlCY,QAAA,sBAAsB,0BAkClC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a SAS Date or Datetime to a JavaScript date object, given the logic below:
|
|
3
|
+
*
|
|
4
|
+
* A JS Date contains the number of _milliseconds_ since 01/01/1970
|
|
5
|
+
* A SAS Date contains the number of _days_ since 01/01/1960
|
|
6
|
+
* A SAS Datetime contains the number of _seconds_ since 01/01/1960
|
|
7
|
+
*
|
|
8
|
+
* @param sasValue SAS Date or Datetime to be converted. The type could be `number` or `string.
|
|
9
|
+
* @param unit Unit from which to convert the SAS Date / Datetime, eg `sasdate | sasdatetime`
|
|
10
|
+
* @returns JavaScript Date object
|
|
11
|
+
*/
|
|
12
|
+
export declare const convertSasDateToJsDate: (sasValue: number | string, unit: 'sasdate' | 'sasdatetime') => Date;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertSasDateToJsDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a SAS Date or Datetime to a JavaScript date object, given the logic below:
|
|
6
|
+
*
|
|
7
|
+
* A JS Date contains the number of _milliseconds_ since 01/01/1970
|
|
8
|
+
* A SAS Date contains the number of _days_ since 01/01/1960
|
|
9
|
+
* A SAS Datetime contains the number of _seconds_ since 01/01/1960
|
|
10
|
+
*
|
|
11
|
+
* @param sasValue SAS Date or Datetime to be converted. The type could be `number` or `string.
|
|
12
|
+
* @param unit Unit from which to convert the SAS Date / Datetime, eg `sasdate | sasdatetime`
|
|
13
|
+
* @returns JavaScript Date object
|
|
14
|
+
*/
|
|
15
|
+
var convertSasDateToJsDate = function (sasValue, unit) {
|
|
16
|
+
var msInDay = 24 * 60 * 60 * 1000;
|
|
17
|
+
var msNegativeTenYears = -315619200000; //since calculating it is not practical/guarantee to get correct value, this is parsed with: new Date(Date.UTC(1960, 0, 1)).getTime()
|
|
18
|
+
if (typeof sasValue !== 'number')
|
|
19
|
+
sasValue = parseFloat(sasValue);
|
|
20
|
+
if (unit === 'sasdatetime') {
|
|
21
|
+
var ms1960 = sasValue * 1000;
|
|
22
|
+
var jsMs = msNegativeTenYears + ms1960;
|
|
23
|
+
var jsDate = new Date(jsMs);
|
|
24
|
+
var timezoneOffsetMs = jsDate.getTimezoneOffset() * 60 * 1000;
|
|
25
|
+
jsMs += timezoneOffsetMs;
|
|
26
|
+
jsDate = new Date(jsMs); // We create new Date object after the timezone correction
|
|
27
|
+
var jsDateUtcMs = Date.UTC(jsDate.getFullYear(), jsDate.getMonth(), jsDate.getDate(), jsDate.getHours(), jsDate.getMinutes(), jsDate.getSeconds());
|
|
28
|
+
return new Date(jsDateUtcMs);
|
|
29
|
+
}
|
|
30
|
+
return new Date(msNegativeTenYears + sasValue * msInDay);
|
|
31
|
+
};
|
|
32
|
+
exports.convertSasDateToJsDate = convertSasDateToJsDate;
|
|
33
|
+
//# sourceMappingURL=convertSasDateToJsDate.js.map
|
|
@@ -0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
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.chunk = exports.diff = exports.bytesToSize = exports.getExecutorPath = exports.decodeFromBase64 = exports.encodeToBase64 = exports.urlOrigin = void 0;
|
|
14
|
-
|
|
3
|
+
exports.chunk = exports.diff = exports.bytesToSize = exports.getExecutorPath = exports.decodeFromBase64 = exports.encodeToBase64 = exports.urlOrigin = exports.isWindows = exports.uniqArray = exports.asyncForEach = exports.uuidv4 = void 0;
|
|
4
|
+
var utils_1 = require("./utils");
|
|
5
|
+
Object.defineProperty(exports, "uuidv4", { enumerable: true, get: function () { return utils_1.uuidv4; } });
|
|
6
|
+
Object.defineProperty(exports, "asyncForEach", { enumerable: true, get: function () { return utils_1.asyncForEach; } });
|
|
7
|
+
Object.defineProperty(exports, "uniqArray", { enumerable: true, get: function () { return utils_1.uniqArray; } });
|
|
8
|
+
Object.defineProperty(exports, "isWindows", { enumerable: true, get: function () { return utils_1.isWindows; } });
|
|
15
9
|
var url_1 = require("./url");
|
|
16
10
|
Object.defineProperty(exports, "urlOrigin", { enumerable: true, get: function () { return url_1.urlOrigin; } });
|
|
17
11
|
var base64_1 = require("./base64");
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,iCAAoE;AAA3D,+FAAA,MAAM,OAAA;AAAE,qGAAA,YAAY,OAAA;AAAE,kGAAA,SAAS,OAAA;AAAE,kGAAA,SAAS,OAAA;AAEnD,6BAAiC;AAAxB,gGAAA,SAAS,OAAA;AAElB,mCAA2D;AAAlD,wGAAA,cAAc,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAEzC,uCAA4C;AAAnC,2GAAA,eAAe,OAAA;AAExB,6CAA2C;AAAlC,0GAAA,WAAW,OAAA;AACpB,+BAA6B;AAApB,4FAAA,IAAI,OAAA;AACb,iCAA+B;AAAtB,8FAAA,KAAK,OAAA"}
|