/** * Timezone-aware date formatting utilities for Outlook MCP Server. * * All user-visible timestamps are formatted in the configured timezone * (MS_TIMEZONE env var, default America/New_York) 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 };