Skip to content
This repository was archived by the owner on May 20, 2026. It is now read-only.

feat: configurable time, weekday, and timezone in date context#5104

Open
eodus wants to merge 2 commits into
microsoft:mainfrom
eodus:custom/time-injection
Open

feat: configurable time, weekday, and timezone in date context#5104
eodus wants to merge 2 commits into
microsoft:mainfrom
eodus:custom/time-injection

Conversation

@eodus
Copy link
Copy Markdown
Member

@eodus eodus commented May 4, 2026

Summary

Add three opt-in settings to include time, weekday, and timezone information in the date context provided to language models in agent mode.

Motivation

Time awareness is useful for models that assist with scheduling, deadlines, session duration tracking, and context-dependent responses. Currently only the date is provided. These settings allow users who want richer temporal context to opt in without affecting anyone else.

Settings

Setting Type Default Description
chat.advanced.context.timeFormat 'off' | '24h' | '12h' 'off' Include current time in 24-hour or 12-hour format
chat.advanced.context.showWeekday boolean false Include day of the week
chat.advanced.context.showTimezone boolean false Include timezone offset (e.g., GMT+2)

Examples

  • Default (all off): The current date is May 4, 2026.
  • All enabled (24h): The current date is Monday, May 4, 2026. The current time is 17:09:32 GMT+2.
  • All enabled (12h): The current date is Monday, May 4, 2026. The current time is 05:09:32 PM GMT+2.

Implementation

  • Shared utility: formatCurrentDateContext() in src/extension/prompts/common/currentDateContext.ts — used by the agent prompt path (CurrentDatePrompt in agentPrompt.tsx).
  • All locales pinned to en-US for deterministic output regardless of system locale. This also fixes a pre-existing issue where the date portion used the system locale, producing mixed-language output (e.g., The current date is 3. Mai 2026. on German systems).
  • Timezone uses Intl.DateTimeFormat.formatToParts() with timeZoneName: 'shortOffset' for consistent GMT±N format across all regions.
  • Prefix cache impact: none. The agent path renders CurrentDatePrompt inside <UserMessage> (via AgentUserMessage), which changes every turn regardless — so even second-level precision has zero additional cache cost. The panel path (which renders the date inside <SystemMessage>) is intentionally untouched to avoid increasing its existing daily cache invalidation to per-second.

Tests

16 unit tests with full determinism (vi.useFakeTimers + vi.stubEnv('TZ', ...) + vi.setSystemTime):

  • All setting combinations (default, 24h, 12h, weekday, timezone, all-parts)
  • 6 timezone blocks: UTC, US Eastern (EDT), Tokyo (GMT+9), US Pacific winter (PST), India (GMT+5:30 — non-whole-hour offset), Tokyo date rollover (UTC night → local next day)
  • Garbage input graceful degradation

Backward compatibility

  • All settings default to off — no behavioral change for existing users.
  • Date formatting is now pinned to en-US (previously used system locale). This is intentional: the surrounding prompt text is English, so mixed-language dates were arguably a bug.

Alexander Shlemov Codespace added 2 commits May 3, 2026 23:57
Add three new settings under chat.advanced.context.*:
- timeFormat: 'off' (default), '24h', or '12h' — controls time display
- showWeekday: include day of week (default: false)
- showTimezone: include timezone offset (default: false)

All settings are opt-in; default behavior is unchanged (date only).

Examples:
- Default: 'The current date is May 3, 2026.'
- All enabled (24h): 'The current date is Sunday, May 3, 2026. The current time is 23:06:32 GMT+2.'
- All enabled (12h): 'The current date is Sunday, May 3, 2026. The current time is 11:06:32 PM GMT+2.'

The date/time formatting logic is extracted into a shared
formatCurrentDateContext() function used by the agent prompt path.
All locales pinned to en-US for deterministic output. Unit tests included.
…ver)

- India (GMT+5:30): verifies non-whole-hour offset formatting
- Tokyo date rollover (UTC 23:30 → local next day): verifies
  weekday and date are correct when timezone shifts the calendar day
Copilot AI review requested due to automatic review settings May 4, 2026 15:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds opt-in configuration to enrich the “current date” prompt context in agent mode by optionally including time, weekday, and timezone offset, via a shared formatter utility used by the agent prompt.

Changes:

  • Added three new advanced settings (timeFormat, showWeekday, showTimezone) and surfaced them in package.json + package.nls.json.
  • Introduced formatCurrentDateContext() to produce deterministic, English (en-US) date/time strings and wired it into the agent prompt (CurrentDatePrompt).
  • Added a new Vitest suite covering combinations and multiple timezone scenarios.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/platform/configuration/common/configurationService.ts Registers new advanced config keys for time/weekday/timezone context.
src/extension/prompts/node/agent/agentPrompt.tsx Switches agent “current date” rendering to use the shared formatter + new config.
src/extension/prompts/common/currentDateContext.ts Adds the shared date/time context formatter (en-US deterministic formatting, optional additions).
src/extension/prompts/common/test/currentDateContext.spec.ts Adds unit tests for formatting across setting combinations and timezones.
package.nls.json Adds localized setting descriptions for the new options.
package.json Adds the new contributed settings schema (enum + booleans).

Comment on lines +23 to +27
beforeEach(() => {
vi.useFakeTimers();
vi.stubEnv('TZ', 'UTC');
// Monday, June 15, 2026 14:30:45 UTC
vi.setSystemTime(new Date('2026-06-15T14:30:45.000Z'));
@alexdima
Copy link
Copy Markdown
Member

Thanks for the contribution! This repository has been archived because the project has moved into the main VS Code repository.

Could you please reopen/recreate this PR against:
https://github.com/microsoft/vscode/tree/main/extensions/copilot

We’ll continue reviewing contributions there. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants