We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 193de35 commit 8402475Copy full SHA for 8402475
src/lib/schedule.ts
@@ -0,0 +1,34 @@
1
+import dayjs from "dayjs";
2
+
3
+// Schedules must be started on Monday, Wednesday or Friday
4
+function calcFirstDate(start: dayjs.Dayjs): dayjs.Dayjs {
5
+ switch (start.day()) {
6
+ case 0:
7
+ case 2:
8
+ case 4:
9
+ return start.add(1, "d");
10
+ case 1:
11
+ case 3:
12
+ case 5:
13
+ return start;
14
+ case 6:
15
+ return start.add(2, "d");
16
+ }
17
+}
18
19
+/**
20
+ Generates scheduled dates only on Monday, Wednesday and Friday
21
+ */
22
+export function* generate({
23
+ start,
24
+}: {
25
+ start?: dayjs.Dayjs;
26
+}): Generator<dayjs.Dayjs, void, unknown> {
27
+ let initialDay = calcFirstDate(start ?? dayjs());
28
29
+ let cur = initialDay;
30
+ while (true) {
31
+ yield cur;
32
+ cur = cur.add(cur.day() >= 4 ? 3 : 2, "d");
33
34
0 commit comments