Skip to content

Commit c91df3c

Browse files
allancascanteAllan Cascante
andauthored
Query Profiler - Display date time in current time zone (#21454)
* Change to display date time in current timezone for the machine * test fix --------- Co-authored-by: Allan Cascante <acascante@microsoft.com>
1 parent 3f0320c commit c91df3c

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

extensions/mssql/src/profiler/profilerConfigService.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,21 @@ export class ProfilerConfigService {
281281
}
282282

283283
/**
284-
* Format a timestamp for display.
285-
* Converts timestamp to ISO 8601 format: "YYYY-MM-DD HH:mm:ss.sss"
284+
* Format a timestamp for display in the local machine timezone.
285+
* Format: "YYYY-MM-DD HH:mm:ss.SSS" (matching SSMS display)
286286
* Example output: "2026-01-29 14:30:45.123"
287287
*/
288288
private formatTimestamp(timestamp: number): string {
289289
try {
290290
const date = new Date(timestamp);
291-
return date.toISOString().replace("T", " ").replace("Z", "");
291+
const year = date.getFullYear();
292+
const month = String(date.getMonth() + 1).padStart(2, "0");
293+
const day = String(date.getDate()).padStart(2, "0");
294+
const hours = String(date.getHours()).padStart(2, "0");
295+
const minutes = String(date.getMinutes()).padStart(2, "0");
296+
const seconds = String(date.getSeconds()).padStart(2, "0");
297+
const ms = String(date.getMilliseconds()).padStart(3, "0");
298+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${ms}`;
292299
} catch {
293300
return String(timestamp);
294301
}

extensions/mssql/test/unit/profiler/profilerConfigService.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,14 @@ suite("ProfilerConfigService Tests", () => {
305305
const event = createTestEvent({ timestamp: testTimestamp });
306306
const viewRow = configService.convertEventToViewRow(event, view);
307307

308-
// Should be formatted as ISO string without T and Z
309-
expect(viewRow.StartTime).to.include("2024-01-15");
310-
expect(viewRow.StartTime).to.include("10:30:00");
308+
// Should be formatted in local timezone as "YYYY-MM-DD HH:mm:ss.SSS"
309+
const localYear = String(testTimestamp.getFullYear());
310+
const localMonth = String(testTimestamp.getMonth() + 1).padStart(2, "0");
311+
const localDay = String(testTimestamp.getDate()).padStart(2, "0");
312+
const localHours = String(testTimestamp.getHours()).padStart(2, "0");
313+
const localMinutes = String(testTimestamp.getMinutes()).padStart(2, "0");
314+
expect(viewRow.StartTime).to.include(`${localYear}-${localMonth}-${localDay}`);
315+
expect(viewRow.StartTime).to.include(`${localHours}:${localMinutes}:00`);
311316
});
312317
});
313318

@@ -778,7 +783,7 @@ suite("ProfilerConfigService Tests", () => {
778783
});
779784
const typedRow = configService.convertEventToTypedRow(event, view);
780785

781-
// Timestamp is formatted as "2024-06-15 10:30:00.000" by getColumnValue,
786+
// Timestamp is formatted in local timezone by getColumnValue,
782787
// then coerced back to a Date by coerceToColumnType
783788
expect(typedRow.StartTime).to.be.an.instanceOf(Date);
784789
const startTime = typedRow.StartTime as Date;

0 commit comments

Comments
 (0)