Show timezone abbreviation in system prompt#4901
Show timezone abbreviation in system prompt#4901dpalfox wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Adds getTimezoneAbbreviation() to convert IANA timezone names (e.g. America/New_York) to friendly abbreviations (e.g. EST). The system prompt now shows: Time zone: America/New_York (EST) instead of just: Time zone: America/New_York
| export function getTimezoneAbbreviation(timezone: string): string { | ||
| try { | ||
| const formatter = new Intl.DateTimeFormat("en-US", { | ||
| timeZone: timezone, | ||
| timeZoneName: "short", | ||
| }); | ||
| const parts = formatter.formatToParts(new Date()); | ||
| const tzPart = parts.find((p) => p.type === "timeZoneName"); | ||
| return tzPart?.value ?? timezone; | ||
| } catch { | ||
| return timezone; | ||
| } | ||
| } |
There was a problem hiding this comment.
[P2] timeZoneName: "short" may not yield true abbreviations across environments
Intl.DateTimeFormat(..., { timeZoneName: "short" }) often returns offsets like GMT-5/UTC−05:00 or localized strings (and can vary by Node/ICU build), so getTimezoneAbbreviation() may not reliably produce EST/PST as the PR description implies. If the goal is a stable, friendly label, consider renaming the function (e.g. to getTimezoneShortName) or using timeZoneName: "shortGeneric"/"shortOffset" depending on the desired output semantics.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/date-time.ts
Line: 26:38
Comment:
[P2] `timeZoneName: "short"` may not yield true abbreviations across environments
`Intl.DateTimeFormat(..., { timeZoneName: "short" })` often returns offsets like `GMT-5`/`UTC−05:00` or localized strings (and can vary by Node/ICU build), so `getTimezoneAbbreviation()` may not reliably produce `EST/PST` as the PR description implies. If the goal is a stable, friendly label, consider renaming the function (e.g. to `getTimezoneShortName`) or using `timeZoneName: "shortGeneric"`/`"shortOffset"` depending on the desired output semantics.
How can I resolve this? If you propose a fix, please make it concise.| function buildTimeSection(params: { userTimezone?: string }) { | ||
| if (!params.userTimezone) return []; | ||
| return ["## Current Date & Time", `Time zone: ${params.userTimezone}`, ""]; | ||
| const abbrev = getTimezoneAbbreviation(params.userTimezone); | ||
| // Show both IANA name and abbreviation if they differ | ||
| const tzDisplay = | ||
| abbrev !== params.userTimezone ? `${params.userTimezone} (${abbrev})` : params.userTimezone; | ||
| return ["## Current Date & Time", `Time zone: ${tzDisplay}`, ""]; | ||
| } |
There was a problem hiding this comment.
[P3] Consider trimming before comparing to avoid duplicate display from whitespace/casing
buildTimeSection() compares abbrev !== params.userTimezone, but params.userTimezone can include whitespace (it’s trimmed later in buildAgentSystemPrompt). If buildTimeSection is ever reused elsewhere, you could end up with America/New_York (America/New_York)-style output due purely to whitespace. Passing the already-trimmed userTimezone down (or trimming locally before both the call and the comparison) keeps the display stable.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/system-prompt.ts
Line: 52:59
Comment:
[P3] Consider trimming before comparing to avoid duplicate display from whitespace/casing
`buildTimeSection()` compares `abbrev !== params.userTimezone`, but `params.userTimezone` can include whitespace (it’s trimmed later in `buildAgentSystemPrompt`). If `buildTimeSection` is ever reused elsewhere, you could end up with `America/New_York (America/New_York)`-style output due purely to whitespace. Passing the already-trimmed `userTimezone` down (or trimming locally before both the call and the comparison) keeps the display stable.
How can I resolve this? If you propose a fix, please make it concise.bfc1ccb to
f92900f
Compare
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Still relevant — this is a small quality-of-life improvement that helps the AI reason about timezones more naturally. Happy to rebase if needed. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Adds \getTimezoneAbbreviation()\ to convert IANA timezone names (e.g. \America/New_York) to friendly abbreviations (e.g. \EST).
The system prompt now shows:
\
Time zone: America/New_York (EST)
\
instead of just:
\
Time zone: America/New_York
\\
This makes it easier for the AI to understand and communicate about timezones.
Greptile Overview
Greptile Summary
This PR adds
getTimezoneAbbreviation()insrc/agents/date-time.tsand updatesbuildTimeSection()insrc/agents/system-prompt.tsto display the user’s IANA timezone along with a shortIntl.DateTimeFormat-derived timezone label (e.g.,America/New_York (EST)) when they differ.The change integrates into the system prompt construction path by enriching the existing “Current Date & Time” section, without altering other prompt sections or the timezone resolution logic.
Confidence Score: 4/5
Intlreturns for “short” timezone names.Intl.DateTimeFormatAPI with a try/catch fallback. The main risk is thattimeZoneName: "short"does not reliably produce abbreviations likeEST/PSTacross environments/locales and can yield GMT offsets (e.g.,GMT-5) or localized strings, which may reduce the intended benefit but shouldn’t break functionality.(2/5) Greptile learns from your feedback when you react with thumbs up/down!