src / utils / DateTimeFormatter.ts
/**
* Formats the user's current local date, time, and timezone into a natural-language context message.
* Evaluated fresh from the operating system on every prompt preprocessing turn.
*
* Example output:
* "User's current date is Sunday, July 26, 2026, 9:19 PM IST (Asia/Kolkata). Use this as the present and not your training cutoff date."
*
* @param now Optional Date instance for testing (defaults to new Date()).
*/
export function formatCurrentDateTimeContext(now: Date = new Date()): string {
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
const dateStr = now.toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
const timeStr = now.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
timeZoneName: "short",
});
return `User's real-time date is ${dateStr}, ${timeStr} (${timeZone}). Treat this as the current date and time when interpreting relative expressions such as "today", "yesterday", "tomorrow", "this week", and "latest".`;
}
src / utils / DateTimeFormatter.ts
/**
* Formats the user's current local date, time, and timezone into a natural-language context message.
* Evaluated fresh from the operating system on every prompt preprocessing turn.
*
* Example output:
* "User's current date is Sunday, July 26, 2026, 9:19 PM IST (Asia/Kolkata). Use this as the present and not your training cutoff date."
*
* @param now Optional Date instance for testing (defaults to new Date()).
*/
export function formatCurrentDateTimeContext(now: Date = new Date()): string {
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
const dateStr = now.toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
const timeStr = now.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "2-digit",
hour12: true,
timeZoneName: "short",
});
return `User's real-time date is ${dateStr}, ${timeStr} (${timeZone}). Treat this as the current date and time when interpreting relative expressions such as "today", "yesterday", "tomorrow", "this week", and "latest".`;
}