- Handle empty 2xx Graph API responses without JSON parse errors - Fix list-rules handler import (handleListRules named export) - Add timezone-aware display formatting using MS_TIMEZONE / DEFAULT_TIMEZONE - Return created event ID in create-event success message - Change default timezone from Windows name to IANA (America/New_York)
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
/**
|
|
* Timezone-aware date formatting utilities for Outlook MCP Server.
|
|
*
|
|
* All user-visible timestamps are formatted in the configured timezone
|
|
* (MS_TIMEZONE env var, default Eastern Standard Time) so that dates
|
|
* rendered inside the UTC container still match the user's local time.
|
|
*/
|
|
const config = require('../config');
|
|
|
|
/**
|
|
* Format an ISO 8601 or Graph dateTime string for display.
|
|
* @param {string} isoString - ISO 8601 / UTC timestamp from Graph API
|
|
* @param {string} [timeZone] - IANA or Windows timezone name (defaults to config.DEFAULT_TIMEZONE)
|
|
* @returns {string} Formatted date/time string with timezone abbreviation
|
|
*/
|
|
function formatDateTime(isoString, timeZone = config.DEFAULT_TIMEZONE) {
|
|
if (!isoString) return 'Unknown';
|
|
|
|
const d = new Date(isoString);
|
|
if (isNaN(d.getTime())) return String(isoString);
|
|
|
|
try {
|
|
return d.toLocaleString('en-US', {
|
|
timeZone,
|
|
month: 'numeric',
|
|
day: 'numeric',
|
|
year: 'numeric',
|
|
hour: 'numeric',
|
|
minute: '2-digit',
|
|
hour12: true,
|
|
timeZoneName: 'short'
|
|
});
|
|
} catch (err) {
|
|
// If the configured timezone identifier is invalid, fall back to ISO.
|
|
console.error(`Invalid timezone "${timeZone}", falling back to ISO: ${err.message}`);
|
|
return d.toISOString();
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
formatDateTime
|
|
};
|