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:
Misaka_Company
2026-04-13 17:52:50 +08:00
parent 6aa1fc29e5
commit 420f811488
3 changed files with 9 additions and 8 deletions

View File

@@ -27,7 +27,7 @@ export class MySqlDialect implements SqlDialect {
}
currentTimestamp(): string {
return 'NOW()'
return 'UTC_TIMESTAMP()'
}
upsert(params: {

View File

@@ -26,7 +26,7 @@ export class SqlServerDialect implements SqlDialect {
}
currentTimestamp(): string {
return 'GETDATE()'
return 'SYSUTCDATETIME()'
}
upsert(params: {

View File

@@ -88,12 +88,13 @@ const formatDateTime = (dateStr: string | Date | null | undefined): string => {
return String(dateStr)
}
const year = date.getUTCFullYear()
const month = String(date.getUTCMonth() + 1).padStart(2, '0')
const day = String(date.getUTCDate()).padStart(2, '0')
const hours = String(date.getUTCHours()).padStart(2, '0')
const minutes = String(date.getUTCMinutes()).padStart(2, '0')
const seconds = String(date.getUTCSeconds()).padStart(2, '0')
// Use local time instead of UTC for display
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
const hours = String(date.getHours()).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}`
}