@dereekb/date 0.0.1

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.
Files changed (71) hide show
  1. package/README.md +7 -0
  2. package/package.json +19 -0
  3. package/src/index.d.ts +3 -0
  4. package/src/index.js +7 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/date/date.calendar.d.ts +29 -0
  7. package/src/lib/date/date.calendar.js +54 -0
  8. package/src/lib/date/date.calendar.js.map +1 -0
  9. package/src/lib/date/date.d.ts +61 -0
  10. package/src/lib/date/date.duration.d.ts +9 -0
  11. package/src/lib/date/date.duration.js +35 -0
  12. package/src/lib/date/date.duration.js.map +1 -0
  13. package/src/lib/date/date.format.d.ts +11 -0
  14. package/src/lib/date/date.format.js +60 -0
  15. package/src/lib/date/date.format.js.map +1 -0
  16. package/src/lib/date/date.hashset.d.ts +4 -0
  17. package/src/lib/date/date.hashset.js +11 -0
  18. package/src/lib/date/date.hashset.js.map +1 -0
  19. package/src/lib/date/date.js +131 -0
  20. package/src/lib/date/date.js.map +1 -0
  21. package/src/lib/date/date.range.d.ts +107 -0
  22. package/src/lib/date/date.range.js +222 -0
  23. package/src/lib/date/date.range.js.map +1 -0
  24. package/src/lib/date/date.round.d.ts +14 -0
  25. package/src/lib/date/date.round.js +48 -0
  26. package/src/lib/date/date.round.js.map +1 -0
  27. package/src/lib/date/date.sort.d.ts +10 -0
  28. package/src/lib/date/date.sort.js +25 -0
  29. package/src/lib/date/date.sort.js.map +1 -0
  30. package/src/lib/date/date.time.d.ts +82 -0
  31. package/src/lib/date/date.time.js +208 -0
  32. package/src/lib/date/date.time.js.map +1 -0
  33. package/src/lib/date/date.time.limit.d.ts +59 -0
  34. package/src/lib/date/date.time.limit.js +93 -0
  35. package/src/lib/date/date.time.limit.js.map +1 -0
  36. package/src/lib/date/date.time.minute.d.ts +73 -0
  37. package/src/lib/date/date.time.minute.js +104 -0
  38. package/src/lib/date/date.time.minute.js.map +1 -0
  39. package/src/lib/date/date.timezone.d.ts +74 -0
  40. package/src/lib/date/date.timezone.js +126 -0
  41. package/src/lib/date/date.timezone.js.map +1 -0
  42. package/src/lib/date/date.unix.d.ts +6 -0
  43. package/src/lib/date/date.unix.js +41 -0
  44. package/src/lib/date/date.unix.js.map +1 -0
  45. package/src/lib/date/index.d.ts +13 -0
  46. package/src/lib/date/index.js +17 -0
  47. package/src/lib/date/index.js.map +1 -0
  48. package/src/lib/date.request.d.ts +22 -0
  49. package/src/lib/date.request.js +3 -0
  50. package/src/lib/date.request.js.map +1 -0
  51. package/src/lib/expires/expires.d.ts +39 -0
  52. package/src/lib/expires/expires.js +74 -0
  53. package/src/lib/expires/expires.js.map +1 -0
  54. package/src/lib/expires/index.d.ts +1 -0
  55. package/src/lib/expires/index.js +5 -0
  56. package/src/lib/expires/index.js.map +1 -0
  57. package/src/lib/rrule/date.recurrence.d.ts +60 -0
  58. package/src/lib/rrule/date.recurrence.js +84 -0
  59. package/src/lib/rrule/date.recurrence.js.map +1 -0
  60. package/src/lib/rrule/date.rrule.d.ts +125 -0
  61. package/src/lib/rrule/date.rrule.extension.d.ts +74 -0
  62. package/src/lib/rrule/date.rrule.extension.js +147 -0
  63. package/src/lib/rrule/date.rrule.extension.js.map +1 -0
  64. package/src/lib/rrule/date.rrule.js +180 -0
  65. package/src/lib/rrule/date.rrule.js.map +1 -0
  66. package/src/lib/rrule/date.rrule.parse.d.ts +114 -0
  67. package/src/lib/rrule/date.rrule.parse.js +131 -0
  68. package/src/lib/rrule/date.rrule.parse.js.map +1 -0
  69. package/src/lib/rrule/index.d.ts +4 -0
  70. package/src/lib/rrule/index.js +8 -0
  71. package/src/lib/rrule/index.js.map +1 -0
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=date.request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.request.js","sourceRoot":"","sources":["../../../../../packages/date/src/lib/date.request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ import { Maybe, UnixDateTimeNumber } from '@dereekb/util';
2
+ /**
3
+ * An object that can expire.
4
+ */
5
+ export interface Expires {
6
+ /**
7
+ * Date this object expires at. If not defined, it has expired.
8
+ */
9
+ expiresAt?: Maybe<Date>;
10
+ }
11
+ /**
12
+ * Returns true if any of the input items have expired.
13
+ *
14
+ * If the list is empty, returns false.
15
+ */
16
+ export declare function atleastOneNotExpired(expires: Maybe<Expires>[]): boolean;
17
+ /**
18
+ * Returns true if any of the input items has expired.
19
+ *
20
+ * If the list is empty, returns the second argument, or true by default.
21
+ */
22
+ export declare function anyHaveExpired(expires: Maybe<Expires>[], expireIfEmpty?: boolean): boolean;
23
+ export declare function timeNumberHasExpired(timeNumber: UnixDateTimeNumber, expiresIn?: number): boolean;
24
+ /**
25
+ * Creates an Expires object from the input time number.
26
+ *
27
+ * @param timeNumber Number to convert to a date.
28
+ * @param expiresIn If the input number is the initial date, and not the
29
+ * expiration date, this is used to find the expiresAt time.
30
+ */
31
+ export declare function timeNumberToExpires(timeNumber: UnixDateTimeNumber, expiresIn?: number): Expires;
32
+ /**
33
+ * Checks whether or not the item has expired. If no expiration date is set, it is considered expired.
34
+ */
35
+ export declare function hasExpired(expires: Maybe<Expires>): boolean;
36
+ /**
37
+ * Returns the expiration date, or a date 1 minute in the past if not defined.
38
+ */
39
+ export declare function getExpiration(expires: Maybe<Expires>): Date;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExpiration = exports.hasExpired = exports.timeNumberToExpires = exports.timeNumberHasExpired = exports.anyHaveExpired = exports.atleastOneNotExpired = void 0;
4
+ const date_1 = require("@dereekb/date");
5
+ const date_fns_1 = require("date-fns");
6
+ /**
7
+ * Returns true if any of the input items have expired.
8
+ *
9
+ * If the list is empty, returns false.
10
+ */
11
+ function atleastOneNotExpired(expires) {
12
+ for (const expire of expires) {
13
+ if (!hasExpired(expire)) {
14
+ return true;
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+ exports.atleastOneNotExpired = atleastOneNotExpired;
20
+ /**
21
+ * Returns true if any of the input items has expired.
22
+ *
23
+ * If the list is empty, returns the second argument, or true by default.
24
+ */
25
+ function anyHaveExpired(expires, expireIfEmpty = true) {
26
+ if (expires.length === 0) {
27
+ return expireIfEmpty;
28
+ }
29
+ for (const expire of expires) {
30
+ if (hasExpired(expire)) {
31
+ return true;
32
+ }
33
+ }
34
+ return false;
35
+ }
36
+ exports.anyHaveExpired = anyHaveExpired;
37
+ function timeNumberHasExpired(timeNumber, expiresIn) {
38
+ return hasExpired(timeNumberToExpires(timeNumber, expiresIn));
39
+ }
40
+ exports.timeNumberHasExpired = timeNumberHasExpired;
41
+ /**
42
+ * Creates an Expires object from the input time number.
43
+ *
44
+ * @param timeNumber Number to convert to a date.
45
+ * @param expiresIn If the input number is the initial date, and not the
46
+ * expiration date, this is used to find the expiresAt time.
47
+ */
48
+ function timeNumberToExpires(timeNumber, expiresIn) {
49
+ let expiresAt = (0, date_1.dateFromDateOrTimeNumber)(timeNumber);
50
+ if (expiresAt && expiresIn) {
51
+ expiresAt = (0, date_fns_1.addMilliseconds)(expiresAt, expiresIn);
52
+ }
53
+ return {
54
+ expiresAt
55
+ };
56
+ }
57
+ exports.timeNumberToExpires = timeNumberToExpires;
58
+ /**
59
+ * Checks whether or not the item has expired. If no expiration date is set, it is considered expired.
60
+ */
61
+ function hasExpired(expires) {
62
+ const expiresAt = getExpiration(expires);
63
+ return (0, date_fns_1.isPast)(expiresAt);
64
+ }
65
+ exports.hasExpired = hasExpired;
66
+ /**
67
+ * Returns the expiration date, or a date 1 minute in the past if not defined.
68
+ */
69
+ function getExpiration(expires) {
70
+ var _a;
71
+ return (_a = expires === null || expires === void 0 ? void 0 : expires.expiresAt) !== null && _a !== void 0 ? _a : (0, date_fns_1.addMinutes)(new Date(), -1);
72
+ }
73
+ exports.getExpiration = getExpiration;
74
+ //# sourceMappingURL=expires.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expires.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/expires/expires.ts"],"names":[],"mappings":";;;AAAA,wCAAyD;AAEzD,uCAA+D;AAY/D;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,OAAyB;IAC5D,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;YACvB,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AARD,oDAQC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,OAAyB,EAAE,aAAa,GAAG,IAAI;IAC5E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,aAAa,CAAC;KACtB;IAED,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE;YACtB,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAZD,wCAYC;AAED,SAAgB,oBAAoB,CAAC,UAA8B,EAAE,SAAkB;IACrF,OAAO,UAAU,CAAC,mBAAmB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;AAChE,CAAC;AAFD,oDAEC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,UAA8B,EAAE,SAAkB;IACpF,IAAI,SAAS,GAAG,IAAA,+BAAwB,EAAC,UAAU,CAAC,CAAC;IAErD,IAAI,SAAS,IAAI,SAAS,EAAE;QAC1B,SAAS,GAAG,IAAA,0BAAe,EAAC,SAAS,EAAE,SAAS,CAAC,CAAC;KACnD;IAED,OAAO;QACL,SAAS;KACV,CAAC;AACJ,CAAC;AAVD,kDAUC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,OAAuB;IAChD,MAAM,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,OAAO,IAAA,iBAAM,EAAC,SAAS,CAAC,CAAC;AAC3B,CAAC;AAHD,gCAGC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,OAAuB;;IACnD,OAAO,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,IAAA,qBAAU,EAAC,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAFD,sCAEC"}
@@ -0,0 +1 @@
1
+ export * from './expires';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./expires"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/expires/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B"}
@@ -0,0 +1,60 @@
1
+ import { CalendarDate, DateRange } from '../date';
2
+ import { DateRRuleInstance } from './date.rrule';
3
+ import { RRuleLines, RRuleStringLineSet } from './date.rrule.parse';
4
+ import { TimezoneString } from '@dereekb/util';
5
+ export interface RecurrenceModel {
6
+ recur?: ModelRecurrenceInfo;
7
+ recurs: boolean;
8
+ }
9
+ /**
10
+ * Indexed recurrence information for a model with recurrence information.
11
+ */
12
+ export declare class ModelRecurrenceInfo implements DateRange {
13
+ /**
14
+ * Timezone the rule is a part of.
15
+ *
16
+ * Required for RRules that have timezone-sensitive implementations.
17
+ */
18
+ timezone?: TimezoneString;
19
+ /**
20
+ * RRules for this recurrence.
21
+ */
22
+ rrule: RRuleLines;
23
+ /**
24
+ * First instance of the recurrence.
25
+ */
26
+ start: Date;
27
+ /**
28
+ * Final instance of the recurrence.
29
+ */
30
+ end: Date;
31
+ /**
32
+ * True if the recurrence has no end.
33
+ */
34
+ forever?: boolean;
35
+ constructor(template: ModelRecurrenceInfo);
36
+ }
37
+ export interface ModelRecurrenceStart {
38
+ /**
39
+ * Lines/set of rules to follow.
40
+ */
41
+ rrule: RRuleStringLineSet;
42
+ /**
43
+ * Date information for the recurrence.
44
+ */
45
+ date: CalendarDate;
46
+ /**
47
+ * Timezone the recurrence should follow.
48
+ */
49
+ timezone?: TimezoneString;
50
+ }
51
+ /**
52
+ * Used for expanding a ModelRecurrenceUpdate into ModelRecurrenceInfo.
53
+ */
54
+ export declare class ModelRecurrenceInfoUtility {
55
+ /**
56
+ * Creates a ModelRecurrenceInfo instance from the input ModelRecurrenceStart.
57
+ */
58
+ static expandModelRecurrenceStartToModelRecurrenceInfo(update: ModelRecurrenceStart): ModelRecurrenceInfo;
59
+ static makeDateRRuleInstance(info: ModelRecurrenceInfo, date: CalendarDate): DateRRuleInstance;
60
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModelRecurrenceInfoUtility = exports.ModelRecurrenceInfo = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const date_rrule_1 = require("./date.rrule");
7
+ const date_rrule_parse_1 = require("./date.rrule.parse");
8
+ /**
9
+ * Indexed recurrence information for a model with recurrence information.
10
+ */
11
+ let ModelRecurrenceInfo = class ModelRecurrenceInfo {
12
+ constructor(template) {
13
+ this.timezone = template.timezone;
14
+ this.rrule = template.rrule;
15
+ this.start = template.start;
16
+ this.end = template.end;
17
+ this.forever = template.forever;
18
+ }
19
+ };
20
+ (0, tslib_1.__decorate)([
21
+ (0, class_transformer_1.Expose)(),
22
+ (0, tslib_1.__metadata)("design:type", String)
23
+ ], ModelRecurrenceInfo.prototype, "timezone", void 0);
24
+ (0, tslib_1.__decorate)([
25
+ (0, class_transformer_1.Expose)(),
26
+ (0, tslib_1.__metadata)("design:type", String)
27
+ ], ModelRecurrenceInfo.prototype, "rrule", void 0);
28
+ (0, tslib_1.__decorate)([
29
+ (0, class_transformer_1.Expose)(),
30
+ (0, tslib_1.__metadata)("design:type", Date)
31
+ ], ModelRecurrenceInfo.prototype, "start", void 0);
32
+ (0, tslib_1.__decorate)([
33
+ (0, class_transformer_1.Expose)(),
34
+ (0, tslib_1.__metadata)("design:type", Date)
35
+ ], ModelRecurrenceInfo.prototype, "end", void 0);
36
+ (0, tslib_1.__decorate)([
37
+ (0, class_transformer_1.Expose)(),
38
+ (0, tslib_1.__metadata)("design:type", Boolean)
39
+ ], ModelRecurrenceInfo.prototype, "forever", void 0);
40
+ ModelRecurrenceInfo = (0, tslib_1.__decorate)([
41
+ (0, class_transformer_1.Exclude)(),
42
+ (0, tslib_1.__metadata)("design:paramtypes", [ModelRecurrenceInfo])
43
+ ], ModelRecurrenceInfo);
44
+ exports.ModelRecurrenceInfo = ModelRecurrenceInfo;
45
+ /**
46
+ * Used for expanding a ModelRecurrenceUpdate into ModelRecurrenceInfo.
47
+ */
48
+ class ModelRecurrenceInfoUtility {
49
+ /**
50
+ * Creates a ModelRecurrenceInfo instance from the input ModelRecurrenceStart.
51
+ */
52
+ static expandModelRecurrenceStartToModelRecurrenceInfo(update) {
53
+ var _a;
54
+ const { date, rrule, timezone } = update;
55
+ const dateRRule = date_rrule_1.DateRRuleUtility.makeInstance({
56
+ rruleStringLineSet: rrule,
57
+ options: {
58
+ date
59
+ }
60
+ });
61
+ const dateRange = dateRRule.getRecurrenceDateRange();
62
+ const rruleSetString = date_rrule_parse_1.DateRRuleParseUtility.toRRuleLines(rrule);
63
+ const recurrenceInfo = {
64
+ timezone,
65
+ rrule: rruleSetString,
66
+ start: dateRange.start,
67
+ end: (_a = dateRange.finalRecurrenceEndsAt) !== null && _a !== void 0 ? _a : dateRange.end,
68
+ forever: dateRange.forever
69
+ };
70
+ return new ModelRecurrenceInfo(recurrenceInfo);
71
+ }
72
+ static makeDateRRuleInstance(info, date) {
73
+ const { rrule, timezone } = info;
74
+ return date_rrule_1.DateRRuleUtility.makeInstance({
75
+ rruleLines: rrule,
76
+ options: {
77
+ date,
78
+ timezone
79
+ }
80
+ });
81
+ }
82
+ }
83
+ exports.ModelRecurrenceInfoUtility = ModelRecurrenceInfoUtility;
84
+ //# sourceMappingURL=date.recurrence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.recurrence.js","sourceRoot":"","sources":["../../../../../../packages/date/src/lib/rrule/date.recurrence.ts"],"names":[],"mappings":";;;;AAAA,yDAAoD;AAEpD,6CAAmE;AACnE,yDAA2F;AAQ3F;;GAEG;AAEH,IAAa,mBAAmB,GAAhC,MAAa,mBAAmB;IAkC9B,YAAY,QAA6B;QACvC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAClC,CAAC;CAEF,CAAA;AAlCC;IADC,IAAA,0BAAM,GAAE;;qDACiB;AAM1B;IADC,IAAA,0BAAM,GAAE;;kDACS;AAMlB;IADC,IAAA,0BAAM,GAAE;2CACF,IAAI;kDAAC;AAMZ;IADC,IAAA,0BAAM,GAAE;2CACJ,IAAI;gDAAC;AAMV;IADC,IAAA,0BAAM,GAAE;;oDACS;AAhCP,mBAAmB;IAD/B,IAAA,2BAAO,GAAE;kDAmCc,mBAAmB;GAlC9B,mBAAmB,CA0C/B;AA1CY,kDAAmB;AA+DhC;;GAEG;AACH,MAAa,0BAA0B;IAErC;;OAEG;IACH,MAAM,CAAC,+CAA+C,CAAC,MAA4B;;QACjF,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QAEzC,MAAM,SAAS,GAAG,6BAAgB,CAAC,YAAY,CAAC;YAC9C,kBAAkB,EAAE,KAAK;YACzB,OAAO,EAAE;gBACP,IAAI;aACL;SACF,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,SAAS,CAAC,sBAAsB,EAAE,CAAC;QACrD,MAAM,cAAc,GAAe,wCAAqB,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE7E,MAAM,cAAc,GAAG;YACrB,QAAQ;YACR,KAAK,EAAE,cAAc;YACrB,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,GAAG,EAAE,MAAA,SAAS,CAAC,qBAAqB,mCAAI,SAAS,CAAC,GAAG;YACrD,OAAO,EAAE,SAAS,CAAC,OAAO;SAC3B,CAAC;QAEF,OAAO,IAAI,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC;IAED,MAAM,CAAC,qBAAqB,CAAC,IAAyB,EAAE,IAAkB;QACxE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAEjC,OAAO,6BAAgB,CAAC,YAAY,CAAC;YACnC,UAAU,EAAE,KAAK;YACjB,OAAO,EAAE;gBACP,IAAI;gBACJ,QAAQ;aACT;SACF,CAAC,CAAC;IACL,CAAC;CAEF;AAzCD,gEAyCC"}
@@ -0,0 +1,125 @@
1
+ import { Maybe, TimezoneString } from '@dereekb/util';
2
+ import { RRule, Options } from 'rrule';
3
+ import { CalendarDate, DateSet, DateRange, DateRangeParams } from '../date';
4
+ import { BaseDateAsUTC, DateTimezoneUtcNormalInstance } from '../date/date.timezone';
5
+ import { DateRRule } from './date.rrule.extension';
6
+ import { RRuleLines, RRuleStringLineSet, RRuleStringSetSeparation } from './date.rrule.parse';
7
+ /**
8
+ * Since RRule only deals with UTC date/times, dates going into it must always be in UTC.
9
+ */
10
+ export declare type RRuleBaseDateAsUTC = BaseDateAsUTC;
11
+ export interface DateRRuleExpansionOptions {
12
+ /**
13
+ * Start/End Dates to get the range between.
14
+ */
15
+ range?: DateRange;
16
+ /**
17
+ * Optional DateRangeParams to derive the start/end from.
18
+ */
19
+ rangeParams?: DateRangeParams;
20
+ }
21
+ export interface MakeDateRRuleInstance {
22
+ /**
23
+ * Lines string to build an RRule from.
24
+ */
25
+ rruleLines?: RRuleLines;
26
+ /**
27
+ * Line set to build an RRule from.
28
+ */
29
+ rruleStringLineSet?: RRuleStringLineSet;
30
+ /**
31
+ * Options to use when creating the DateRRule.
32
+ */
33
+ options: DateRRuleInstanceOptions;
34
+ }
35
+ export interface DateRRuleStaticExpansionOptions extends DateRRuleExpansionOptions {
36
+ /**
37
+ * DateRRuleInstanceInstance to use for expansion.
38
+ */
39
+ instance?: DateRRuleInstance;
40
+ /**
41
+ * DateRRuleInstance to build.
42
+ */
43
+ instanceFrom?: MakeDateRRuleInstance;
44
+ }
45
+ export interface DateRRuleExpansion {
46
+ /**
47
+ * Range used for expansion, if applicable.
48
+ */
49
+ between?: Maybe<DateRange>;
50
+ dates: CalendarDate[];
51
+ }
52
+ export interface DateRRuleInstanceOptions {
53
+ /**
54
+ * Start reference/date. Required if DTSTART is not provided.
55
+ */
56
+ date?: CalendarDate;
57
+ /**
58
+ * (Optional) Timezone to use for the recurrence.
59
+ *
60
+ * This is not the timezone to convert values to, as this is
61
+ */
62
+ timezone?: TimezoneString;
63
+ /**
64
+ * Dates to exclude.
65
+ */
66
+ exclude?: DateSet;
67
+ }
68
+ export interface RecurrenceDateRange extends DateRange {
69
+ /**
70
+ * True if the recurrence never ends.
71
+ */
72
+ forever: boolean;
73
+ /**
74
+ * Date the final recurrence will end at, based on the duration of the event.
75
+ *
76
+ * If forever, this date is undefined.
77
+ */
78
+ finalRecurrenceEndsAt?: Maybe<Date>;
79
+ }
80
+ export interface ForeverRecurrenceDateRange extends RecurrenceDateRange {
81
+ forever: true;
82
+ finalRecurrenceEndsAt?: undefined;
83
+ }
84
+ export declare class DateRRuleInstance {
85
+ readonly options: DateRRuleInstanceOptions;
86
+ readonly rrule: DateRRule;
87
+ readonly normalInstance: DateTimezoneUtcNormalInstance;
88
+ /**
89
+ * Creates a new DateRRuleInstance from the input.
90
+ */
91
+ static make(params: MakeDateRRuleInstance): DateRRuleInstance;
92
+ constructor(rrule: RRule, options: DateRRuleInstanceOptions);
93
+ get timezone(): TimezoneString;
94
+ nextRecurrenceDate(from?: Date): Maybe<Date>;
95
+ /**
96
+ * Expands the input DateRRuleExpansionOptions to a DateRRuleExpansion.
97
+ *
98
+ * @param options
99
+ * @returns
100
+ */
101
+ expand(options: DateRRuleExpansionOptions): DateRRuleExpansion;
102
+ /**
103
+ * Returns true if there is a single date within the range.
104
+ */
105
+ haveRecurrenceInDateRange(dateRange: DateRange): boolean;
106
+ /**
107
+ * Returns the date range from when the recurrence starts, to the end date.
108
+ */
109
+ getRecurrenceDateRange(): RecurrenceDateRange | ForeverRecurrenceDateRange;
110
+ hasForeverRange(): boolean;
111
+ }
112
+ export interface RRuleOptions extends RRuleStringSetSeparation {
113
+ /**
114
+ * Options for an RRule instance
115
+ */
116
+ options: Partial<Options>;
117
+ }
118
+ export declare class DateRRuleUtility {
119
+ /**
120
+ * Creates the expansion item results based on the input.
121
+ */
122
+ static expand(options: DateRRuleStaticExpansionOptions): DateRRuleExpansion;
123
+ static makeInstance(params: MakeDateRRuleInstance): DateRRuleInstance;
124
+ static toRRuleOptions(rruleStringLineSet: RRuleStringLineSet): RRuleOptions;
125
+ }
@@ -0,0 +1,74 @@
1
+ import { Maybe } from '@dereekb/util';
2
+ import { RRule } from 'rrule';
3
+ export declare const DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED = 10000;
4
+ export declare class DateRRule extends RRule {
5
+ /**
6
+ * Returns the last occurence that occurs in the rule chain.
7
+ *
8
+ * @returns
9
+ */
10
+ last(): Maybe<Date>;
11
+ /**
12
+ * Returns the next recurrence that occurs on/after the input date.
13
+ *
14
+ * @returns
15
+ */
16
+ next(minDate: Date): Maybe<Date>;
17
+ /**
18
+ * Returns any recurrence between the input min and max dates, if specified.
19
+ *
20
+ * @param minDate
21
+ * @param maxDate
22
+ * @returns
23
+ */
24
+ any(filter?: {
25
+ minDate?: Maybe<Date>;
26
+ maxDate?: Maybe<Date>;
27
+ }): boolean;
28
+ }
29
+ /**
30
+ * Used for typing information. Unused otherwise.
31
+ */
32
+ declare abstract class BaseRRuleIter {
33
+ readonly method = "before";
34
+ readonly minDate: any;
35
+ readonly maxDate: any;
36
+ readonly _result: any;
37
+ readonly args: any;
38
+ total: number;
39
+ protected _value: Date | null;
40
+ getValue(): Date | null;
41
+ }
42
+ /**
43
+ * Used by DateRRule to find the last result.
44
+ */
45
+ export declare class LastIterResult extends BaseRRuleIter {
46
+ readonly maxIterationsAllowed: number;
47
+ readonly maxDate: Date;
48
+ constructor(maxIterationsAllowed?: number);
49
+ accept(date: Date): boolean;
50
+ add(date: Date): boolean;
51
+ clone(): LastIterResult;
52
+ }
53
+ export declare class NextIterResult extends BaseRRuleIter {
54
+ readonly minDate: Date;
55
+ readonly maxIterationsAllowed: number;
56
+ readonly maxDate: Date;
57
+ constructor(minDate: Date, maxIterationsAllowed?: number);
58
+ accept(date: Date): boolean;
59
+ add(date: Date): boolean;
60
+ clone(): NextIterResult;
61
+ }
62
+ export declare class AnyIterResult extends BaseRRuleIter {
63
+ readonly maxIterationsAllowed: number;
64
+ readonly minDate: Date | null;
65
+ readonly maxDate: Date | null;
66
+ constructor(filter?: {
67
+ minDate?: Maybe<Date>;
68
+ maxDate?: Maybe<Date>;
69
+ }, maxIterationsAllowed?: number);
70
+ accept(date: Date): boolean;
71
+ add(date: Date): boolean;
72
+ clone(): AnyIterResult;
73
+ }
74
+ export {};
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AnyIterResult = exports.NextIterResult = exports.LastIterResult = exports.DateRRule = exports.DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED = void 0;
4
+ const date_1 = require("@dereekb/date");
5
+ const rrule_1 = require("rrule");
6
+ // TODO: Fix typings in RRule, or better yet, add the given types up to RRule.
7
+ exports.DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED = 10000;
8
+ class DateRRule extends rrule_1.RRule {
9
+ /**
10
+ * Returns the last occurence that occurs in the rule chain.
11
+ *
12
+ * @returns
13
+ */
14
+ last() {
15
+ return this._iter(new LastIterResult());
16
+ }
17
+ /**
18
+ * Returns the next recurrence that occurs on/after the input date.
19
+ *
20
+ * @returns
21
+ */
22
+ next(minDate) {
23
+ return this._iter(new NextIterResult(minDate));
24
+ }
25
+ /**
26
+ * Returns any recurrence between the input min and max dates, if specified.
27
+ *
28
+ * @param minDate
29
+ * @param maxDate
30
+ * @returns
31
+ */
32
+ any(filter = {}) {
33
+ return this._iter(new AnyIterResult(filter)) != null;
34
+ }
35
+ }
36
+ exports.DateRRule = DateRRule;
37
+ /**
38
+ * Used for typing information. Unused otherwise.
39
+ */
40
+ class BaseRRuleIter {
41
+ constructor() {
42
+ this.method = 'before';
43
+ this.total = 0;
44
+ this._value = null;
45
+ }
46
+ getValue() {
47
+ return this._value;
48
+ }
49
+ }
50
+ /**
51
+ * Used by DateRRule to find the last result.
52
+ */
53
+ class LastIterResult extends BaseRRuleIter {
54
+ constructor(maxIterationsAllowed = exports.DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED) {
55
+ super();
56
+ this.maxIterationsAllowed = maxIterationsAllowed;
57
+ this.maxDate = (0, date_1.maxFutureDate)();
58
+ }
59
+ accept(date) {
60
+ ++this.total;
61
+ const tooLate = date > this.maxDate;
62
+ if (tooLate) {
63
+ return false;
64
+ }
65
+ else {
66
+ this.add(date);
67
+ const maxIterationReached = this.total >= this.maxIterationsAllowed;
68
+ return !maxIterationReached;
69
+ }
70
+ }
71
+ add(date) {
72
+ this._value = date;
73
+ return true;
74
+ }
75
+ clone() {
76
+ return new LastIterResult(this.maxIterationsAllowed);
77
+ }
78
+ }
79
+ exports.LastIterResult = LastIterResult;
80
+ class NextIterResult extends BaseRRuleIter {
81
+ constructor(minDate, maxIterationsAllowed = exports.DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED) {
82
+ super();
83
+ this.minDate = minDate;
84
+ this.maxIterationsAllowed = maxIterationsAllowed;
85
+ this.maxDate = this.minDate;
86
+ }
87
+ accept(date) {
88
+ this.total += 1;
89
+ const tooEarly = this.minDate > date;
90
+ if (tooEarly) {
91
+ const maxIterationReached = this.total >= this.maxIterationsAllowed;
92
+ return !maxIterationReached;
93
+ }
94
+ else {
95
+ this.add(date);
96
+ return false;
97
+ }
98
+ }
99
+ add(date) {
100
+ this._value = date;
101
+ return false;
102
+ }
103
+ clone() {
104
+ return new NextIterResult(this.minDate, this.maxIterationsAllowed);
105
+ }
106
+ }
107
+ exports.NextIterResult = NextIterResult;
108
+ class AnyIterResult extends BaseRRuleIter {
109
+ constructor(filter, maxIterationsAllowed = exports.DEFAULT_LAST_ITER_RESULT_MAX_ITERATIONS_ALLOWED) {
110
+ var _a, _b;
111
+ super();
112
+ this.maxIterationsAllowed = maxIterationsAllowed;
113
+ this.minDate = null;
114
+ this.maxDate = null;
115
+ if (filter) {
116
+ this.minDate = (_a = filter.minDate) !== null && _a !== void 0 ? _a : null;
117
+ this.maxDate = (_b = filter.maxDate) !== null && _b !== void 0 ? _b : null;
118
+ }
119
+ }
120
+ accept(date) {
121
+ ++this.total;
122
+ const tooEarly = this.minDate != null && (this.minDate > date);
123
+ if (tooEarly) {
124
+ const maxIterationReached = this.total >= this.maxIterationsAllowed;
125
+ return !maxIterationReached;
126
+ }
127
+ else {
128
+ const tooLate = this.maxDate != null && (this.maxDate < date);
129
+ if (tooLate) {
130
+ return true;
131
+ }
132
+ else {
133
+ this.add(date);
134
+ return false;
135
+ }
136
+ }
137
+ }
138
+ add(date) {
139
+ this._value = date;
140
+ return false;
141
+ }
142
+ clone() {
143
+ return new AnyIterResult({ minDate: this.minDate, maxDate: this.maxDate });
144
+ }
145
+ }
146
+ exports.AnyIterResult = AnyIterResult;
147
+ //# sourceMappingURL=date.rrule.extension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.rrule.extension.js","sourceRo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