@my-devkit/core 1.0.91 → 1.0.93
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/date-helper.d.ts +3 -2
- package/dist/date-helper.js +22 -10
- package/dist/date-helper.js.map +1 -1
- package/package.json +1 -1
- package/src/date-helper.ts +30 -10
package/dist/date-helper.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare class DateHelper {
|
|
2
2
|
static getUTCTimestamp(): number;
|
|
3
|
-
static getElapsedTime(startDate: Date): number;
|
|
4
|
-
static getReadableElapsedTime(startDate: Date): string;
|
|
3
|
+
static getElapsedTime(startDate: Date, endDate?: Date): number;
|
|
4
|
+
static getReadableElapsedTime(startDate: Date, endDate?: Date, short?: boolean): string;
|
|
5
|
+
static addDays(startDate: Date, numberOfDays: number): Date;
|
|
5
6
|
}
|
package/dist/date-helper.js
CHANGED
|
@@ -8,22 +8,34 @@ var DateHelper = /** @class */ (function () {
|
|
|
8
8
|
var now = new Date;
|
|
9
9
|
return Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
|
|
10
10
|
};
|
|
11
|
-
DateHelper.getElapsedTime = function (startDate) {
|
|
12
|
-
|
|
11
|
+
DateHelper.getElapsedTime = function (startDate, endDate) {
|
|
12
|
+
if (endDate === void 0) { endDate = new Date(); }
|
|
13
|
+
return Math.abs(endDate.getTime() - startDate.getTime());
|
|
13
14
|
};
|
|
14
|
-
DateHelper.getReadableElapsedTime = function (startDate) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
var
|
|
15
|
+
DateHelper.getReadableElapsedTime = function (startDate, endDate, short) {
|
|
16
|
+
if (endDate === void 0) { endDate = new Date(); }
|
|
17
|
+
if (short === void 0) { short = false; }
|
|
18
|
+
var elapsedTime = this.getElapsedTime(startDate, endDate);
|
|
19
|
+
var hours = Math.floor(elapsedTime / (60 * 60 * 1000));
|
|
20
|
+
elapsedTime = elapsedTime - (60 * 60 * 1000) * hours;
|
|
21
|
+
var minutes = Math.floor(elapsedTime / (60 * 1000));
|
|
22
|
+
elapsedTime = elapsedTime - (60 * 1000) * minutes;
|
|
23
|
+
var seconds = Math.floor(elapsedTime / 1000);
|
|
24
|
+
var miliseconds = elapsedTime - 1000 * seconds;
|
|
25
|
+
if (hours) {
|
|
26
|
+
return short ? "".concat(hours, " h") : "".concat(hours, " h ").concat(minutes, " min ").concat(seconds, " sec ").concat(miliseconds, " ms");
|
|
27
|
+
}
|
|
19
28
|
if (minutes) {
|
|
20
|
-
return "".concat(minutes, " min ").concat(seconds, " sec ").concat(miliseconds, " ms");
|
|
29
|
+
return short ? "".concat(minutes, " min") : "".concat(minutes, " min ").concat(seconds, " sec ").concat(miliseconds, " ms");
|
|
21
30
|
}
|
|
22
|
-
|
|
23
|
-
return "".concat(seconds, " sec ").concat(miliseconds, " ms");
|
|
31
|
+
if (seconds) {
|
|
32
|
+
return short ? "".concat(seconds, " sec") : "".concat(seconds, " sec ").concat(miliseconds, " ms");
|
|
24
33
|
}
|
|
25
34
|
return "".concat(miliseconds, " ms");
|
|
26
35
|
};
|
|
36
|
+
DateHelper.addDays = function (startDate, numberOfDays) {
|
|
37
|
+
return new Date(Date.UTC(startDate.getUTCFullYear(), startDate.getUTCMonth(), startDate.getUTCDate() + numberOfDays, startDate.getUTCHours(), startDate.getUTCMinutes(), startDate.getUTCSeconds()));
|
|
38
|
+
};
|
|
27
39
|
return DateHelper;
|
|
28
40
|
}());
|
|
29
41
|
exports.DateHelper = DateHelper;
|
package/dist/date-helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-helper.js","sourceRoot":"","sources":["../src/date-helper.ts"],"names":[],"mappings":";;;AAAA;IAAA;
|
|
1
|
+
{"version":3,"file":"date-helper.js","sourceRoot":"","sources":["../src/date-helper.ts"],"names":[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C;QAC/C,IAAM,WAAW,GAAG,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC;QAEjD,IAAI,KAAK,EAAE;YACP,OAAO,KAAK,CAAC,CAAC,CAAC,UAAG,KAAK,OAAI,CAAC,CAAC,CAAC,UAAG,KAAK,gBAAM,OAAO,mBAAS,OAAO,kBAAQ,WAAW,QAAK,CAAC;SAC/F;QAED,IAAI,OAAO,EAAE;YACT,OAAO,KAAK,CAAC,CAAC,CAAC,UAAG,OAAO,SAAM,CAAC,CAAC,CAAC,UAAG,OAAO,mBAAS,OAAO,kBAAQ,WAAW,QAAK,CAAC;SACxF;QAED,IAAI,OAAO,EAAE;YACT,OAAO,KAAK,CAAC,CAAC,CAAC,UAAG,OAAO,SAAM,CAAC,CAAC,CAAC,UAAG,OAAO,kBAAQ,WAAW,QAAK,CAAC;SACxE;QACD,OAAO,UAAG,WAAW,QAAK,CAAC;IAC/B,CAAC;IAEa,kBAAO,GAArB,UAAsB,SAAe,EAAE,YAAoB;QACvD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CACpB,SAAS,CAAC,cAAc,EAAE,EAC1B,SAAS,CAAC,WAAW,EAAE,EACvB,SAAS,CAAC,UAAU,EAAE,GAAG,YAAY,EACrC,SAAS,CAAC,WAAW,EAAE,EACvB,SAAS,CAAC,aAAa,EAAE,EACzB,SAAS,CAAC,aAAa,EAAE,CAC5B,CAAC,CAAC;IACP,CAAC;IACL,iBAAC;AAAD,CAAC,AA7CD,IA6CC;AA7CY,gCAAU"}
|
package/package.json
CHANGED
package/src/date-helper.ts
CHANGED
|
@@ -5,22 +5,42 @@ export class DateHelper {
|
|
|
5
5
|
now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
public static getElapsedTime(startDate: Date): number {
|
|
9
|
-
return (
|
|
8
|
+
public static getElapsedTime(startDate: Date, endDate = new Date()): number {
|
|
9
|
+
return Math.abs(endDate.getTime() - startDate.getTime());
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
public static getReadableElapsedTime(startDate: Date): string {
|
|
13
|
-
|
|
12
|
+
public static getReadableElapsedTime(startDate: Date, endDate = new Date(), short = false): string {
|
|
13
|
+
let elapsedTime = this.getElapsedTime(startDate, endDate);
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
const hours = Math.floor(elapsedTime / (60 * 60 * 1000));
|
|
16
|
+
elapsedTime = elapsedTime - (60 * 60 * 1000) * hours;
|
|
17
|
+
const minutes = Math.floor(elapsedTime / (60 * 1000));
|
|
18
|
+
elapsedTime = elapsedTime - (60 * 1000) * minutes;
|
|
19
|
+
const seconds = Math.floor(elapsedTime / 1000);
|
|
20
|
+
const miliseconds = elapsedTime - 1000 * seconds;
|
|
21
|
+
|
|
22
|
+
if (hours) {
|
|
23
|
+
return short ? `${hours} h` : `${hours} h ${minutes} min ${seconds} sec ${miliseconds} ms`;
|
|
24
|
+
}
|
|
18
25
|
|
|
19
26
|
if (minutes) {
|
|
20
|
-
return `${minutes} min ${seconds} sec ${miliseconds} ms`;
|
|
21
|
-
}
|
|
22
|
-
|
|
27
|
+
return short ? `${minutes} min` : `${minutes} min ${seconds} sec ${miliseconds} ms`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (seconds) {
|
|
31
|
+
return short ? `${seconds} sec` : `${seconds} sec ${miliseconds} ms`;
|
|
23
32
|
}
|
|
24
33
|
return `${miliseconds} ms`;
|
|
25
34
|
}
|
|
35
|
+
|
|
36
|
+
public static addDays(startDate: Date, numberOfDays: number): Date {
|
|
37
|
+
return new Date(Date.UTC(
|
|
38
|
+
startDate.getUTCFullYear(),
|
|
39
|
+
startDate.getUTCMonth(),
|
|
40
|
+
startDate.getUTCDate() + numberOfDays,
|
|
41
|
+
startDate.getUTCHours(),
|
|
42
|
+
startDate.getUTCMinutes(),
|
|
43
|
+
startDate.getUTCSeconds()
|
|
44
|
+
));
|
|
45
|
+
}
|
|
26
46
|
}
|