Skip to content

buildTimeSection should inject current date/time, not just timezone #34422

@adamjdavidson

Description

@adamjdavidson

Problem

buildTimeSection() in the system prompt builder only injects the timezone:

## Current Date & Time
Time zone: UTC

The actual current date and time are not included. This means agents have no reliable way to know the current date without calling a tool first, leading to off-by-one-day errors when reasoning about time-sensitive content (scheduling, email triage, etc.).

Suggested Fix

Use Intl.DateTimeFormat to render the current datetime in the user's timezone:

function buildTimeSection(params) {
    if (!params.userTimezone) return [];
    const now = new Date();
    const formatter = new Intl.DateTimeFormat('en-US', {
        timeZone: params.userTimezone,
        weekday: 'long',
        year: 'numeric',
        month: 'long',
        day: 'numeric',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        hour12: true
    });
    const dateStr = formatter.format(now);
    return [
        '## Current Date & Time',
        `Current date and time: ${dateStr}`,
        `Time zone: ${params.userTimezone}`,
        ''
    ];
}

This affects reply-*.js, subagent-registry-*.js, pi-embedded-*.js, and plugin-sdk/reply-*.js.

Workaround

We've patched this locally on our instance and confirmed it works. Happy to submit a PR if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions