@qrvey/utils 1.6.0-4 → 1.6.0-6
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/dist/cjs/dates/constants/DATETIME_COLUMN_FORMAT.js +1 -9
- package/dist/cjs/dates/helpers/adjustTimezone.js +6 -0
- package/dist/cjs/dates/helpers/isValidPotentialDate.js +1 -1
- package/dist/cjs/format/helpers/index.d.ts +1 -0
- package/dist/cjs/format/helpers/index.js +17 -0
- package/dist/cjs/format/helpers/isDateTimeFormat.d.ts +7 -0
- package/dist/cjs/format/helpers/isDateTimeFormat.js +17 -0
- package/dist/cjs/format/localization.js +2 -3
- package/dist/dates/constants/DATETIME_COLUMN_FORMAT.js +1 -9
- package/dist/dates/helpers/adjustTimezone.js +6 -0
- package/dist/dates/helpers/isValidPotentialDate.js +1 -1
- package/dist/format/helpers/index.d.ts +1 -0
- package/dist/format/helpers/index.js +1 -0
- package/dist/format/helpers/isDateTimeFormat.d.ts +7 -0
- package/dist/format/helpers/isDateTimeFormat.js +13 -0
- package/dist/format/localization.js +2 -3
- package/package.json +1 -1
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DATETIME_COLUMN_FORMAT = void 0;
|
|
4
|
-
exports.DATETIME_COLUMN_FORMAT = [
|
|
5
|
-
"MM/DD/YYYY HH24:MM:SS",
|
|
6
|
-
"DD/MM/YYYY HH24:MM:SS",
|
|
7
|
-
"YYYY-MM-DD HH24:MM:SS",
|
|
8
|
-
"MM/DD/YYYY HH24:MI:SS",
|
|
9
|
-
"DD/MM/YYYY HH24:MI:SS",
|
|
10
|
-
"YYYY-MM-DD HH24:MI:SS",
|
|
11
|
-
"YYYY-MM-DD HH:mm:ss",
|
|
12
|
-
];
|
|
4
|
+
exports.DATETIME_COLUMN_FORMAT = ["HH24:MM:SS", "HH24:MI:SS", "HH:mm:ss"];
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.adjustTimezone = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const isValidPotentialDate_1 = require("./isValidPotentialDate");
|
|
6
|
+
const validateDate_1 = require("./validateDate");
|
|
4
7
|
/**
|
|
5
8
|
* Adjusts a Date with the UTC-0 Timezone.
|
|
6
9
|
* @param date String, object or millisencond number of the date
|
|
7
10
|
* @returns updated Date object
|
|
8
11
|
*/
|
|
9
12
|
function adjustTimezone(date) {
|
|
13
|
+
if (!(0, isValidPotentialDate_1.isValidPotentialDate)(date) ||
|
|
14
|
+
(typeof date === "string" && !(0, validateDate_1.validateDate)(date, constants_1.DATE_FORMAT.DAY)))
|
|
15
|
+
return date;
|
|
10
16
|
const dt = new Date(date.valueOf());
|
|
11
17
|
return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
|
|
12
18
|
}
|
|
@@ -11,7 +11,7 @@ const isTokenLabel_1 = require("../../tokens/isTokenLabel");
|
|
|
11
11
|
function isValidPotentialDate(date) {
|
|
12
12
|
return (!(0, isEmpty_1.isEmpty)(date) &&
|
|
13
13
|
!(0, isTokenLabel_1.isTokenLabel)(date) &&
|
|
14
|
-
(date instanceof Date ||
|
|
14
|
+
((date instanceof Date && !isNaN(date)) ||
|
|
15
15
|
typeof date === "string" ||
|
|
16
16
|
typeof date === "number"));
|
|
17
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./isDateTimeFormat";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./isDateTimeFormat"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IFormatOutputFormat } from "../../interfaces/format/IFormatOutputFormat.Interface";
|
|
2
|
+
/**
|
|
3
|
+
* It checks if the outputFormat is a date time format.
|
|
4
|
+
* @param {IFormatOutputFormat} outputFormat - IFormatOutputFormat
|
|
5
|
+
* @returns A boolean
|
|
6
|
+
*/
|
|
7
|
+
export declare const isDateTimeFormat: (outputFormat: IFormatOutputFormat) => boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDateTimeFormat = void 0;
|
|
4
|
+
const DATETIME_COLUMN_FORMAT_1 = require("../../dates/constants/DATETIME_COLUMN_FORMAT");
|
|
5
|
+
/**
|
|
6
|
+
* It checks if the outputFormat is a date time format.
|
|
7
|
+
* @param {IFormatOutputFormat} outputFormat - IFormatOutputFormat
|
|
8
|
+
* @returns A boolean
|
|
9
|
+
*/
|
|
10
|
+
const isDateTimeFormat = (outputFormat) => {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const format = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Default" && ((_a = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _a === void 0 ? void 0 : _a.format)
|
|
13
|
+
? (_b = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _b === void 0 ? void 0 : _b.format
|
|
14
|
+
: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format;
|
|
15
|
+
return DATETIME_COLUMN_FORMAT_1.DATETIME_COLUMN_FORMAT.some((opt) => format === null || format === void 0 ? void 0 : format.includes(opt));
|
|
16
|
+
};
|
|
17
|
+
exports.isDateTimeFormat = isDateTimeFormat;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatWithLocale = exports.chooseLang = exports.getLang = void 0;
|
|
4
|
-
const DATETIME_COLUMN_FORMAT_1 = require("../dates/constants/DATETIME_COLUMN_FORMAT");
|
|
5
4
|
const isEmpty_1 = require("../general/mix/isEmpty");
|
|
6
5
|
const definition_1 = require("./definition");
|
|
7
6
|
const durationFormatter_1 = require("./duration/durationFormatter");
|
|
7
|
+
const isDateTimeFormat_1 = require("./helpers/isDateTimeFormat");
|
|
8
8
|
const getLang = (locale) => {
|
|
9
9
|
if (!locale)
|
|
10
10
|
return;
|
|
@@ -36,8 +36,7 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
36
36
|
const dateParam = new Date(dateValue);
|
|
37
37
|
let langOpts = options;
|
|
38
38
|
if (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) {
|
|
39
|
-
|
|
40
|
-
if (DATETIME_COLUMN_FORMAT_1.DATETIME_COLUMN_FORMAT.includes(format))
|
|
39
|
+
if ((0, isDateTimeFormat_1.isDateTimeFormat)(outputFormat))
|
|
41
40
|
langOpts = definition_1.DATETIME_OPTIONS;
|
|
42
41
|
}
|
|
43
42
|
try {
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export const DATETIME_COLUMN_FORMAT = [
|
|
2
|
-
"MM/DD/YYYY HH24:MM:SS",
|
|
3
|
-
"DD/MM/YYYY HH24:MM:SS",
|
|
4
|
-
"YYYY-MM-DD HH24:MM:SS",
|
|
5
|
-
"MM/DD/YYYY HH24:MI:SS",
|
|
6
|
-
"DD/MM/YYYY HH24:MI:SS",
|
|
7
|
-
"YYYY-MM-DD HH24:MI:SS",
|
|
8
|
-
"YYYY-MM-DD HH:mm:ss",
|
|
9
|
-
];
|
|
1
|
+
export const DATETIME_COLUMN_FORMAT = ["HH24:MM:SS", "HH24:MI:SS", "HH:mm:ss"];
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { DATE_FORMAT } from "../constants";
|
|
2
|
+
import { isValidPotentialDate } from "./isValidPotentialDate";
|
|
3
|
+
import { validateDate } from "./validateDate";
|
|
1
4
|
/**
|
|
2
5
|
* Adjusts a Date with the UTC-0 Timezone.
|
|
3
6
|
* @param date String, object or millisencond number of the date
|
|
4
7
|
* @returns updated Date object
|
|
5
8
|
*/
|
|
6
9
|
export function adjustTimezone(date) {
|
|
10
|
+
if (!isValidPotentialDate(date) ||
|
|
11
|
+
(typeof date === "string" && !validateDate(date, DATE_FORMAT.DAY)))
|
|
12
|
+
return date;
|
|
7
13
|
const dt = new Date(date.valueOf());
|
|
8
14
|
return new Date(+dt + dt.getTimezoneOffset() * 1000 * 60);
|
|
9
15
|
}
|
|
@@ -8,7 +8,7 @@ import { isTokenLabel } from "../../tokens/isTokenLabel";
|
|
|
8
8
|
export function isValidPotentialDate(date) {
|
|
9
9
|
return (!isEmpty(date) &&
|
|
10
10
|
!isTokenLabel(date) &&
|
|
11
|
-
(date instanceof Date ||
|
|
11
|
+
((date instanceof Date && !isNaN(date)) ||
|
|
12
12
|
typeof date === "string" ||
|
|
13
13
|
typeof date === "number"));
|
|
14
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./isDateTimeFormat";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./isDateTimeFormat";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IFormatOutputFormat } from "../../interfaces/format/IFormatOutputFormat.Interface";
|
|
2
|
+
/**
|
|
3
|
+
* It checks if the outputFormat is a date time format.
|
|
4
|
+
* @param {IFormatOutputFormat} outputFormat - IFormatOutputFormat
|
|
5
|
+
* @returns A boolean
|
|
6
|
+
*/
|
|
7
|
+
export declare const isDateTimeFormat: (outputFormat: IFormatOutputFormat) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DATETIME_COLUMN_FORMAT } from "../../dates/constants/DATETIME_COLUMN_FORMAT";
|
|
2
|
+
/**
|
|
3
|
+
* It checks if the outputFormat is a date time format.
|
|
4
|
+
* @param {IFormatOutputFormat} outputFormat - IFormatOutputFormat
|
|
5
|
+
* @returns A boolean
|
|
6
|
+
*/
|
|
7
|
+
export const isDateTimeFormat = (outputFormat) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const format = (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format) === "Default" && ((_a = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _a === void 0 ? void 0 : _a.format)
|
|
10
|
+
? (_b = outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) === null || _b === void 0 ? void 0 : _b.format
|
|
11
|
+
: outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.format;
|
|
12
|
+
return DATETIME_COLUMN_FORMAT.some((opt) => format === null || format === void 0 ? void 0 : format.includes(opt));
|
|
13
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DATETIME_COLUMN_FORMAT } from "../dates/constants/DATETIME_COLUMN_FORMAT";
|
|
2
1
|
import { isEmpty } from "../general/mix/isEmpty";
|
|
3
2
|
import { currencyISO, LANG_DEFAULT, CURRENCY_DEFAULT, DATETIME_OPTIONS, } from "./definition";
|
|
4
3
|
import { DurationFormatter } from "./duration/durationFormatter";
|
|
4
|
+
import { isDateTimeFormat } from "./helpers/isDateTimeFormat";
|
|
5
5
|
export const getLang = (locale) => {
|
|
6
6
|
if (!locale)
|
|
7
7
|
return;
|
|
@@ -30,8 +30,7 @@ function formatLocaleDate(value, outputFormat, config) {
|
|
|
30
30
|
const dateParam = new Date(dateValue);
|
|
31
31
|
let langOpts = options;
|
|
32
32
|
if (outputFormat === null || outputFormat === void 0 ? void 0 : outputFormat.originalFormat) {
|
|
33
|
-
|
|
34
|
-
if (DATETIME_COLUMN_FORMAT.includes(format))
|
|
33
|
+
if (isDateTimeFormat(outputFormat))
|
|
35
34
|
langOpts = DATETIME_OPTIONS;
|
|
36
35
|
}
|
|
37
36
|
try {
|