@8ms/helpers 2.0.34 → 2.0.37
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/.yarn/install-state.gz +0 -0
- package/date/calculation.js +21 -1
- package/date/format.d.ts +5 -0
- package/date/format.js +10 -2
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/date/calculation.js
CHANGED
|
@@ -22,6 +22,25 @@ const getDate = (input, setMidnight) => {
|
|
|
22
22
|
else if (input instanceof luxon_1.DateTime) {
|
|
23
23
|
instance = input.toUTC();
|
|
24
24
|
}
|
|
25
|
+
else if ("number" === typeof input) {
|
|
26
|
+
// Handle different numeric formats
|
|
27
|
+
if (input >= 19000101 && input <= 99991231) {
|
|
28
|
+
// YYYYMMDD format (e.g., 20231225)
|
|
29
|
+
const dateStr = input.toString();
|
|
30
|
+
const year = parseInt(dateStr.substring(0, 4));
|
|
31
|
+
const month = parseInt(dateStr.substring(4, 6));
|
|
32
|
+
const day = parseInt(dateStr.substring(6, 8));
|
|
33
|
+
instance = luxon_1.DateTime.fromObject({ year, month, day }, { zone: "utc" });
|
|
34
|
+
}
|
|
35
|
+
else if (input < 10000000000) {
|
|
36
|
+
// Unix timestamp in seconds
|
|
37
|
+
instance = luxon_1.DateTime.fromSeconds(input, { zone: "utc" });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Unix timestamp in milliseconds
|
|
41
|
+
instance = luxon_1.DateTime.fromMillis(input, { zone: "utc" });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
25
44
|
else {
|
|
26
45
|
instance = luxon_1.DateTime.fromISO(input.toString(), { zone: "utc" });
|
|
27
46
|
if (!instance.isValid) {
|
|
@@ -138,7 +157,8 @@ const getMonthsBetween = (start, end) => {
|
|
|
138
157
|
const endDate = (0, exports.getDate)(end)
|
|
139
158
|
.startOf("month");
|
|
140
159
|
// Start from the 1st of the month containing startDate
|
|
141
|
-
let current = (0, exports.getDate)(start)
|
|
160
|
+
let current = (0, exports.getDate)(start)
|
|
161
|
+
.startOf("month");
|
|
142
162
|
while (current <= endDate) {
|
|
143
163
|
months.push(current);
|
|
144
164
|
// Move to next month
|
package/date/format.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export declare const getFullDateTime: (input: InputDate) => string;
|
|
|
33
33
|
* Example: 1901-02-03 → Feb 1901
|
|
34
34
|
*/
|
|
35
35
|
export declare const getMonthYearString: (input: InputDate) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Returns a YYYY MMM value as a number for a given year.
|
|
38
|
+
* Example: 1901-02-03 → 1901 Feb
|
|
39
|
+
*/
|
|
40
|
+
export declare const getYearMonthString: (input: InputDate) => string;
|
|
36
41
|
/**
|
|
37
42
|
* Shorthand to get the current date.
|
|
38
43
|
*/
|
package/date/format.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
|
|
3
|
+
exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getYearMonthString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
|
|
4
4
|
const calculation_1 = require("./calculation");
|
|
5
5
|
const luxon_1 = require("luxon");
|
|
6
6
|
/**
|
|
@@ -73,7 +73,7 @@ exports.getFullDate = getFullDate;
|
|
|
73
73
|
* Example: 1901-02-03 01:23:45 → 1:23am 3 Feb 1901
|
|
74
74
|
*/
|
|
75
75
|
const getFullDateTime = (input) => {
|
|
76
|
-
return (0, exports.format)(input, "d MMM yyyy h:
|
|
76
|
+
return (0, exports.format)(input, "d MMM yyyy h:mm:ss");
|
|
77
77
|
};
|
|
78
78
|
exports.getFullDateTime = getFullDateTime;
|
|
79
79
|
/**
|
|
@@ -84,6 +84,14 @@ const getMonthYearString = (input) => {
|
|
|
84
84
|
return (0, exports.format)(input, "MMM yyyy");
|
|
85
85
|
};
|
|
86
86
|
exports.getMonthYearString = getMonthYearString;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a YYYY MMM value as a number for a given year.
|
|
89
|
+
* Example: 1901-02-03 → 1901 Feb
|
|
90
|
+
*/
|
|
91
|
+
const getYearMonthString = (input) => {
|
|
92
|
+
return (0, exports.format)(input, "yyyy MMM");
|
|
93
|
+
};
|
|
94
|
+
exports.getYearMonthString = getYearMonthString;
|
|
87
95
|
/**
|
|
88
96
|
* Shorthand to get the current date.
|
|
89
97
|
*/
|