lazypush-cli 0.1.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.
@@ -0,0 +1,61 @@
1
+ import dayjs from 'dayjs';
2
+ import utc from 'dayjs/plugin/utc';
3
+ import timezone from 'dayjs/plugin/timezone';
4
+
5
+ dayjs.extend(utc);
6
+ dayjs.extend(timezone);
7
+
8
+ export function parseScheduleTime(input: string, timezone?: string): Date {
9
+ const lower = input.toLowerCase().trim();
10
+ let target = timezone ? dayjs().tz(timezone) : dayjs();
11
+
12
+ if (lower === 'now') {
13
+ return target.utc().toDate();
14
+ }
15
+
16
+ if (lower.startsWith('in ')) {
17
+ const match = lower.match(/^in (\d+)\s*(hour|minute|day)s?$/);
18
+ if (match) {
19
+ const [, num, unit] = match;
20
+ const amount = parseInt(num, 10);
21
+ if (unit === 'hour') target = target.add(amount, 'hour');
22
+ else if (unit === 'minute') target = target.add(amount, 'minute');
23
+ else if (unit === 'day') target = target.add(amount, 'day');
24
+ return target.utc().toDate();
25
+ }
26
+ }
27
+
28
+ const timeMatch = lower.match(/(\d{1,2})(?::(\d{2}))?(\s)?(am|pm)?/);
29
+ if (timeMatch) {
30
+ let [, hour, minutes, , ampm] = timeMatch;
31
+ let h = parseInt(hour, 10);
32
+ let m = minutes ? parseInt(minutes, 10) : 0;
33
+ if (ampm === 'pm' && h !== 12) h += 12;
34
+ if (ampm === 'am' && h === 12) h = 0;
35
+
36
+ const dayMatch = lower.match(/^(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\s+/i);
37
+ if (dayMatch) {
38
+ const dayName = dayMatch[1].toLowerCase();
39
+ const dayMap: { [k: string]: number } = {
40
+ monday: 1, tuesday: 2, wednesday: 3, thursday: 4,
41
+ friday: 5, saturday: 6, sunday: 0
42
+ };
43
+ const targetDay = dayMap[dayName];
44
+ const today = target.day();
45
+ let daysAhead = targetDay - today;
46
+ if (daysAhead <= 0) daysAhead += 7;
47
+ target = target.add(daysAhead, 'day');
48
+ } else if (lower.startsWith('tomorrow')) {
49
+ target = target.add(1, 'day');
50
+ }
51
+
52
+ target = target.hour(h).minute(m).second(0);
53
+ const now = timezone ? dayjs().tz(timezone) : dayjs();
54
+ if (target.isBefore(now)) {
55
+ target = target.add(1, 'day');
56
+ }
57
+ return target.utc().toDate();
58
+ }
59
+
60
+ throw new Error(`Cannot parse time: ${input}. Try: "5pm", "5:47pm", "17:30", "tomorrow 9am", "in 2 hours", "friday 8pm"`);
61
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "outDir": "dist",
6
+ "rootDir": "src",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "types": ["node"]
12
+ },
13
+ "include": ["src/**/*"]
14
+ }