Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -833,10 +833,26 @@ client.on('messageReactionAdd', async (reaction, user) => {
|
|
| 833 |
}
|
| 834 |
});
|
| 835 |
|
| 836 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 837 |
if (!timeInput) return null;
|
| 838 |
const now = new Date();
|
| 839 |
let targetDate = new Date();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
// Support formats like "9 PM", "4/23 9 PM", "4-23 9PM"
|
| 841 |
const regex = /(?:(\d+)[/-](\d+)\s+)?(\d+)\s*(am|pm)/i;
|
| 842 |
const match = timeInput.match(regex);
|
|
@@ -853,9 +869,9 @@ function parseMatchTime(timeInput, offset = 0) {
|
|
| 853 |
if (ampm === 'am' && hours === 12) hours = 0;
|
| 854 |
targetDate.setHours(hours, 0, 0, 0);
|
| 855 |
|
| 856 |
-
//
|
| 857 |
const ts = Math.floor(targetDate.getTime() / 1000);
|
| 858 |
-
return ts - (
|
| 859 |
}
|
| 860 |
return null;
|
| 861 |
}
|
|
|
|
| 833 |
}
|
| 834 |
});
|
| 835 |
|
| 836 |
+
const TIMEZONE_MAP = {
|
| 837 |
+
'EST': -5, 'EDT': -4, 'CST': -6, 'CDT': -5, 'MST': -7, 'MDT': -6,
|
| 838 |
+
'PST': -8, 'PDT': -7, 'GMT': 0, 'UTC': 0, 'BST': 1, 'CET': 1,
|
| 839 |
+
'CEST': 2, 'EET': 2, 'EEST': 3, 'MSK': 3, 'IST': 5.5, 'KST': 9, 'JST': 9
|
| 840 |
+
};
|
| 841 |
+
|
| 842 |
+
function parseMatchTime(timeInput, serverOffset = 0) {
|
| 843 |
if (!timeInput) return null;
|
| 844 |
const now = new Date();
|
| 845 |
let targetDate = new Date();
|
| 846 |
+
|
| 847 |
+
// Check if user provided a timezone code (e.g. "9 PM EST")
|
| 848 |
+
let activeOffset = serverOffset;
|
| 849 |
+
for (const [code, offset] of Object.entries(TIMEZONE_MAP)) {
|
| 850 |
+
if (timeInput.toUpperCase().includes(code)) {
|
| 851 |
+
activeOffset = offset;
|
| 852 |
+
break;
|
| 853 |
+
}
|
| 854 |
+
}
|
| 855 |
+
|
| 856 |
// Support formats like "9 PM", "4/23 9 PM", "4-23 9PM"
|
| 857 |
const regex = /(?:(\d+)[/-](\d+)\s+)?(\d+)\s*(am|pm)/i;
|
| 858 |
const match = timeInput.match(regex);
|
|
|
|
| 869 |
if (ampm === 'am' && hours === 12) hours = 0;
|
| 870 |
targetDate.setHours(hours, 0, 0, 0);
|
| 871 |
|
| 872 |
+
// Convert to UTC by subtracting the offset
|
| 873 |
const ts = Math.floor(targetDate.getTime() / 1000);
|
| 874 |
+
return ts - (activeOffset * 3600);
|
| 875 |
}
|
| 876 |
return null;
|
| 877 |
}
|