@naturalcycles/js-lib 14.237.0 → 14.238.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.
@@ -57,6 +57,10 @@ export declare class LocalDate {
57
57
  * Checks if this localDate is same or younger (>=) than "today" by X units.
58
58
  */
59
59
  isSameOrYoungerThan(n: number, unit: LocalDateUnit, today?: LocalDateInput): boolean;
60
+ getAgeInYears(today?: LocalDateInput): number;
61
+ getAgeInMonths(today?: LocalDateInput): number;
62
+ getAgeInDays(today?: LocalDateInput): number;
63
+ getAgeIn(unit: LocalDateUnit, today?: LocalDateInput): number;
60
64
  /**
61
65
  * Returns 1 if this > d
62
66
  * returns 0 if they are equal
@@ -108,6 +108,18 @@ class LocalDate {
108
108
  isSameOrYoungerThan(n, unit, today) {
109
109
  return this.isSameOrAfter(exports.localDate.of(today || new Date()).plus(-n, unit));
110
110
  }
111
+ getAgeInYears(today) {
112
+ return this.getAgeIn('year', today);
113
+ }
114
+ getAgeInMonths(today) {
115
+ return this.getAgeIn('month', today);
116
+ }
117
+ getAgeInDays(today) {
118
+ return this.getAgeIn('day', today);
119
+ }
120
+ getAgeIn(unit, today) {
121
+ return exports.localDate.of(today || new Date()).diff(this, unit);
122
+ }
111
123
  /**
112
124
  * Returns 1 if this > d
113
125
  * returns 0 if they are equal
@@ -163,6 +163,13 @@ export declare class LocalTime {
163
163
  * Checks if this localTime is same or younger (>=) than "now" by X units.
164
164
  */
165
165
  isSameOrYoungerThan(n: number, unit: LocalTimeUnit, now?: LocalTimeInput): boolean;
166
+ getAgeInYears(now?: LocalTimeInput): number;
167
+ getAgeInMonths(now?: LocalTimeInput): number;
168
+ getAgeInDays(now?: LocalTimeInput): number;
169
+ getAgeInHours(now?: LocalTimeInput): number;
170
+ getAgeInMinutes(now?: LocalTimeInput): number;
171
+ getAgeInSeconds(now?: LocalTimeInput): number;
172
+ getAgeIn(unit: LocalTimeUnit, now?: LocalTimeInput): number;
166
173
  /**
167
174
  * Returns 1 if this > d
168
175
  * returns 0 if they are equal
@@ -418,6 +418,27 @@ class LocalTime {
418
418
  isSameOrYoungerThan(n, unit, now) {
419
419
  return this.isSameOrAfter(exports.localTime.of(now ?? new Date()).plus(-n, unit));
420
420
  }
421
+ getAgeInYears(now) {
422
+ return this.getAgeIn('year', now);
423
+ }
424
+ getAgeInMonths(now) {
425
+ return this.getAgeIn('month', now);
426
+ }
427
+ getAgeInDays(now) {
428
+ return this.getAgeIn('day', now);
429
+ }
430
+ getAgeInHours(now) {
431
+ return this.getAgeIn('hour', now);
432
+ }
433
+ getAgeInMinutes(now) {
434
+ return this.getAgeIn('minute', now);
435
+ }
436
+ getAgeInSeconds(now) {
437
+ return this.getAgeIn('second', now);
438
+ }
439
+ getAgeIn(unit, now) {
440
+ return exports.localTime.of(now ?? new Date()).diff(this, unit);
441
+ }
421
442
  /**
422
443
  * Returns 1 if this > d
423
444
  * returns 0 if they are equal
@@ -105,6 +105,18 @@ export class LocalDate {
105
105
  isSameOrYoungerThan(n, unit, today) {
106
106
  return this.isSameOrAfter(localDate.of(today || new Date()).plus(-n, unit));
107
107
  }
108
+ getAgeInYears(today) {
109
+ return this.getAgeIn('year', today);
110
+ }
111
+ getAgeInMonths(today) {
112
+ return this.getAgeIn('month', today);
113
+ }
114
+ getAgeInDays(today) {
115
+ return this.getAgeIn('day', today);
116
+ }
117
+ getAgeIn(unit, today) {
118
+ return localDate.of(today || new Date()).diff(this, unit);
119
+ }
108
120
  /**
109
121
  * Returns 1 if this > d
110
122
  * returns 0 if they are equal
@@ -415,6 +415,27 @@ export class LocalTime {
415
415
  isSameOrYoungerThan(n, unit, now) {
416
416
  return this.isSameOrAfter(localTime.of(now ?? new Date()).plus(-n, unit));
417
417
  }
418
+ getAgeInYears(now) {
419
+ return this.getAgeIn('year', now);
420
+ }
421
+ getAgeInMonths(now) {
422
+ return this.getAgeIn('month', now);
423
+ }
424
+ getAgeInDays(now) {
425
+ return this.getAgeIn('day', now);
426
+ }
427
+ getAgeInHours(now) {
428
+ return this.getAgeIn('hour', now);
429
+ }
430
+ getAgeInMinutes(now) {
431
+ return this.getAgeIn('minute', now);
432
+ }
433
+ getAgeInSeconds(now) {
434
+ return this.getAgeIn('second', now);
435
+ }
436
+ getAgeIn(unit, now) {
437
+ return localTime.of(now ?? new Date()).diff(this, unit);
438
+ }
418
439
  /**
419
440
  * Returns 1 if this > d
420
441
  * returns 0 if they are equal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.237.0",
3
+ "version": "14.238.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -141,6 +141,19 @@ export class LocalDate {
141
141
  return this.isSameOrAfter(localDate.of(today || new Date()).plus(-n, unit))
142
142
  }
143
143
 
144
+ getAgeInYears(today?: LocalDateInput): number {
145
+ return this.getAgeIn('year', today)
146
+ }
147
+ getAgeInMonths(today?: LocalDateInput): number {
148
+ return this.getAgeIn('month', today)
149
+ }
150
+ getAgeInDays(today?: LocalDateInput): number {
151
+ return this.getAgeIn('day', today)
152
+ }
153
+ getAgeIn(unit: LocalDateUnit, today?: LocalDateInput): number {
154
+ return localDate.of(today || new Date()).diff(this, unit)
155
+ }
156
+
144
157
  /**
145
158
  * Returns 1 if this > d
146
159
  * returns 0 if they are equal
@@ -500,6 +500,28 @@ export class LocalTime {
500
500
  return this.isSameOrAfter(localTime.of(now ?? new Date()).plus(-n, unit))
501
501
  }
502
502
 
503
+ getAgeInYears(now?: LocalTimeInput): number {
504
+ return this.getAgeIn('year', now)
505
+ }
506
+ getAgeInMonths(now?: LocalTimeInput): number {
507
+ return this.getAgeIn('month', now)
508
+ }
509
+ getAgeInDays(now?: LocalTimeInput): number {
510
+ return this.getAgeIn('day', now)
511
+ }
512
+ getAgeInHours(now?: LocalTimeInput): number {
513
+ return this.getAgeIn('hour', now)
514
+ }
515
+ getAgeInMinutes(now?: LocalTimeInput): number {
516
+ return this.getAgeIn('minute', now)
517
+ }
518
+ getAgeInSeconds(now?: LocalTimeInput): number {
519
+ return this.getAgeIn('second', now)
520
+ }
521
+ getAgeIn(unit: LocalTimeUnit, now?: LocalTimeInput): number {
522
+ return localTime.of(now ?? new Date()).diff(this, unit)
523
+ }
524
+
503
525
  /**
504
526
  * Returns 1 if this > d
505
527
  * returns 0 if they are equal