fix: ensure all timestamps use UTC timezone

- Add NowFunc to GORM config for UTC auto-generated timestamps
- Add .UTC() to all time.UnixMilli() calls in trader files
- Add .UTC() to all time.Now() calls in store and api files
- Fix TypeScript unused imports in frontend
This commit is contained in:
tinkle-community
2026-01-04 20:03:56 +08:00
parent 50923f6a2e
commit 5c9e134e99
25 changed files with 96 additions and 85 deletions
+2 -2
View File
@@ -149,7 +149,7 @@ func (s *AIModelStore) Update(userID, id string, enabled bool, apiKey, customAPI
"enabled": enabled,
"custom_api_url": customAPIURL,
"custom_model_name": customModelName,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
}
// If apiKey is not empty, update it (encryption handled by crypto.EncryptedString)
if apiKey != "" {
@@ -167,7 +167,7 @@ func (s *AIModelStore) Update(userID, id string, enabled bool, apiKey, customAPI
"enabled": enabled,
"custom_api_url": customAPIURL,
"custom_model_name": customModelName,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
}
if apiKey != "" {
updates["api_key"] = crypto.EncryptedString(apiKey)
+2 -2
View File
@@ -236,7 +236,7 @@ func (s *ExchangeStore) Update(userID, id string, enabled bool, apiKey, secretKe
"aster_signer": asterSigner,
"lighter_wallet_addr": lighterWalletAddr,
"lighter_api_key_index": lighterApiKeyIndex,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
}
// Only update encrypted fields if not empty
@@ -275,7 +275,7 @@ func (s *ExchangeStore) UpdateAccountName(userID, id, accountName string) error
Where("id = ? AND user_id = ?", id, userID).
Updates(map[string]interface{}{
"account_name": accountName,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
})
if result.Error != nil {
return result.Error
+9
View File
@@ -2,6 +2,7 @@ package store
import (
"fmt"
"time"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
@@ -21,6 +22,10 @@ func DB() *gorm.DB {
func InitGorm(dbPath string) (*gorm.DB, error) {
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
// Use UTC for all auto-generated timestamps (autoCreateTime, autoUpdateTime)
NowFunc: func() time.Time {
return time.Now().UTC()
},
})
if err != nil {
return nil, fmt.Errorf("failed to open SQLite database: %w", err)
@@ -53,6 +58,10 @@ func InitGormPostgres(host string, port int, user, password, dbname, sslmode str
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
// Use UTC for all auto-generated timestamps (autoCreateTime, autoUpdateTime)
NowFunc: func() time.Time {
return time.Now().UTC()
},
})
if err != nil {
return nil, fmt.Errorf("failed to open PostgreSQL database: %w", err)
+2 -2
View File
@@ -69,8 +69,8 @@ func (pb *PositionBuilder) handleOpen(
Status: "OPEN",
Source: "sync",
Fee: fee,
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CreatedAt: time.Now().UTC(),
UpdatedAt: time.Now().UTC(),
}
return pb.positionStore.CreateOpenPosition(position)
}
+1 -1
View File
@@ -328,7 +328,7 @@ func (s *StrategyStore) Update(strategy *Strategy) error {
"config": strategy.Config,
"is_public": strategy.IsPublic,
"config_visible": strategy.ConfigVisible,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
}).Error
}
+1 -1
View File
@@ -123,7 +123,7 @@ func (s *UserStore) UpdateOTPVerified(userID string, verified bool) error {
func (s *UserStore) UpdatePassword(userID, passwordHash string) error {
return s.db.Model(&User{}).Where("id = ?", userID).Updates(map[string]interface{}{
"password_hash": passwordHash,
"updated_at": time.Now(),
"updated_at": time.Now().UTC(),
}).Error
}