@naturalcycles/js-lib 14.93.0 → 14.94.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.
@@ -19,11 +19,20 @@ export declare class DateInterval {
19
19
  isSameOrBefore(d: DateIntervalConfig): boolean;
20
20
  isAfter(d: DateIntervalConfig): boolean;
21
21
  isSameOrAfter(d: DateIntervalConfig): boolean;
22
+ /**
23
+ * Ranges of DateInterval (start, end) are INCLUSIVE.
24
+ */
25
+ includes(d: LocalDateConfig): boolean;
22
26
  /**
23
27
  * DateIntervals compare by start date.
24
28
  * If it's the same - then by end date.
25
29
  */
26
30
  cmp(d: DateIntervalConfig): -1 | 0 | 1;
31
+ /**
32
+ * Returns an array of LocalDates that are included in the interval.
33
+ * Ranges are INCLUSIVE.
34
+ */
35
+ getDays(): LocalDate[];
27
36
  toString(): string;
28
- private toJSON;
37
+ toJSON(): string;
29
38
  }
@@ -42,6 +42,13 @@ class DateInterval {
42
42
  isSameOrAfter(d) {
43
43
  return this.cmp(d) >= 0;
44
44
  }
45
+ /**
46
+ * Ranges of DateInterval (start, end) are INCLUSIVE.
47
+ */
48
+ includes(d) {
49
+ d = localDate_1.LocalDate.of(d);
50
+ return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end);
51
+ }
45
52
  /**
46
53
  * DateIntervals compare by start date.
47
54
  * If it's the same - then by end date.
@@ -50,6 +57,19 @@ class DateInterval {
50
57
  d = DateInterval.parse(d);
51
58
  return this.start.cmp(d.start) || this.end.cmp(d.end);
52
59
  }
60
+ /**
61
+ * Returns an array of LocalDates that are included in the interval.
62
+ * Ranges are INCLUSIVE.
63
+ */
64
+ getDays() {
65
+ const days = [];
66
+ let current = this.start;
67
+ do {
68
+ days.push(current);
69
+ current = current.add(1, 'day');
70
+ } while (current.isSameOrBefore(this.end));
71
+ return days;
72
+ }
53
73
  toString() {
54
74
  return [this.start, this.end].join('/');
55
75
  }
@@ -2,6 +2,7 @@ import { Sequence } from '../seq/seq';
2
2
  import { IsoDate, UnixTimestamp } from '../types';
3
3
  import { LocalTime } from './localTime';
4
4
  export declare type LocalDateUnit = 'year' | 'month' | 'day';
5
+ export declare type Inclusiveness = '()' | '[]' | '[)' | '(]';
5
6
  export declare type LocalDateConfig = LocalDate | string;
6
7
  /**
7
8
  * @experimental
@@ -42,6 +43,7 @@ export declare class LocalDate {
42
43
  isSameOrBefore(d: LocalDateConfig): boolean;
43
44
  isAfter(d: LocalDateConfig): boolean;
44
45
  isSameOrAfter(d: LocalDateConfig): boolean;
46
+ isBetween(min: LocalDateConfig, max: LocalDateConfig, incl?: Inclusiveness): boolean;
45
47
  /**
46
48
  * Returns 1 if this > d
47
49
  * returns 0 if they are equal
@@ -131,6 +131,15 @@ class LocalDate {
131
131
  isSameOrAfter(d) {
132
132
  return this.cmp(d) >= 0;
133
133
  }
134
+ isBetween(min, max, incl = '[)') {
135
+ let r = this.cmp(min);
136
+ if (r < 0 || (r === 0 && incl[0] === '('))
137
+ return false;
138
+ r = this.cmp(max);
139
+ if (r > 0 || (r === 0 && incl[1] === ')'))
140
+ return false;
141
+ return true;
142
+ }
134
143
  /**
135
144
  * Returns 1 if this > d
136
145
  * returns 0 if they are equal
@@ -1,5 +1,5 @@
1
1
  import { IsoDate, IsoDateTime, UnixTimestamp } from '../types';
2
- import { LocalDate } from './localDate';
2
+ import { Inclusiveness, LocalDate } from './localDate';
3
3
  export declare type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second';
4
4
  export declare type LocalTimeConfig = LocalTime | Date | IsoDateTime | UnixTimestamp;
5
5
  export interface LocalTimeComponents {
@@ -64,6 +64,7 @@ export declare class LocalTime {
64
64
  isSameOrBefore(d: LocalTimeConfig): boolean;
65
65
  isAfter(d: LocalTimeConfig): boolean;
66
66
  isSameOrAfter(d: LocalTimeConfig): boolean;
67
+ isBetween(min: LocalTimeConfig, max: LocalTimeConfig, incl?: Inclusiveness): boolean;
67
68
  /**
68
69
  * Returns 1 if this > d
69
70
  * returns 0 if they are equal
@@ -263,6 +263,15 @@ class LocalTime {
263
263
  isSameOrAfter(d) {
264
264
  return this.cmp(d) >= 0;
265
265
  }
266
+ isBetween(min, max, incl = '[)') {
267
+ let r = this.cmp(min);
268
+ if (r < 0 || (r === 0 && incl[0] === '('))
269
+ return false;
270
+ r = this.cmp(max);
271
+ if (r > 0 || (r === 0 && incl[1] === ')'))
272
+ return false;
273
+ return true;
274
+ }
266
275
  /**
267
276
  * Returns 1 if this > d
268
277
  * returns 0 if they are equal
package/dist/index.d.ts CHANGED
@@ -64,8 +64,8 @@ export * from './string/leven';
64
64
  export * from './datetime/localDate';
65
65
  export * from './datetime/localTime';
66
66
  export * from './datetime/dateInterval';
67
- import { LocalDateConfig, LocalDateUnit } from './datetime/localDate';
67
+ import { LocalDateConfig, LocalDateUnit, Inclusiveness } from './datetime/localDate';
68
68
  import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime';
69
69
  import { DateIntervalConfig } from './datetime/dateInterval';
70
- export type { DateIntervalConfig, LocalDateConfig, LocalDateUnit, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
70
+ export type { DateIntervalConfig, LocalDateConfig, LocalDateUnit, Inclusiveness, LocalTimeConfig, LocalTimeUnit, LocalTimeComponents, AbortableMapper, AbortablePredicate, AbortableAsyncPredicate, AbortableAsyncMapper, PQueueCfg, MemoCache, AsyncMemoCache, PromiseDecoratorCfg, PromiseDecoratorResp, ErrorData, ErrorObject, HttpErrorData, HttpErrorResponse, Admin401ErrorData, Admin403ErrorData, StringMap, PromiseMap, AnyObject, AnyFunction, ValuesOf, ValueOf, KeyValueTuple, ObjectMapper, ObjectPredicate, InstanceId, IsoDate, IsoDateTime, Reviver, PMapOptions, Mapper, AsyncMapper, Predicate, AsyncPredicate, BatchResult, DeferredPromise, PRetryOptions, PTimeoutOptions, TryCatchOptions, StringifyAnyOptions, JsonStringifyFunction, Merge, ReadonlyDeep, Promisable, Simplify, ConditionalPick, ConditionalExcept, Class, UnixTimestamp, Integer, BaseDBEntity, SavedDBEntity, Saved, Unsaved, CreatedUpdated, CreatedUpdatedId, ObjectWithId, AnyObjectWithId, JsonSchema, JsonSchemaAny, JsonSchemaOneOf, JsonSchemaAllOf, JsonSchemaAnyOf, JsonSchemaNot, JsonSchemaRef, JsonSchemaConst, JsonSchemaEnum, JsonSchemaString, JsonSchemaNumber, JsonSchemaBoolean, JsonSchemaNull, JsonSchemaRootObject, JsonSchemaObject, JsonSchemaArray, JsonSchemaTuple, JsonSchemaBuilder, CommonLogLevel, CommonLogWithLevelFunction, CommonLogFunction, CommonLogger, };
71
71
  export { is, _createPromiseDecorator, _stringMapValues, _stringMapEntries, _objectKeys, pMap, _passthroughMapper, _passUndefinedMapper, _passthroughPredicate, _passNothingPredicate, _noop, ErrorMode, pDefer, AggregatedError, pRetry, pRetryFn, pTimeout, pTimeoutFn, _tryCatch, _TryCatch, _stringifyAny, jsonSchema, JsonSchemaAnyBuilder, commonLoggerMinLevel, commonLoggerNoop, commonLogLevelNumber, commonLoggerPipe, commonLoggerPrefix, commonLoggerCreate, PQueue, END, SKIP, };
@@ -39,6 +39,13 @@ export class DateInterval {
39
39
  isSameOrAfter(d) {
40
40
  return this.cmp(d) >= 0;
41
41
  }
42
+ /**
43
+ * Ranges of DateInterval (start, end) are INCLUSIVE.
44
+ */
45
+ includes(d) {
46
+ d = LocalDate.of(d);
47
+ return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end);
48
+ }
42
49
  /**
43
50
  * DateIntervals compare by start date.
44
51
  * If it's the same - then by end date.
@@ -47,6 +54,19 @@ export class DateInterval {
47
54
  d = DateInterval.parse(d);
48
55
  return this.start.cmp(d.start) || this.end.cmp(d.end);
49
56
  }
57
+ /**
58
+ * Returns an array of LocalDates that are included in the interval.
59
+ * Ranges are INCLUSIVE.
60
+ */
61
+ getDays() {
62
+ const days = [];
63
+ let current = this.start;
64
+ do {
65
+ days.push(current);
66
+ current = current.add(1, 'day');
67
+ } while (current.isSameOrBefore(this.end));
68
+ return days;
69
+ }
50
70
  toString() {
51
71
  return [this.start, this.end].join('/');
52
72
  }
@@ -128,6 +128,15 @@ export class LocalDate {
128
128
  isSameOrAfter(d) {
129
129
  return this.cmp(d) >= 0;
130
130
  }
131
+ isBetween(min, max, incl = '[)') {
132
+ let r = this.cmp(min);
133
+ if (r < 0 || (r === 0 && incl[0] === '('))
134
+ return false;
135
+ r = this.cmp(max);
136
+ if (r > 0 || (r === 0 && incl[1] === ')'))
137
+ return false;
138
+ return true;
139
+ }
131
140
  /**
132
141
  * Returns 1 if this > d
133
142
  * returns 0 if they are equal
@@ -260,6 +260,15 @@ export class LocalTime {
260
260
  isSameOrAfter(d) {
261
261
  return this.cmp(d) >= 0;
262
262
  }
263
+ isBetween(min, max, incl = '[)') {
264
+ let r = this.cmp(min);
265
+ if (r < 0 || (r === 0 && incl[0] === '('))
266
+ return false;
267
+ r = this.cmp(max);
268
+ if (r > 0 || (r === 0 && incl[1] === ')'))
269
+ return false;
270
+ return true;
271
+ }
263
272
  /**
264
273
  * Returns 1 if this > d
265
274
  * 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.93.0",
3
+ "version": "14.94.0",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -49,6 +49,14 @@ export class DateInterval {
49
49
  return this.cmp(d) >= 0
50
50
  }
51
51
 
52
+ /**
53
+ * Ranges of DateInterval (start, end) are INCLUSIVE.
54
+ */
55
+ includes(d: LocalDateConfig): boolean {
56
+ d = LocalDate.of(d)
57
+ return d.isSameOrAfter(this.start) && d.isSameOrBefore(this.end)
58
+ }
59
+
52
60
  /**
53
61
  * DateIntervals compare by start date.
54
62
  * If it's the same - then by end date.
@@ -58,11 +66,26 @@ export class DateInterval {
58
66
  return this.start.cmp(d.start) || this.end.cmp(d.end)
59
67
  }
60
68
 
69
+ /**
70
+ * Returns an array of LocalDates that are included in the interval.
71
+ * Ranges are INCLUSIVE.
72
+ */
73
+ getDays(): LocalDate[] {
74
+ const days: LocalDate[] = []
75
+ let current = this.start
76
+ do {
77
+ days.push(current)
78
+ current = current.add(1, 'day')
79
+ } while (current.isSameOrBefore(this.end))
80
+
81
+ return days
82
+ }
83
+
61
84
  toString(): string {
62
85
  return [this.start, this.end].join('/')
63
86
  }
64
87
 
65
- private toJSON(): string {
88
+ toJSON(): string {
66
89
  return this.toString()
67
90
  }
68
91
  }
@@ -4,6 +4,7 @@ import { END, IsoDate, UnixTimestamp } from '../types'
4
4
  import { LocalTime } from './localTime'
5
5
 
6
6
  export type LocalDateUnit = 'year' | 'month' | 'day'
7
+ export type Inclusiveness = '()' | '[]' | '[)' | '(]'
7
8
 
8
9
  const m31 = new Set<number>([1, 3, 5, 7, 8, 10, 12])
9
10
 
@@ -194,6 +195,14 @@ export class LocalDate {
194
195
  return this.cmp(d) >= 0
195
196
  }
196
197
 
198
+ isBetween(min: LocalDateConfig, max: LocalDateConfig, incl: Inclusiveness = '[)'): boolean {
199
+ let r = this.cmp(min)
200
+ if (r < 0 || (r === 0 && incl[0] === '(')) return false
201
+ r = this.cmp(max)
202
+ if (r > 0 || (r === 0 && incl[1] === ')')) return false
203
+ return true
204
+ }
205
+
197
206
  /**
198
207
  * Returns 1 if this > d
199
208
  * returns 0 if they are equal
@@ -1,7 +1,7 @@
1
1
  import { _assert } from '../error/assert'
2
2
  import { _ms } from '../time/time.util'
3
3
  import { IsoDate, IsoDateTime, UnixTimestamp } from '../types'
4
- import { LocalDate } from './localDate'
4
+ import { Inclusiveness, LocalDate } from './localDate'
5
5
 
6
6
  export type LocalTimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'
7
7
 
@@ -322,6 +322,14 @@ export class LocalTime {
322
322
  return this.cmp(d) >= 0
323
323
  }
324
324
 
325
+ isBetween(min: LocalTimeConfig, max: LocalTimeConfig, incl: Inclusiveness = '[)'): boolean {
326
+ let r = this.cmp(min)
327
+ if (r < 0 || (r === 0 && incl[0] === '(')) return false
328
+ r = this.cmp(max)
329
+ if (r > 0 || (r === 0 && incl[1] === ')')) return false
330
+ return true
331
+ }
332
+
325
333
  /**
326
334
  * Returns 1 if this > d
327
335
  * returns 0 if they are equal
package/src/index.ts CHANGED
@@ -159,7 +159,7 @@ export * from './string/leven'
159
159
  export * from './datetime/localDate'
160
160
  export * from './datetime/localTime'
161
161
  export * from './datetime/dateInterval'
162
- import { LocalDateConfig, LocalDateUnit } from './datetime/localDate'
162
+ import { LocalDateConfig, LocalDateUnit, Inclusiveness } from './datetime/localDate'
163
163
  import { LocalTimeConfig, LocalTimeUnit, LocalTimeComponents } from './datetime/localTime'
164
164
  import { DateIntervalConfig } from './datetime/dateInterval'
165
165
 
@@ -167,6 +167,7 @@ export type {
167
167
  DateIntervalConfig,
168
168
  LocalDateConfig,
169
169
  LocalDateUnit,
170
+ Inclusiveness,
170
171
  LocalTimeConfig,
171
172
  LocalTimeUnit,
172
173
  LocalTimeComponents,