@etsoo/shared 1.1.74 → 1.1.75

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.
@@ -63,8 +63,14 @@ test('Tests for formatForInput', () => {
63
63
  const result3 = DateUtils.formatForInput(d, false);
64
64
  expect(result3).toBe('2021-06-06T20:08');
65
65
 
66
+ const result31 = DateUtils.formatForInput(d, 'date');
67
+ expect(result31).toBe('2021-06-06');
68
+
66
69
  const result4 = DateUtils.formatForInput(d, true);
67
70
  expect(result4).toBe('2021-06-06T20:08:45');
71
+
72
+ const result41 = DateUtils.formatForInput(d, 'datetime-local');
73
+ expect(result41).toBe('2021-06-06T20:08:45');
68
74
  });
69
75
 
70
76
  test('Tests for substract', () => {
@@ -47,9 +47,9 @@ export declare namespace DateUtils {
47
47
  /**
48
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
+ * @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
51
51
  */
52
- function formatForInput(date?: Date | string | null, hasSecond?: boolean): string;
52
+ function formatForInput(date?: Date | string | null, hasSecondOrType?: boolean | string): string;
53
53
  /**
54
54
  * Get month's days
55
55
  * @param year Year
@@ -94,14 +94,19 @@ var DateUtils;
94
94
  /**
95
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
+ * @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
98
98
  */
99
- function formatForInput(date, hasSecond) {
99
+ function formatForInput(date, hasSecondOrType) {
100
100
  // Parse string as date
101
101
  if (typeof date === 'string')
102
102
  date = new Date(date);
103
103
  // Default is now
104
104
  date !== null && date !== void 0 ? date : (date = new Date());
105
+ const hasSecond = typeof hasSecondOrType === 'string'
106
+ ? hasSecondOrType === 'date'
107
+ ? undefined
108
+ : true
109
+ : hasSecondOrType;
105
110
  // Parts
106
111
  const parts = [
107
112
  date.getFullYear(),
@@ -47,9 +47,9 @@ export declare namespace DateUtils {
47
47
  /**
48
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
+ * @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
51
51
  */
52
- function formatForInput(date?: Date | string | null, hasSecond?: boolean): string;
52
+ function formatForInput(date?: Date | string | null, hasSecondOrType?: boolean | string): string;
53
53
  /**
54
54
  * Get month's days
55
55
  * @param year Year
@@ -91,14 +91,19 @@ export var DateUtils;
91
91
  /**
92
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
+ * @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
95
95
  */
96
- function formatForInput(date, hasSecond) {
96
+ function formatForInput(date, hasSecondOrType) {
97
97
  // Parse string as date
98
98
  if (typeof date === 'string')
99
99
  date = new Date(date);
100
100
  // Default is now
101
101
  date !== null && date !== void 0 ? date : (date = new Date());
102
+ const hasSecond = typeof hasSecondOrType === 'string'
103
+ ? hasSecondOrType === 'date'
104
+ ? undefined
105
+ : true
106
+ : hasSecondOrType;
102
107
  // Parts
103
108
  const parts = [
104
109
  date.getFullYear(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.74",
3
+ "version": "1.1.75",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DateUtils.ts CHANGED
@@ -147,11 +147,11 @@ export namespace DateUtils {
147
147
  /**
148
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
+ * @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
151
151
  */
152
152
  export function formatForInput(
153
153
  date?: Date | string | null,
154
- hasSecond?: boolean
154
+ hasSecondOrType?: boolean | string
155
155
  ) {
156
156
  // Parse string as date
157
157
  if (typeof date === 'string') date = new Date(date);
@@ -159,6 +159,13 @@ export namespace DateUtils {
159
159
  // Default is now
160
160
  date ??= new Date();
161
161
 
162
+ const hasSecond =
163
+ typeof hasSecondOrType === 'string'
164
+ ? hasSecondOrType === 'date'
165
+ ? undefined
166
+ : true
167
+ : hasSecondOrType;
168
+
162
169
  // Parts
163
170
  const parts = [
164
171
  date.getFullYear(),