schedule-task-mcp
Version:
MCP server for scheduled task management and execution with support for interval, cron, and date-based triggers
35 lines (33 loc) • 974 B
text/typescript
export function getSystemTimeZone(): string {
try {
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (tz && typeof tz === 'string') {
return tz;
}
} catch (error) {
console.warn('[schedule-task-mcp] Unable to resolve system timezone, falling back to Asia/Shanghai', error);
}
return 'Asia/Shanghai';
}
export function formatInTimezone(dateIso: string | undefined, timeZone: string, fallback?: string): string | undefined {
if (!dateIso) {
return fallback;
}
try {
const formatter = new Intl.DateTimeFormat('zh-CN', {
timeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
});
const date = new Date(dateIso);
return formatter.format(date).replace(/\//g, '-');
} catch (error) {
console.error('Failed to format date in timezone', timeZone, error);
return dateIso;
}
}