forked from jorrit-stack/Raycast-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-two-months.js
More file actions
executable file
·50 lines (41 loc) · 1.46 KB
/
add-two-months.js
File metadata and controls
executable file
·50 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Add 2 Months to Clipboard Date
// @raycast.mode silent
// @raycast.packageName Date Utils
// @raycast.icon 📅
// Documentation:
// @raycast.description Add 2 months to a date in clipboard (format: YYYY-MM-DD HH:MM:SS UTC)
// @raycast.author jorrit_harmamny
// @raycast.authorURL https://raycast.com/jorrit_harmamny
const { execSync } = require('child_process');
function addMonths(date, months) {
const d = new Date(date);
d.setMonth(d.getMonth() + months);
return d;
}
try {
const clipboardContent = execSync('pbpaste', { encoding: 'utf-8' }).trim();
// Parse custom format: "2026-02-06 13:53:18 UTC"
const dateMatch = clipboardContent.match(/^(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})\s+UTC$/);
let date;
if (dateMatch) {
// Parse the matched format
const [, year, month, day, hours, minutes, seconds] = dateMatch;
date = new Date(`${year}-${month}-${day}T${hours}:${minutes}:${seconds}Z`);
} else {
// Fallback: try to parse as-is
date = new Date(clipboardContent);
}
if (isNaN(date.getTime())) {
console.log("❌ Not a valid date format");
process.exit(1);
}
const newDate = addMonths(date, 2);
const result = newDate.toISOString().replace('T', ' ').replace(/\.\d{3}Z/, ' UTC');
execSync('pbcopy', { input: result });
console.log(`✅ Copied: ${result}`);
} catch (error) {
console.log(`❌ ${error.message}`);
}