@qrvey/utils 1.6.0-1 → 1.6.0-2
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/adapters/dateToHms.d.ts +3 -1
- package/dist/cjs/dates/adapters/dateToHms.js +47 -2
- package/dist/cjs/dates/interfaces/IDFDateToHmsSettings.d.ts +5 -0
- package/dist/cjs/dates/interfaces/IDFDateToHmsSettings.js +2 -0
- package/dist/cjs/dates/interfaces/index.d.ts +1 -0
- package/dist/cjs/dates/interfaces/index.js +1 -0
- package/dist/dates/adapters/dateToHms.d.ts +3 -1
- package/dist/dates/adapters/dateToHms.js +47 -2
- package/dist/dates/interfaces/IDFDateToHmsSettings.d.ts +5 -0
- package/dist/dates/interfaces/IDFDateToHmsSettings.js +1 -0
- package/dist/dates/interfaces/index.d.ts +1 -0
- package/dist/dates/interfaces/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { IDFDateToHmsSettings } from "../interfaces/IDFDateToHmsSettings";
|
|
1
2
|
/**
|
|
2
3
|
* * Transform a Date to [HH:mm:ss] date format.
|
|
3
4
|
* @param date String, object or millisencond number of the date
|
|
5
|
+
* @param settings the settings of the dateToHms function
|
|
4
6
|
* @returns string of [HH:mm:ss] date format
|
|
5
7
|
*/
|
|
6
|
-
export declare function dateToHms(date: string | Date | number): string;
|
|
8
|
+
export declare function dateToHms(date: string | Date | number, settings?: IDFDateToHmsSettings): string;
|
|
@@ -7,14 +7,59 @@ const isValidPotentialDate_1 = require("../helpers/isValidPotentialDate");
|
|
|
7
7
|
/**
|
|
8
8
|
* * Transform a Date to [HH:mm:ss] date format.
|
|
9
9
|
* @param date String, object or millisencond number of the date
|
|
10
|
+
* @param settings the settings of the dateToHms function
|
|
10
11
|
* @returns string of [HH:mm:ss] date format
|
|
11
12
|
*/
|
|
12
|
-
function dateToHms(date) {
|
|
13
|
+
function dateToHms(date, settings) {
|
|
13
14
|
if (!(0, isValidPotentialDate_1.isValidPotentialDate)(date))
|
|
14
15
|
return date;
|
|
15
16
|
const dt = new Date(date.valueOf());
|
|
16
17
|
if (!(0, isValidDateObject_1.isValidDateObject)(dt))
|
|
17
18
|
return date;
|
|
18
|
-
|
|
19
|
+
const defaultSettings = getDefaultSettings(settings);
|
|
20
|
+
const hours = getHours(dt, defaultSettings);
|
|
21
|
+
const minutes = getMinutes(dt, defaultSettings);
|
|
22
|
+
const seconds = getSeconds(dt, defaultSettings);
|
|
23
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
19
24
|
}
|
|
20
25
|
exports.dateToHms = dateToHms;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the settings for this function.
|
|
28
|
+
* @param settings the settings of the dateToHms function
|
|
29
|
+
* @returns a new object for the settings
|
|
30
|
+
*/
|
|
31
|
+
function getDefaultSettings(settings) {
|
|
32
|
+
var _a, _b, _c;
|
|
33
|
+
return {
|
|
34
|
+
omitHour: (_a = settings === null || settings === void 0 ? void 0 : settings.omitHour) !== null && _a !== void 0 ? _a : false,
|
|
35
|
+
omitMinute: (_b = settings === null || settings === void 0 ? void 0 : settings.omitMinute) !== null && _b !== void 0 ? _b : false,
|
|
36
|
+
omitSecond: (_c = settings === null || settings === void 0 ? void 0 : settings.omitSecond) !== null && _c !== void 0 ? _c : false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the Hours
|
|
41
|
+
* @param date the date object
|
|
42
|
+
* @param settings the settings of the dateToHms function
|
|
43
|
+
* @returns the hour string
|
|
44
|
+
*/
|
|
45
|
+
function getHours(date, settings) {
|
|
46
|
+
return (0, padLeadingZeros_1.padLeadingZeros)(settings.omitHour ? "0" : date.getHours(), 2).slice(-2);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the Minutes
|
|
50
|
+
* @param date the date object
|
|
51
|
+
* @param settings the settings of the dateToHms function
|
|
52
|
+
* @returns the minute string
|
|
53
|
+
*/
|
|
54
|
+
function getMinutes(date, settings) {
|
|
55
|
+
return (0, padLeadingZeros_1.padLeadingZeros)(settings.omitMinute ? "0" : date.getMinutes(), 2).slice(-2);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the Seconds
|
|
59
|
+
* @param date the date object
|
|
60
|
+
* @param settings the settings of the dateToHms function
|
|
61
|
+
* @returns the seconds string
|
|
62
|
+
*/
|
|
63
|
+
function getSeconds(date, settings) {
|
|
64
|
+
return (0, padLeadingZeros_1.padLeadingZeros)(settings.omitSecond ? "0" : date.getSeconds(), 2).slice(-2);
|
|
65
|
+
}
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./IDateFormat"), exports);
|
|
18
18
|
__exportStar(require("./IDateGroupingProperty"), exports);
|
|
19
|
+
__exportStar(require("./IDFDateToHmsSettings"), exports);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { IDFDateToHmsSettings } from "../interfaces/IDFDateToHmsSettings";
|
|
1
2
|
/**
|
|
2
3
|
* * Transform a Date to [HH:mm:ss] date format.
|
|
3
4
|
* @param date String, object or millisencond number of the date
|
|
5
|
+
* @param settings the settings of the dateToHms function
|
|
4
6
|
* @returns string of [HH:mm:ss] date format
|
|
5
7
|
*/
|
|
6
|
-
export declare function dateToHms(date: string | Date | number): string;
|
|
8
|
+
export declare function dateToHms(date: string | Date | number, settings?: IDFDateToHmsSettings): string;
|
|
@@ -4,13 +4,58 @@ import { isValidPotentialDate } from "../helpers/isValidPotentialDate";
|
|
|
4
4
|
/**
|
|
5
5
|
* * Transform a Date to [HH:mm:ss] date format.
|
|
6
6
|
* @param date String, object or millisencond number of the date
|
|
7
|
+
* @param settings the settings of the dateToHms function
|
|
7
8
|
* @returns string of [HH:mm:ss] date format
|
|
8
9
|
*/
|
|
9
|
-
export function dateToHms(date) {
|
|
10
|
+
export function dateToHms(date, settings) {
|
|
10
11
|
if (!isValidPotentialDate(date))
|
|
11
12
|
return date;
|
|
12
13
|
const dt = new Date(date.valueOf());
|
|
13
14
|
if (!isValidDateObject(dt))
|
|
14
15
|
return date;
|
|
15
|
-
|
|
16
|
+
const defaultSettings = getDefaultSettings(settings);
|
|
17
|
+
const hours = getHours(dt, defaultSettings);
|
|
18
|
+
const minutes = getMinutes(dt, defaultSettings);
|
|
19
|
+
const seconds = getSeconds(dt, defaultSettings);
|
|
20
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Gets the settings for this function.
|
|
24
|
+
* @param settings the settings of the dateToHms function
|
|
25
|
+
* @returns a new object for the settings
|
|
26
|
+
*/
|
|
27
|
+
function getDefaultSettings(settings) {
|
|
28
|
+
var _a, _b, _c;
|
|
29
|
+
return {
|
|
30
|
+
omitHour: (_a = settings === null || settings === void 0 ? void 0 : settings.omitHour) !== null && _a !== void 0 ? _a : false,
|
|
31
|
+
omitMinute: (_b = settings === null || settings === void 0 ? void 0 : settings.omitMinute) !== null && _b !== void 0 ? _b : false,
|
|
32
|
+
omitSecond: (_c = settings === null || settings === void 0 ? void 0 : settings.omitSecond) !== null && _c !== void 0 ? _c : false,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Gets the Hours
|
|
37
|
+
* @param date the date object
|
|
38
|
+
* @param settings the settings of the dateToHms function
|
|
39
|
+
* @returns the hour string
|
|
40
|
+
*/
|
|
41
|
+
function getHours(date, settings) {
|
|
42
|
+
return padLeadingZeros(settings.omitHour ? "0" : date.getHours(), 2).slice(-2);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets the Minutes
|
|
46
|
+
* @param date the date object
|
|
47
|
+
* @param settings the settings of the dateToHms function
|
|
48
|
+
* @returns the minute string
|
|
49
|
+
*/
|
|
50
|
+
function getMinutes(date, settings) {
|
|
51
|
+
return padLeadingZeros(settings.omitMinute ? "0" : date.getMinutes(), 2).slice(-2);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the Seconds
|
|
55
|
+
* @param date the date object
|
|
56
|
+
* @param settings the settings of the dateToHms function
|
|
57
|
+
* @returns the seconds string
|
|
58
|
+
*/
|
|
59
|
+
function getSeconds(date, settings) {
|
|
60
|
+
return padLeadingZeros(settings.omitSecond ? "0" : date.getSeconds(), 2).slice(-2);
|
|
16
61
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|