@etsoo/shared 1.1.51 → 1.1.52
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/README.md +1 -0
- package/__tests__/DateUtils.ts +8 -1
- package/lib/cjs/DateUtils.d.ts +3 -2
- package/lib/cjs/DateUtils.js +11 -4
- package/lib/mjs/DateUtils.d.ts +3 -2
- package/lib/mjs/DateUtils.js +11 -4
- package/package.json +4 -5
- package/src/DateUtils.ts +13 -4
package/README.md
CHANGED
|
@@ -142,6 +142,7 @@ Dates related utilities
|
|
|
142
142
|
|Methods||
|
|
143
143
|
|getDays|Get month's days|
|
|
144
144
|
|forma|Format dates|
|
|
145
|
+
|formatForInput|Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property|
|
|
145
146
|
|jsonParser|JSON parser|
|
|
146
147
|
|parse|Parse string to date|
|
|
147
148
|
|substract|Date extended method, substract a date|
|
package/__tests__/DateUtils.ts
CHANGED
|
@@ -56,8 +56,15 @@ test('Tests for formatForInput', () => {
|
|
|
56
56
|
const result1 = DateUtils.formatForInput('2021/7/17');
|
|
57
57
|
expect(result1).toBe('2021-07-17');
|
|
58
58
|
|
|
59
|
-
const
|
|
59
|
+
const d = new Date(2021, 5, 6, 20, 18, 45);
|
|
60
|
+
const result2 = DateUtils.formatForInput(d);
|
|
60
61
|
expect(result2).toBe('2021-06-06');
|
|
62
|
+
|
|
63
|
+
const result3 = DateUtils.formatForInput(d, false);
|
|
64
|
+
expect(result3).toBe('2021-06-06T20:18');
|
|
65
|
+
|
|
66
|
+
const result4 = DateUtils.formatForInput(d, true);
|
|
67
|
+
expect(result4).toBe('2021-06-06T20:18:45');
|
|
61
68
|
});
|
|
62
69
|
|
|
63
70
|
test('Tests for substract', () => {
|
package/lib/cjs/DateUtils.d.ts
CHANGED
|
@@ -45,10 +45,11 @@ export declare namespace DateUtils {
|
|
|
45
45
|
*/
|
|
46
46
|
function format(input?: Date | string, locale?: string | string[], options?: FormatOptions, timeZone?: string): string | undefined;
|
|
47
47
|
/**
|
|
48
|
-
* Format to 'yyyy-MM-dd', especially used for date input min/max property
|
|
48
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
49
49
|
* @param date Input date
|
|
50
|
+
* @param hasSecond 'undefined' for date only, 'false' for hour:minute only
|
|
50
51
|
*/
|
|
51
|
-
function formatForInput(date?: Date | string | null): string;
|
|
52
|
+
function formatForInput(date?: Date | string | null, hasSecond?: boolean): string;
|
|
52
53
|
/**
|
|
53
54
|
* Get month's days
|
|
54
55
|
* @param year Year
|
package/lib/cjs/DateUtils.js
CHANGED
|
@@ -92,10 +92,11 @@ var DateUtils;
|
|
|
92
92
|
}
|
|
93
93
|
DateUtils.format = format;
|
|
94
94
|
/**
|
|
95
|
-
* Format to 'yyyy-MM-dd', especially used for date input min/max property
|
|
95
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
96
96
|
* @param date Input date
|
|
97
|
+
* @param hasSecond 'undefined' for date only, 'false' for hour:minute only
|
|
97
98
|
*/
|
|
98
|
-
function formatForInput(date) {
|
|
99
|
+
function formatForInput(date, hasSecond) {
|
|
99
100
|
// Parse string as date
|
|
100
101
|
if (typeof date === 'string')
|
|
101
102
|
date = new Date(date);
|
|
@@ -107,8 +108,14 @@ var DateUtils;
|
|
|
107
108
|
(date.getMonth() + 1).toString().padStart(2, '0'),
|
|
108
109
|
date.getDate().toString().padStart(2, '0')
|
|
109
110
|
];
|
|
110
|
-
//
|
|
111
|
-
|
|
111
|
+
// Date
|
|
112
|
+
const d = parts.join('-');
|
|
113
|
+
if (hasSecond == null)
|
|
114
|
+
return d;
|
|
115
|
+
const hm = [date.getHours(), date.getMinutes()];
|
|
116
|
+
if (hasSecond)
|
|
117
|
+
hm.push(date.getSeconds());
|
|
118
|
+
return `${d}T${hm.join(':')}`;
|
|
112
119
|
}
|
|
113
120
|
DateUtils.formatForInput = formatForInput;
|
|
114
121
|
/**
|
package/lib/mjs/DateUtils.d.ts
CHANGED
|
@@ -45,10 +45,11 @@ export declare namespace DateUtils {
|
|
|
45
45
|
*/
|
|
46
46
|
function format(input?: Date | string, locale?: string | string[], options?: FormatOptions, timeZone?: string): string | undefined;
|
|
47
47
|
/**
|
|
48
|
-
* Format to 'yyyy-MM-dd', especially used for date input min/max property
|
|
48
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
49
49
|
* @param date Input date
|
|
50
|
+
* @param hasSecond 'undefined' for date only, 'false' for hour:minute only
|
|
50
51
|
*/
|
|
51
|
-
function formatForInput(date?: Date | string | null): string;
|
|
52
|
+
function formatForInput(date?: Date | string | null, hasSecond?: boolean): string;
|
|
52
53
|
/**
|
|
53
54
|
* Get month's days
|
|
54
55
|
* @param year Year
|
package/lib/mjs/DateUtils.js
CHANGED
|
@@ -89,10 +89,11 @@ export var DateUtils;
|
|
|
89
89
|
}
|
|
90
90
|
DateUtils.format = format;
|
|
91
91
|
/**
|
|
92
|
-
* Format to 'yyyy-MM-dd', especially used for date input min/max property
|
|
92
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
93
93
|
* @param date Input date
|
|
94
|
+
* @param hasSecond 'undefined' for date only, 'false' for hour:minute only
|
|
94
95
|
*/
|
|
95
|
-
function formatForInput(date) {
|
|
96
|
+
function formatForInput(date, hasSecond) {
|
|
96
97
|
// Parse string as date
|
|
97
98
|
if (typeof date === 'string')
|
|
98
99
|
date = new Date(date);
|
|
@@ -104,8 +105,14 @@ export var DateUtils;
|
|
|
104
105
|
(date.getMonth() + 1).toString().padStart(2, '0'),
|
|
105
106
|
date.getDate().toString().padStart(2, '0')
|
|
106
107
|
];
|
|
107
|
-
//
|
|
108
|
-
|
|
108
|
+
// Date
|
|
109
|
+
const d = parts.join('-');
|
|
110
|
+
if (hasSecond == null)
|
|
111
|
+
return d;
|
|
112
|
+
const hm = [date.getHours(), date.getMinutes()];
|
|
113
|
+
if (hasSecond)
|
|
114
|
+
hm.push(date.getSeconds());
|
|
115
|
+
return `${d}T${hm.join(':')}`;
|
|
109
116
|
}
|
|
110
117
|
DateUtils.formatForInput = formatForInput;
|
|
111
118
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.52",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -53,12 +53,11 @@
|
|
|
53
53
|
"url": "https://github.com/ETSOO/Shared/issues"
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
56
|
-
"dependencies": {},
|
|
57
56
|
"devDependencies": {
|
|
58
57
|
"@types/jest": "^28.1.8",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
60
|
-
"@typescript-eslint/parser": "^5.
|
|
61
|
-
"eslint": "^8.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
59
|
+
"@typescript-eslint/parser": "^5.36.1",
|
|
60
|
+
"eslint": "^8.23.0",
|
|
62
61
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
63
62
|
"eslint-plugin-import": "^2.26.0",
|
|
64
63
|
"jest": "^28.1.3",
|
package/src/DateUtils.ts
CHANGED
|
@@ -145,10 +145,14 @@ export namespace DateUtils {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Format to 'yyyy-MM-dd', especially used for date input min/max property
|
|
148
|
+
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
149
149
|
* @param date Input date
|
|
150
|
+
* @param hasSecond 'undefined' for date only, 'false' for hour:minute only
|
|
150
151
|
*/
|
|
151
|
-
export function formatForInput(
|
|
152
|
+
export function formatForInput(
|
|
153
|
+
date?: Date | string | null,
|
|
154
|
+
hasSecond?: boolean
|
|
155
|
+
) {
|
|
152
156
|
// Parse string as date
|
|
153
157
|
if (typeof date === 'string') date = new Date(date);
|
|
154
158
|
|
|
@@ -162,8 +166,13 @@ export namespace DateUtils {
|
|
|
162
166
|
date.getDate().toString().padStart(2, '0')
|
|
163
167
|
];
|
|
164
168
|
|
|
165
|
-
//
|
|
166
|
-
|
|
169
|
+
// Date
|
|
170
|
+
const d = parts.join('-');
|
|
171
|
+
if (hasSecond == null) return d;
|
|
172
|
+
|
|
173
|
+
const hm = [date.getHours(), date.getMinutes()];
|
|
174
|
+
if (hasSecond) hm.push(date.getSeconds());
|
|
175
|
+
return `${d}T${hm.join(':')}`;
|
|
167
176
|
}
|
|
168
177
|
|
|
169
178
|
/**
|