chronos-ts 1.1.0 → 2.0.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.
@@ -1,61 +0,0 @@
1
- export declare class Interval {
2
- private minutes;
3
- private hours;
4
- private days;
5
- private weeks;
6
- private months;
7
- /**
8
- * Constructs a new instance of the Interval class.
9
- *
10
- * @param minutes - The number of minutes (default is 0).
11
- * @param hours - The number of hours (default is 0).
12
- * @param days - The number of days (default is 0).
13
- * @param weeks - The number of weeks (default is 0).
14
- * @param months - The number of months (default is 0).
15
- */
16
- private constructor();
17
- /**
18
- * Creates an Interval instance representing the specified number of minutes.
19
- *
20
- * @param minutes - The number of minutes for the interval.
21
- * @returns An Interval instance representing the specified number of minutes.
22
- */
23
- static minutes(minutes: number): Interval;
24
- /**
25
- * Creates an Interval instance representing the given number of hours.
26
- *
27
- * @param hours - The number of hours for the interval.
28
- * @returns An Interval instance with the specified hours.
29
- */
30
- static hours(hours: number): Interval;
31
- /**
32
- * Creates an Interval instance representing the specified number of days.
33
- *
34
- * @param days - The number of days for the interval.
35
- * @returns An Interval instance with the specified number of days.
36
- */
37
- static days(days: number): Interval;
38
- /**
39
- * Creates an Interval instance representing the specified number of weeks.
40
- *
41
- * @param weeks - The number of weeks for the interval.
42
- * @returns An Interval instance with the specified number of weeks.
43
- */
44
- static weeks(weeks: number): Interval;
45
- /**
46
- * Creates an Interval instance representing a specified number of months.
47
- *
48
- * @param months - The number of months for the interval.
49
- * @returns An Interval instance with the specified number of months.
50
- */
51
- static months(months: number): Interval;
52
- /**
53
- * Calculates the total interval in minutes.
54
- *
55
- * This method sums up the minutes, hours, days, weeks, and months
56
- * to return the total interval in minutes.
57
- *
58
- * @returns {number} The total interval in minutes.
59
- */
60
- getMinutesInterval(): number;
61
- }
package/dist/interval.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Interval = void 0;
4
- class Interval {
5
- /**
6
- * Constructs a new instance of the Interval class.
7
- *
8
- * @param minutes - The number of minutes (default is 0).
9
- * @param hours - The number of hours (default is 0).
10
- * @param days - The number of days (default is 0).
11
- * @param weeks - The number of weeks (default is 0).
12
- * @param months - The number of months (default is 0).
13
- */
14
- constructor(minutes = 0, hours = 0, days = 0, weeks = 0, months = 0) {
15
- this.minutes = minutes;
16
- this.hours = hours;
17
- this.days = days;
18
- this.weeks = weeks;
19
- this.months = months;
20
- }
21
- /**
22
- * Creates an Interval instance representing the specified number of minutes.
23
- *
24
- * @param minutes - The number of minutes for the interval.
25
- * @returns An Interval instance representing the specified number of minutes.
26
- */
27
- static minutes(minutes) {
28
- return new Interval(minutes);
29
- }
30
- /**
31
- * Creates an Interval instance representing the given number of hours.
32
- *
33
- * @param hours - The number of hours for the interval.
34
- * @returns An Interval instance with the specified hours.
35
- */
36
- static hours(hours) {
37
- return new Interval(0, hours);
38
- }
39
- /**
40
- * Creates an Interval instance representing the specified number of days.
41
- *
42
- * @param days - The number of days for the interval.
43
- * @returns An Interval instance with the specified number of days.
44
- */
45
- static days(days) {
46
- return new Interval(0, 0, days);
47
- }
48
- /**
49
- * Creates an Interval instance representing the specified number of weeks.
50
- *
51
- * @param weeks - The number of weeks for the interval.
52
- * @returns An Interval instance with the specified number of weeks.
53
- */
54
- static weeks(weeks) {
55
- return new Interval(0, 0, 0, weeks);
56
- }
57
- /**
58
- * Creates an Interval instance representing a specified number of months.
59
- *
60
- * @param months - The number of months for the interval.
61
- * @returns An Interval instance with the specified number of months.
62
- */
63
- static months(months) {
64
- return new Interval(0, 0, 0, 0, months);
65
- }
66
- /**
67
- * Calculates the total interval in minutes.
68
- *
69
- * This method sums up the minutes, hours, days, weeks, and months
70
- * to return the total interval in minutes.
71
- *
72
- * @returns {number} The total interval in minutes.
73
- */
74
- getMinutesInterval() {
75
- return (this.minutes +
76
- this.hours * 60 +
77
- this.days * 24 * 60 +
78
- this.weeks * 7 * 24 * 60 +
79
- this.months * 30 * 24 * 60);
80
- }
81
- }
82
- exports.Interval = Interval;
package/dist/period.d.ts DELETED
@@ -1,196 +0,0 @@
1
- import { Interval } from './interval';
2
- import { Precision } from './precision';
3
- export declare class Period {
4
- private startDate;
5
- private endDate;
6
- private precision;
7
- private interval;
8
- /**
9
- * Constructs a new Period instance.
10
- *
11
- * @param start - The start date of the period, either as a string or a Date object.
12
- * @param end - The end date of the period, either as a string or a Date object.
13
- * @param precision - The precision level of the period, defaulting to Precision.DAY.
14
- * @param interval - An optional interval associated with the period, defaulting to null.
15
- * @throws {Error} If start date is after end date or if dates are invalid.
16
- */
17
- constructor(start: string | Date, end: string | Date, precision?: Precision, interval?: Interval | null);
18
- /**
19
- * Validates and converts a date input to a Date object.
20
- *
21
- * @param date - The date to validate, either as a string or Date object.
22
- * @returns A valid Date object.
23
- * @throws {Error} If the date is invalid.
24
- */
25
- private validateDate;
26
- /**
27
- * Retrieves the start date of the period.
28
- *
29
- * @returns {Date} The start date as a Date object.
30
- */
31
- getStartDate(): Date;
32
- /**
33
- * Retrieves the end date of the period.
34
- *
35
- * @returns {Date} The end date as a Date object.
36
- */
37
- getEndDate(): Date;
38
- /**
39
- * Checks if a given date is within the period defined by `startDate` and `endDate`.
40
- *
41
- * @param date - The date to check, either as a string or a Date object.
42
- * @returns `true` if the date is within the period, `false` otherwise.
43
- */
44
- contains(date: string | Date): boolean;
45
- /**
46
- * Determines if the current period overlaps with another period.
47
- *
48
- * @param other - The other period to compare with.
49
- * @returns `true` if the periods overlap, otherwise `false`.
50
- */
51
- overlapsWith(other: Period): boolean;
52
- /**
53
- * Determines if the current period is adjacent to another period.
54
- *
55
- * Two periods are considered adjacent if they do not overlap and the gap
56
- * between them is within one precision unit of the larger precision of the two periods.
57
- *
58
- * @param other - The other period to compare with.
59
- * @returns `true` if the periods are adjacent, `false` otherwise.
60
- */
61
- isAdjacentTo(other: Period): boolean;
62
- /**
63
- * Retrieves an array of dates within the specified interval.
64
- *
65
- * @returns {Date[] | null} An array of dates if the interval is defined, otherwise `null`.
66
- */
67
- getDatesInInterval(): Date[] | null;
68
- /**
69
- * Calculates the number of minutes in the interval between the start and end dates.
70
- *
71
- * @returns {number} The number of minutes between the start and end dates.
72
- */
73
- getMinutesInInterval(): number;
74
- /**
75
- * Calculates the number of whole hours in the interval.
76
- *
77
- * @returns {number} The number of whole hours in the interval.
78
- */
79
- getHoursInInterval(): number;
80
- /**
81
- * Calculates the number of whole days in the interval.
82
- *
83
- * @returns The number of whole days in the interval.
84
- */
85
- getDaysInInterval(): number;
86
- /**
87
- * Calculates the number of whole weeks in the interval.
88
- *
89
- * @returns The number of whole weeks in the interval.
90
- */
91
- getWeeksInInterval(): number;
92
- /**
93
- * Calculates the number of whole months in the interval between the start and end dates.
94
- *
95
- * This method computes the difference in months between the `startDate` and `endDate` properties.
96
- * It adjusts for month boundaries by decrementing the month count if the end date's day is less than the start date's day.
97
- *
98
- * @returns {number} The number of whole months in the interval.
99
- */
100
- getMonthsInInterval(): number;
101
- /**
102
- * Calculates the number of whole years in the interval.
103
- *
104
- * @returns The number of whole years in the interval.
105
- */
106
- getYearsInInterval(): number;
107
- /**
108
- * Calculates the length of the period in the specified precision.
109
- *
110
- * @returns {number} The length of the period, rounded down to the nearest whole number.
111
- */
112
- length(): number;
113
- /**
114
- * Determines the overlapping period between this period and another period.
115
- *
116
- * @param other - The other period to check for overlap with.
117
- * @returns The overlapping period as a new `Period` instance, or `null` if there is no overlap.
118
- */
119
- overlap(other: Period): Period | null;
120
- /**
121
- * Subtracts the given period from the current period and returns the resulting periods.
122
- * If the periods do not overlap, the current period is returned as a single-element array.
123
- * If they do overlap, the resulting periods are returned as an array.
124
- *
125
- * @param other - The period to subtract from the current period.
126
- * @returns An array of resulting periods after subtraction.
127
- */
128
- subtract(other: Period): Period[];
129
- /**
130
- * Calculates the gap between this period and another period.
131
- * If the periods overlap or are adjacent, returns null.
132
- * Otherwise, returns a new Period representing the gap between the two periods.
133
- *
134
- * @param other - The other period to compare with.
135
- * @returns A new Period representing the gap, or null if the periods overlap or are adjacent.
136
- */
137
- gap(other: Period): Period | null;
138
- /**
139
- * Computes the symmetric difference between this period and another period.
140
- * The symmetric difference is defined as the set of periods that are in either
141
- * of the two periods but not in their intersection.
142
- *
143
- * @param other - The other period to compute the symmetric difference with.
144
- * @returns An array of periods representing the symmetric difference, sorted
145
- * by start date and merged if adjacent.
146
- */
147
- symmetricDifference(other: Period): Period[];
148
- private mergeAdjacentPeriods;
149
- /**
150
- * Renews the current period by creating a new `Period` instance.
151
- * The new period starts immediately after the end of the current period
152
- * and has the same length and precision.
153
- *
154
- * @returns {Period} A new `Period` instance with updated start and end dates.
155
- */
156
- renew(): Period;
157
- /**
158
- * Computes the union of this period with another period.
159
- * If the periods overlap or are adjacent, they are merged into a single period.
160
- * Otherwise, the periods are returned as separate, sorted periods.
161
- *
162
- * @param other - The other period to union with this period.
163
- * @returns An array of periods resulting from the union operation.
164
- */
165
- union(other: Period): Period[];
166
- /**
167
- * Sets the start date for the period.
168
- *
169
- * @param start - The start date, which can be a string or a Date object.
170
- * @returns The current instance for method chaining.
171
- * @throws {Error} If the new start date is after the current end date.
172
- */
173
- setStart(start: string | Date): this;
174
- /**
175
- * Sets the end date for the period.
176
- *
177
- * @param end - The end date as a string or Date object.
178
- * @returns The current instance for method chaining.
179
- * @throws {Error} If the new end date is before the current start date.
180
- */
181
- setEnd(end: string | Date): this;
182
- /**
183
- * Sets the precision for the period.
184
- *
185
- * @param precision - The precision to set.
186
- * @returns The current instance for method chaining.
187
- */
188
- setPrecision(precision: Precision): this;
189
- /**
190
- * Sets the interval for the period.
191
- *
192
- * @param interval - The interval to be set.
193
- * @returns The current instance of the period.
194
- */
195
- setInterval(interval: Interval): this;
196
- }