@etsoo/shared 1.1.78 → 1.1.79

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.
@@ -73,6 +73,12 @@ test('Tests for formatForInput', () => {
73
73
  expect(result41).toBe('2021-06-06T20:08:45');
74
74
  });
75
75
 
76
+ test('Tests for isExpired', () => {
77
+ expect(DateUtils.isExpired(null)).toBeFalsy();
78
+ expect(DateUtils.isExpired('2020/1/1')).toBeTruthy();
79
+ expect(DateUtils.isExpired('9999/1/1')).toBeFalsy();
80
+ });
81
+
76
82
  test('Tests for substract', () => {
77
83
  const d1 = new Date('2021/1/13 12:00:00');
78
84
  const d2 = new Date('2022/1/13 12:00:00');
@@ -57,6 +57,12 @@ export declare namespace DateUtils {
57
57
  * @returns Days
58
58
  */
59
59
  const getDays: (year: number, month: number) => number;
60
+ /**
61
+ * Is the test date expired to now
62
+ * @param testDate Test date
63
+ * @returns Result
64
+ */
65
+ function isExpired(testDate?: Date | string | null): boolean;
60
66
  /**
61
67
  * Build JSON parser
62
68
  * @param keys Date field names
@@ -133,6 +133,21 @@ var DateUtils;
133
133
  * @returns Days
134
134
  */
135
135
  DateUtils.getDays = (year, month) => new Date(year, month + 1, 0).getDate();
136
+ /**
137
+ * Is the test date expired to now
138
+ * @param testDate Test date
139
+ * @returns Result
140
+ */
141
+ function isExpired(testDate) {
142
+ if (testDate == null)
143
+ return false;
144
+ const d = parse(testDate);
145
+ // Format error
146
+ if (d == null)
147
+ return false;
148
+ return d.valueOf() < new Date().valueOf();
149
+ }
150
+ DateUtils.isExpired = isExpired;
136
151
  /**
137
152
  * Build JSON parser
138
153
  * @param keys Date field names
@@ -57,6 +57,12 @@ export declare namespace DateUtils {
57
57
  * @returns Days
58
58
  */
59
59
  const getDays: (year: number, month: number) => number;
60
+ /**
61
+ * Is the test date expired to now
62
+ * @param testDate Test date
63
+ * @returns Result
64
+ */
65
+ function isExpired(testDate?: Date | string | null): boolean;
60
66
  /**
61
67
  * Build JSON parser
62
68
  * @param keys Date field names
@@ -130,6 +130,21 @@ export var DateUtils;
130
130
  * @returns Days
131
131
  */
132
132
  DateUtils.getDays = (year, month) => new Date(year, month + 1, 0).getDate();
133
+ /**
134
+ * Is the test date expired to now
135
+ * @param testDate Test date
136
+ * @returns Result
137
+ */
138
+ function isExpired(testDate) {
139
+ if (testDate == null)
140
+ return false;
141
+ const d = parse(testDate);
142
+ // Format error
143
+ if (d == null)
144
+ return false;
145
+ return d.valueOf() < new Date().valueOf();
146
+ }
147
+ DateUtils.isExpired = isExpired;
133
148
  /**
134
149
  * Build JSON parser
135
150
  * @param keys Date field names
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.78",
3
+ "version": "1.1.79",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -56,9 +56,9 @@
56
56
  "devDependencies": {
57
57
  "@types/jest": "^29.2.3",
58
58
  "@types/lodash.isequal": "^4.5.6",
59
- "@typescript-eslint/eslint-plugin": "^5.43.0",
60
- "@typescript-eslint/parser": "^5.43.0",
61
- "eslint": "^8.27.0",
59
+ "@typescript-eslint/eslint-plugin": "^5.45.0",
60
+ "@typescript-eslint/parser": "^5.45.0",
61
+ "eslint": "^8.28.0",
62
62
  "eslint-config-airbnb-base": "^15.0.0",
63
63
  "eslint-plugin-import": "^2.26.0",
64
64
  "jest": "^29.3.1",
package/src/DateUtils.ts CHANGED
@@ -194,6 +194,21 @@ export namespace DateUtils {
194
194
  export const getDays = (year: number, month: number) =>
195
195
  new Date(year, month + 1, 0).getDate();
196
196
 
197
+ /**
198
+ * Is the test date expired to now
199
+ * @param testDate Test date
200
+ * @returns Result
201
+ */
202
+ export function isExpired(testDate?: Date | string | null) {
203
+ if (testDate == null) return false;
204
+ const d = parse(testDate);
205
+
206
+ // Format error
207
+ if (d == null) return false;
208
+
209
+ return d.valueOf() < new Date().valueOf();
210
+ }
211
+
197
212
  /**
198
213
  * Build JSON parser
199
214
  * @param keys Date field names