fix(timezone): use UTC for database storage and local time for UI display
Backend changes: - SQL Server dialect: GETDATE() → SYSUTCDATETIME() - MySQL dialect: NOW() → UTC_TIMESTAMP() - Ensures OperationTime and EndTime use consistent UTC timezone Frontend changes: - formatDateTime: display UTC timestamps in user's local timezone - Uses getFullYear/getMonth/getDate/getHours (local) instead of UTC methods Data migration: - Executed migration script to fix historical OperationTime records - All existing records now have correct UTC timestamps - Execution duration now accurate (minutes, not hours) Impact: - New executions store UTC timestamps correctly - UI displays times in user's local timezone (UTC+8 for CN users) - Historical data corrected via migration - Time difference between OperationTime and EndTime now accurate
This commit is contained in:
@@ -27,7 +27,7 @@ export class MySqlDialect implements SqlDialect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentTimestamp(): string {
|
currentTimestamp(): string {
|
||||||
return 'NOW()'
|
return 'UTC_TIMESTAMP()'
|
||||||
}
|
}
|
||||||
|
|
||||||
upsert(params: {
|
upsert(params: {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class SqlServerDialect implements SqlDialect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentTimestamp(): string {
|
currentTimestamp(): string {
|
||||||
return 'GETDATE()'
|
return 'SYSUTCDATETIME()'
|
||||||
}
|
}
|
||||||
|
|
||||||
upsert(params: {
|
upsert(params: {
|
||||||
|
|||||||
@@ -88,12 +88,13 @@ const formatDateTime = (dateStr: string | Date | null | undefined): string => {
|
|||||||
return String(dateStr)
|
return String(dateStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
const year = date.getUTCFullYear()
|
// Use local time instead of UTC for display
|
||||||
const month = String(date.getUTCMonth() + 1).padStart(2, '0')
|
const year = date.getFullYear()
|
||||||
const day = String(date.getUTCDate()).padStart(2, '0')
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||||
const hours = String(date.getUTCHours()).padStart(2, '0')
|
const day = String(date.getDate()).padStart(2, '0')
|
||||||
const minutes = String(date.getUTCMinutes()).padStart(2, '0')
|
const hours = String(date.getHours()).padStart(2, '0')
|
||||||
const seconds = String(date.getUTCSeconds()).padStart(2, '0')
|
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||||
|
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||||
|
|
||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user