@naturalcycles/js-lib 14.185.0 → 14.187.0

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.
@@ -55,8 +55,20 @@ export declare class LocalDate {
55
55
  * Example:
56
56
  *
57
57
  * localDate(expirationDate).isOlderThan(5, 'day')
58
+ *
59
+ * Third argument allows to override "today".
58
60
  */
59
- isOlderThan(n: number, unit: LocalDateUnitStrict): boolean;
61
+ isOlderThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean;
62
+ /**
63
+ * Checks if this localDate is younger than "today" by X units.
64
+ *
65
+ * Example:
66
+ *
67
+ * localDate(expirationDate).isYoungerThan(5, 'day')
68
+ *
69
+ * Third argument allows to override "today".
70
+ */
71
+ isYoungerThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean;
60
72
  /**
61
73
  * Returns 1 if this > d
62
74
  * returns 0 if they are equal
@@ -75,6 +87,10 @@ export declare class LocalDate {
75
87
  diff(d: LocalDateInput, unit: LocalDateUnit): number;
76
88
  add(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
77
89
  subtract(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
90
+ /**
91
+ * Alias to subtract
92
+ */
93
+ minus(num: number, unit: LocalDateUnit, mutate?: boolean): LocalDate;
78
94
  startOf(unit: LocalDateUnitStrict): LocalDate;
79
95
  endOf(unit: LocalDateUnitStrict): LocalDate;
80
96
  static getYearLength(year: number): number;
@@ -185,9 +185,23 @@ class LocalDate {
185
185
  * Example:
186
186
  *
187
187
  * localDate(expirationDate).isOlderThan(5, 'day')
188
+ *
189
+ * Third argument allows to override "today".
190
+ */
191
+ isOlderThan(n, unit, today) {
192
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit));
193
+ }
194
+ /**
195
+ * Checks if this localDate is younger than "today" by X units.
196
+ *
197
+ * Example:
198
+ *
199
+ * localDate(expirationDate).isYoungerThan(5, 'day')
200
+ *
201
+ * Third argument allows to override "today".
188
202
  */
189
- isOlderThan(n, unit) {
190
- return this.isBefore(LocalDate.today().add(-n, unit));
203
+ isYoungerThan(n, unit, today) {
204
+ return !this.isOlderThan(n, unit, today);
191
205
  }
192
206
  /**
193
207
  * Returns 1 if this > d
@@ -338,6 +352,12 @@ class LocalDate {
338
352
  subtract(num, unit, mutate = false) {
339
353
  return this.add(-num, unit, mutate);
340
354
  }
355
+ /**
356
+ * Alias to subtract
357
+ */
358
+ minus(num, unit, mutate = false) {
359
+ return this.add(-num, unit, mutate);
360
+ }
341
361
  startOf(unit) {
342
362
  if (unit === 'day')
343
363
  return this;
@@ -72,6 +72,10 @@ export declare class LocalTime {
72
72
  setComponents(c: Partial<LocalTimeComponents>, mutate?: boolean): LocalTime;
73
73
  add(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
74
74
  subtract(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
75
+ /**
76
+ * Alias to subtract.
77
+ */
78
+ minus(num: number, unit: LocalTimeUnit, mutate?: boolean): LocalTime;
75
79
  absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number;
76
80
  diff(other: LocalTimeInput, unit: LocalTimeUnit): number;
77
81
  startOf(unit: LocalTimeUnit, mutate?: boolean): LocalTime;
@@ -93,8 +97,20 @@ export declare class LocalTime {
93
97
  * Example:
94
98
  *
95
99
  * localTime(expirationDate).isOlderThan(5, 'day')
100
+ *
101
+ * Third argument allows to override "now".
102
+ */
103
+ isOlderThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean;
104
+ /**
105
+ * Checks if this localTime is younger than "now" by X units.
106
+ *
107
+ * Example:
108
+ *
109
+ * localTime(expirationDate).isYoungerThan(5, 'day')
110
+ *
111
+ * Third argument allows to override "now".
96
112
  */
97
- isOlderThan(n: number, unit: LocalTimeUnit): boolean;
113
+ isYoungerThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean;
98
114
  /**
99
115
  * Returns 1 if this > d
100
116
  * returns 0 if they are equal
@@ -214,6 +214,12 @@ class LocalTime {
214
214
  subtract(num, unit, mutate = false) {
215
215
  return this.add(num * -1, unit, mutate);
216
216
  }
217
+ /**
218
+ * Alias to subtract.
219
+ */
220
+ minus(num, unit, mutate = false) {
221
+ return this.add(num * -1, unit, mutate);
222
+ }
217
223
  absDiff(other, unit) {
218
224
  return Math.abs(this.diff(other, unit));
219
225
  }
@@ -363,9 +369,23 @@ class LocalTime {
363
369
  * Example:
364
370
  *
365
371
  * localTime(expirationDate).isOlderThan(5, 'day')
372
+ *
373
+ * Third argument allows to override "now".
374
+ */
375
+ isOlderThan(n, unit, now) {
376
+ return this.isBefore(LocalTime.of(now ?? new Date()).add(-n, unit));
377
+ }
378
+ /**
379
+ * Checks if this localTime is younger than "now" by X units.
380
+ *
381
+ * Example:
382
+ *
383
+ * localTime(expirationDate).isYoungerThan(5, 'day')
384
+ *
385
+ * Third argument allows to override "now".
366
386
  */
367
- isOlderThan(n, unit) {
368
- return this.isBefore(LocalTime.now().add(-n, unit));
387
+ isYoungerThan(n, unit, now) {
388
+ return !this.isOlderThan(n, unit, now);
369
389
  }
370
390
  /**
371
391
  * Returns 1 if this > d
@@ -182,9 +182,23 @@ export class LocalDate {
182
182
  * Example:
183
183
  *
184
184
  * localDate(expirationDate).isOlderThan(5, 'day')
185
+ *
186
+ * Third argument allows to override "today".
187
+ */
188
+ isOlderThan(n, unit, today) {
189
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit));
190
+ }
191
+ /**
192
+ * Checks if this localDate is younger than "today" by X units.
193
+ *
194
+ * Example:
195
+ *
196
+ * localDate(expirationDate).isYoungerThan(5, 'day')
197
+ *
198
+ * Third argument allows to override "today".
185
199
  */
186
- isOlderThan(n, unit) {
187
- return this.isBefore(LocalDate.today().add(-n, unit));
200
+ isYoungerThan(n, unit, today) {
201
+ return !this.isOlderThan(n, unit, today);
188
202
  }
189
203
  /**
190
204
  * Returns 1 if this > d
@@ -335,6 +349,12 @@ export class LocalDate {
335
349
  subtract(num, unit, mutate = false) {
336
350
  return this.add(-num, unit, mutate);
337
351
  }
352
+ /**
353
+ * Alias to subtract
354
+ */
355
+ minus(num, unit, mutate = false) {
356
+ return this.add(-num, unit, mutate);
357
+ }
338
358
  startOf(unit) {
339
359
  if (unit === 'day')
340
360
  return this;
@@ -212,6 +212,12 @@ export class LocalTime {
212
212
  subtract(num, unit, mutate = false) {
213
213
  return this.add(num * -1, unit, mutate);
214
214
  }
215
+ /**
216
+ * Alias to subtract.
217
+ */
218
+ minus(num, unit, mutate = false) {
219
+ return this.add(num * -1, unit, mutate);
220
+ }
215
221
  absDiff(other, unit) {
216
222
  return Math.abs(this.diff(other, unit));
217
223
  }
@@ -361,9 +367,23 @@ export class LocalTime {
361
367
  * Example:
362
368
  *
363
369
  * localTime(expirationDate).isOlderThan(5, 'day')
370
+ *
371
+ * Third argument allows to override "now".
372
+ */
373
+ isOlderThan(n, unit, now) {
374
+ return this.isBefore(LocalTime.of(now !== null && now !== void 0 ? now : new Date()).add(-n, unit));
375
+ }
376
+ /**
377
+ * Checks if this localTime is younger than "now" by X units.
378
+ *
379
+ * Example:
380
+ *
381
+ * localTime(expirationDate).isYoungerThan(5, 'day')
382
+ *
383
+ * Third argument allows to override "now".
364
384
  */
365
- isOlderThan(n, unit) {
366
- return this.isBefore(LocalTime.now().add(-n, unit));
385
+ isYoungerThan(n, unit, now) {
386
+ return !this.isOlderThan(n, unit, now);
367
387
  }
368
388
  /**
369
389
  * Returns 1 if this > d
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.185.0",
3
+ "version": "14.187.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -246,9 +246,24 @@ export class LocalDate {
246
246
  * Example:
247
247
  *
248
248
  * localDate(expirationDate).isOlderThan(5, 'day')
249
+ *
250
+ * Third argument allows to override "today".
251
+ */
252
+ isOlderThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean {
253
+ return this.isBefore(LocalDate.of(today || new Date()).add(-n, unit))
254
+ }
255
+
256
+ /**
257
+ * Checks if this localDate is younger than "today" by X units.
258
+ *
259
+ * Example:
260
+ *
261
+ * localDate(expirationDate).isYoungerThan(5, 'day')
262
+ *
263
+ * Third argument allows to override "today".
249
264
  */
250
- isOlderThan(n: number, unit: LocalDateUnitStrict): boolean {
251
- return this.isBefore(LocalDate.today().add(-n, unit))
265
+ isYoungerThan(n: number, unit: LocalDateUnitStrict, today?: LocalDateInput): boolean {
266
+ return !this.isOlderThan(n, unit, today)
252
267
  }
253
268
 
254
269
  /**
@@ -417,6 +432,13 @@ export class LocalDate {
417
432
  return this.add(-num, unit, mutate)
418
433
  }
419
434
 
435
+ /**
436
+ * Alias to subtract
437
+ */
438
+ minus(num: number, unit: LocalDateUnit, mutate = false): LocalDate {
439
+ return this.add(-num, unit, mutate)
440
+ }
441
+
420
442
  startOf(unit: LocalDateUnitStrict): LocalDate {
421
443
  if (unit === 'day') return this
422
444
  if (unit === 'month') return LocalDate.create(this.$year, this.$month, 1)
@@ -284,6 +284,13 @@ export class LocalTime {
284
284
  return this.add(num * -1, unit, mutate)
285
285
  }
286
286
 
287
+ /**
288
+ * Alias to subtract.
289
+ */
290
+ minus(num: number, unit: LocalTimeUnit, mutate = false): LocalTime {
291
+ return this.add(num * -1, unit, mutate)
292
+ }
293
+
287
294
  absDiff(other: LocalTimeInput, unit: LocalTimeUnit): number {
288
295
  return Math.abs(this.diff(other, unit))
289
296
  }
@@ -446,9 +453,24 @@ export class LocalTime {
446
453
  * Example:
447
454
  *
448
455
  * localTime(expirationDate).isOlderThan(5, 'day')
456
+ *
457
+ * Third argument allows to override "now".
458
+ */
459
+ isOlderThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean {
460
+ return this.isBefore(LocalTime.of(now ?? new Date()).add(-n, unit))
461
+ }
462
+
463
+ /**
464
+ * Checks if this localTime is younger than "now" by X units.
465
+ *
466
+ * Example:
467
+ *
468
+ * localTime(expirationDate).isYoungerThan(5, 'day')
469
+ *
470
+ * Third argument allows to override "now".
449
471
  */
450
- isOlderThan(n: number, unit: LocalTimeUnit): boolean {
451
- return this.isBefore(LocalTime.now().add(-n, unit))
472
+ isYoungerThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean {
473
+ return !this.isOlderThan(n, unit, now)
452
474
  }
453
475
 
454
476
  /**