Skip to content

Conversation

lmuhlha
Copy link

@lmuhlha lmuhlha commented Oct 8, 2025

The Problem

grafana/grafana#106452

When using ${__to:date:M} or similar date formatting on __from/__to, the value was evaluated in the client's local timezone instead of respecting the dashboard's configured timezone (e.g., UTC). This breaks Prometheus queries like month() == bool vector(${__to:date:M}) across different timezones.

The Fix
Made changes to 3 files:

  1. formatRegistry.ts - Added timezone support to the interface and formatter
  • Added getTimeZone?(): TimeZone method to the FormatVariable interface
  • Imported dateTimeForTimeZone from @grafana/data
  • Updated the Date formatter to use dateTimeForTimeZone(timeZone, nrValue) when a timezone is available
  • Falls back to the old behavior (dateTime(nrValue)) when no timezone is provided
  1. timeMacros.ts - Implemented timezone retrieval for time macros
  • Added getTimeZone() method to TimeFromAndToMacro class
  • This method retrieves the timezone from the scene's time range using getTimeRange(this._sceneObject).getTimeZone()
  1. timeMacros.test.ts - Added tests
  • Test 1: Verifies UTC timezone is respected
  • Test 2: Verifies custom timezones (America/New_York) are respected
  • Test 3: Verifies the specific bug case - cross-timezone month boundaries (March 31st 23:00 UTC appears as April 1st in Stockholm UTC+2)

@lmuhlha lmuhlha changed the title Added timezone support to the interface and formatter Added timezone support to the FormatVariable interface and formatter Oct 8, 2025
@lmuhlha lmuhlha changed the title Added timezone support to the FormatVariable interface and formatter Added timezone support to the FormatVariable interface and Date formatter Oct 8, 2025
@CLAassistant
Copy link

CLAassistant commented Oct 9, 2025

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants