@etsoo/shared 1.1.52 → 1.1.53

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 CHANGED
@@ -145,6 +145,8 @@ Dates related utilities
145
145
  |formatForInput|Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property|
146
146
  |jsonParser|JSON parser|
147
147
  |parse|Parse string to date|
148
+ |sameDay|Two dates are in the same day|
149
+ |sameMonth|Two dates are in the same month|
148
150
  |substract|Date extended method, substract a date|
149
151
 
150
152
  ## DomUtils
@@ -76,3 +76,21 @@ test('Tests for substract', () => {
76
76
  expect(d4.substract(d1).totalYears < 2).toBeTruthy();
77
77
  expect(d2.substract(d1).totalMinutes > 10).toBeTruthy();
78
78
  });
79
+
80
+ test('Tests for sameDay', () => {
81
+ expect(
82
+ DateUtils.sameDay('2022/9/11 22:03', new Date(2022, 8, 11, 10, 3))
83
+ ).toBeTruthy();
84
+ expect(
85
+ DateUtils.sameDay('2022/9/11 22:03', new Date(2022, 9, 11, 10, 3))
86
+ ).toBeFalsy();
87
+ });
88
+
89
+ test('Tests for sameMonth', () => {
90
+ expect(
91
+ DateUtils.sameMonth('2022-09-11 22:03', new Date(2022, 8, 10, 10, 3))
92
+ ).toBeTruthy();
93
+ expect(
94
+ DateUtils.sameMonth('2022/9/11 22:03', '2022/8/31 23:59:59')
95
+ ).toBeFalsy();
96
+ });
@@ -70,4 +70,18 @@ export declare namespace DateUtils {
70
70
  * @returns Date
71
71
  */
72
72
  function parse(input?: Date | string | null): Date | undefined;
73
+ /**
74
+ * Two dates are in the same day
75
+ * @param d1 First date
76
+ * @param d2 Second date
77
+ * @returns Result
78
+ */
79
+ function sameDay(d1?: Date | string | null, d2?: Date | string | null): boolean;
80
+ /**
81
+ * Two dates are in the same month
82
+ * @param d1 First date
83
+ * @param d2 Second date
84
+ * @returns Result
85
+ */
86
+ function sameMonth(d1?: Date | string | null, d2?: Date | string | null): boolean;
73
87
  }
@@ -164,4 +164,33 @@ var DateUtils;
164
164
  return input;
165
165
  }
166
166
  DateUtils.parse = parse;
167
+ /**
168
+ * Two dates are in the same day
169
+ * @param d1 First date
170
+ * @param d2 Second date
171
+ * @returns Result
172
+ */
173
+ function sameDay(d1, d2) {
174
+ d1 = parse(d1);
175
+ d2 = parse(d2);
176
+ if (d1 == null || d2 == null)
177
+ return false;
178
+ return d1.toDateString() === d2.toDateString();
179
+ }
180
+ DateUtils.sameDay = sameDay;
181
+ /**
182
+ * Two dates are in the same month
183
+ * @param d1 First date
184
+ * @param d2 Second date
185
+ * @returns Result
186
+ */
187
+ function sameMonth(d1, d2) {
188
+ d1 = parse(d1);
189
+ d2 = parse(d2);
190
+ if (d1 == null || d2 == null)
191
+ return false;
192
+ return (d1.getFullYear() === d2.getFullYear() &&
193
+ d1.getMonth() === d2.getMonth());
194
+ }
195
+ DateUtils.sameMonth = sameMonth;
167
196
  })(DateUtils = exports.DateUtils || (exports.DateUtils = {}));
@@ -70,4 +70,18 @@ export declare namespace DateUtils {
70
70
  * @returns Date
71
71
  */
72
72
  function parse(input?: Date | string | null): Date | undefined;
73
+ /**
74
+ * Two dates are in the same day
75
+ * @param d1 First date
76
+ * @param d2 Second date
77
+ * @returns Result
78
+ */
79
+ function sameDay(d1?: Date | string | null, d2?: Date | string | null): boolean;
80
+ /**
81
+ * Two dates are in the same month
82
+ * @param d1 First date
83
+ * @param d2 Second date
84
+ * @returns Result
85
+ */
86
+ function sameMonth(d1?: Date | string | null, d2?: Date | string | null): boolean;
73
87
  }
@@ -161,4 +161,33 @@ export var DateUtils;
161
161
  return input;
162
162
  }
163
163
  DateUtils.parse = parse;
164
+ /**
165
+ * Two dates are in the same day
166
+ * @param d1 First date
167
+ * @param d2 Second date
168
+ * @returns Result
169
+ */
170
+ function sameDay(d1, d2) {
171
+ d1 = parse(d1);
172
+ d2 = parse(d2);
173
+ if (d1 == null || d2 == null)
174
+ return false;
175
+ return d1.toDateString() === d2.toDateString();
176
+ }
177
+ DateUtils.sameDay = sameDay;
178
+ /**
179
+ * Two dates are in the same month
180
+ * @param d1 First date
181
+ * @param d2 Second date
182
+ * @returns Result
183
+ */
184
+ function sameMonth(d1, d2) {
185
+ d1 = parse(d1);
186
+ d2 = parse(d2);
187
+ if (d1 == null || d2 == null)
188
+ return false;
189
+ return (d1.getFullYear() === d2.getFullYear() &&
190
+ d1.getMonth() === d2.getMonth());
191
+ }
192
+ DateUtils.sameMonth = sameMonth;
164
193
  })(DateUtils || (DateUtils = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.52",
3
+ "version": "1.1.53",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,15 +54,15 @@
54
54
  },
55
55
  "homepage": "https://github.com/ETSOO/Shared#readme",
56
56
  "devDependencies": {
57
- "@types/jest": "^28.1.8",
58
- "@typescript-eslint/eslint-plugin": "^5.36.1",
59
- "@typescript-eslint/parser": "^5.36.1",
57
+ "@types/jest": "^29.0.0",
58
+ "@typescript-eslint/eslint-plugin": "^5.36.2",
59
+ "@typescript-eslint/parser": "^5.36.2",
60
60
  "eslint": "^8.23.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.26.0",
63
- "jest": "^28.1.3",
64
- "jest-environment-jsdom": "^28.1.3",
65
- "ts-jest": "^28.0.8",
66
- "typescript": "^4.8.2"
63
+ "jest": "^29.0.3",
64
+ "jest-environment-jsdom": "^29.0.3",
65
+ "ts-jest": "^29.0.0",
66
+ "typescript": "^4.8.3"
67
67
  }
68
68
  }
package/src/DateUtils.ts CHANGED
@@ -222,4 +222,39 @@ export namespace DateUtils {
222
222
  }
223
223
  return input;
224
224
  }
225
+
226
+ /**
227
+ * Two dates are in the same day
228
+ * @param d1 First date
229
+ * @param d2 Second date
230
+ * @returns Result
231
+ */
232
+ export function sameDay(
233
+ d1?: Date | string | null,
234
+ d2?: Date | string | null
235
+ ) {
236
+ d1 = parse(d1);
237
+ d2 = parse(d2);
238
+ if (d1 == null || d2 == null) return false;
239
+ return d1.toDateString() === d2.toDateString();
240
+ }
241
+
242
+ /**
243
+ * Two dates are in the same month
244
+ * @param d1 First date
245
+ * @param d2 Second date
246
+ * @returns Result
247
+ */
248
+ export function sameMonth(
249
+ d1?: Date | string | null,
250
+ d2?: Date | string | null
251
+ ) {
252
+ d1 = parse(d1);
253
+ d2 = parse(d2);
254
+ if (d1 == null || d2 == null) return false;
255
+ return (
256
+ d1.getFullYear() === d2.getFullYear() &&
257
+ d1.getMonth() === d2.getMonth()
258
+ );
259
+ }
225
260
  }