-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
48 lines (42 loc) · 1.31 KB
/
Copy pathutils.js
File metadata and controls
48 lines (42 loc) · 1.31 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
export function validateInput(title, url, time) {
const result = {
isValid: true,
errors: [],
};
// Validate title
if (typeof title !== "string" || title.trim() === "") {
result.isValid = false;
result.errors.push("Please enter a title");
return result;
}
// Validate URL
try {
new URL(url);
} catch (_) {
result.isValid = false;
result.errors.push("Please enter a valid URL including the protocol (e.g., http:// or https://)");
return result;
}
// Validate time
const timeDate = new Date(time);
const now = new Date();
if (isNaN(timeDate.getTime())) {
result.isValid = false;
result.errors.push("Please enter a valid time");
return result;
} else if (timeDate <= now) {
result.isValid = false;
result.errors.push("The scheduled time must be in the future");
return result;
}
return result;
}
// Helper function to format date for datetime-local input
export function formatDateTimeForInput(date) {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
return `${year}-${month}-${day}T${hours}:${minutes}`;
}