chronos-ts 1.0.0 → 1.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.
- package/README.md +12 -13
- package/dist/period.d.ts +2 -0
- package/dist/period.js +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,13 +65,13 @@ const periodsOverlap = year2023.overlapsWith(q2_2023); // true
|
|
|
65
65
|
|
|
66
66
|
// Get the overlapping period
|
|
67
67
|
const overlap = year2023.overlap(q2_2023);
|
|
68
|
-
console.log(overlap?.
|
|
68
|
+
console.log(overlap?.getStartDate()t, overlap?.getEndDate()); // 2023-04-01, 2023-06-30
|
|
69
69
|
|
|
70
70
|
// Subtract a period
|
|
71
71
|
const remainingPeriods = year2023.subtract(q2_2023);
|
|
72
72
|
console.log(remainingPeriods.length); // 2
|
|
73
|
-
console.log(remainingPeriods[0].
|
|
74
|
-
console.log(remainingPeriods[1].
|
|
73
|
+
console.log(remainingPeriods[0].getStartDate(), remainingPeriods[0].getEndDate()); // 2023-01-01, 2023-03-31
|
|
74
|
+
console.log(remainingPeriods[1].getStartDate(), remainingPeriods[1].getEndDate()); // 2023-07-01, 2023-12-31
|
|
75
75
|
|
|
76
76
|
// Create a period with an interval
|
|
77
77
|
const weeklyPeriod = new Period('2023-01-01', '2023-12-31', Precision.WEEK, Interval.weeks(1));
|
|
@@ -82,7 +82,7 @@ console.log(weeklyDates?.length); // 53 (number of weeks in 2023)
|
|
|
82
82
|
|
|
83
83
|
// Renew a period
|
|
84
84
|
const nextYear = year2023.renew();
|
|
85
|
-
console.log(nextYear.
|
|
85
|
+
console.log(nextYear.getStartDate(), nextYear.getEndDate()); // 2024-01-01, 2024-12-31
|
|
86
86
|
|
|
87
87
|
// Use fluent API
|
|
88
88
|
const customPeriod = new Period('2023-01-01', '2023-12-31')
|
|
@@ -255,7 +255,7 @@ const ytd = (currentQuarter: Period): Period => {
|
|
|
255
255
|
};
|
|
256
256
|
|
|
257
257
|
const q3YTD = ytd(q3_2023);
|
|
258
|
-
console.log(`Q3 YTD period: ${q3YTD.
|
|
258
|
+
console.log(`Q3 YTD period: ${q3YTD.getStartDate().toDateString()} - ${q3YTD.getEndDate().toDateString()}`);
|
|
259
259
|
|
|
260
260
|
// Calculate quarter-over-quarter growth
|
|
261
261
|
const calculateQoQGrowth = (currentQuarter: number, previousQuarter: number): string => {
|
|
@@ -329,7 +329,7 @@ console.log(`There are ${overlappingTasks.length} overlapping tasks in the proje
|
|
|
329
329
|
|
|
330
330
|
// Calculate project progress
|
|
331
331
|
const calculateProgress = (currentDate: Date): number => {
|
|
332
|
-
const daysPassed = projectTimeline.
|
|
332
|
+
const daysPassed = new Period(projectTimeline.getStartDate(), currentDate, Precision.DAY).getDaysInInterval();
|
|
333
333
|
const totalDays = projectTimeline.getDaysInInterval();
|
|
334
334
|
return (daysPassed / totalDays) * 100;
|
|
335
335
|
};
|
|
@@ -356,7 +356,7 @@ class Subscription {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
getRenewalDate(): Date {
|
|
359
|
-
return this.getCurrentPeriod().
|
|
359
|
+
return this.getCurrentPeriod().getEndDate();
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
renew(): void {
|
|
@@ -372,16 +372,15 @@ const annualSubscription = new Subscription(new Date('2023-01-01'), 'annual');
|
|
|
372
372
|
console.log(`Annual subscription active: ${annualSubscription.isActive()}`);
|
|
373
373
|
console.log(`Annual subscription renewal date: ${annualSubscription.getRenewalDate().toDateString()}`);
|
|
374
374
|
|
|
375
|
-
const annualSubscription = new Subscription(new Date('2023-01-01'), 'annual');
|
|
376
|
-
console.log(`Annual subscription active: ${annualSubscription.isActive()}`);
|
|
377
|
-
console.log(`Annual subscription renewal date: ${annualSubscription.getRenewalDate().toDateString()}`);
|
|
378
375
|
// Check if a subscription will be active on a future date
|
|
379
376
|
const futureDate = new Date('2023-12-15');
|
|
380
377
|
console.log(`Monthly subscription active on ${futureDate.toDateString()}: ${monthlySubscription.isActive(futureDate)}`);
|
|
381
378
|
console.log(`Annual subscription active on ${futureDate.toDateString()}: ${annualSubscription.isActive(futureDate)}`);
|
|
379
|
+
|
|
382
380
|
// Renew a subscription
|
|
383
381
|
monthlySubscription.renew();
|
|
384
|
-
|
|
382
|
+
const renewedPeriod = monthlySubscription.getCurrentPeriod();
|
|
383
|
+
console.log(`Monthly subscription renewed. New period: ${renewedPeriod.getStartDate().toDateString()} - ${renewedPeriod.getEndDate().toDateString()}`);
|
|
385
384
|
```
|
|
386
385
|
|
|
387
386
|
**6. Employee Shift Management**
|
|
@@ -473,8 +472,8 @@ class Itinerary {
|
|
|
473
472
|
|
|
474
473
|
getDuration(): number {
|
|
475
474
|
if (this.events.length === 0) return 0;
|
|
476
|
-
const start = this.events.reduce((min, e) => e.
|
|
477
|
-
const end = this.events.reduce((max, e) => e.
|
|
475
|
+
const start = this.events.reduce((min, e) => e.getStartDate() < min ? e.getStartDate() : min, this.events[0].getStartDate());
|
|
476
|
+
const end = this.events.reduce((max, e) => e.getEndDate() > max ? e.getEndDate() : max, this.events[0].getEndDate());
|
|
478
477
|
return new Period(start, end, Precision.HOUR).getDaysInInterval();
|
|
479
478
|
}
|
|
480
479
|
}
|
package/dist/period.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare class Period {
|
|
|
6
6
|
private precision;
|
|
7
7
|
private interval;
|
|
8
8
|
constructor(start: string | Date, end: string | Date, precision?: Precision, interval?: Interval | null);
|
|
9
|
+
getStartDate(): Date;
|
|
10
|
+
getEndDate(): Date;
|
|
9
11
|
contains(date: string | Date): boolean;
|
|
10
12
|
overlapsWith(other: Period): boolean;
|
|
11
13
|
isAdjacentTo(other: Period): boolean;
|
package/dist/period.js
CHANGED
|
@@ -10,6 +10,12 @@ class Period {
|
|
|
10
10
|
this.precision = precision;
|
|
11
11
|
this.interval = interval;
|
|
12
12
|
}
|
|
13
|
+
getStartDate() {
|
|
14
|
+
return new Date(this.startDate);
|
|
15
|
+
}
|
|
16
|
+
getEndDate() {
|
|
17
|
+
return new Date(this.endDate);
|
|
18
|
+
}
|
|
13
19
|
contains(date) {
|
|
14
20
|
const checkDate = new Date(date);
|
|
15
21
|
return checkDate >= this.startDate && checkDate <= this.endDate;
|
package/package.json
CHANGED