suriyun-production / mmorpg-kit-docs

This is document for MMORPG KIT project (https://www.assetstore.unity3d.com/#!/content/110188?aid=1100lGeN)
https://suriyun-production.github.io/mmorpg-kit-docs
49 stars 10 forks source link

LastUpdated read as local instead of UTC. Latest version. #2618

Open codecustard opened 1 week ago

codecustard commented 1 week ago

Describe the bug LastUpdated seems to read as local when expected behaviour is to read it as UTC.

To Reproduce Steps to reproduce the behavior:

  1. Add a trigger to update 'lastUpdated' (Tested SQLITE)

    // Create the trigger to automatically update the 'updateAt' column on updates
    ExecuteNonQuery(@"CREATE TRIGGER IF NOT EXISTS update_characters_updateAt
                AFTER UPDATE ON characters
                FOR EACH ROW
                BEGIN
                    UPDATE characters
                    SET updateAt = CURRENT_TIMESTAMP
                    WHERE id = OLD.id;
                END;"
            );
  2. Retrieve from database:

    PlayerCharacterData characterData = await GetCharacterWithUserIdValidation(request.CharacterId, request.UserId);
    
            if (characterData != null)
            {
                long lastOnline = characterData.LastUpdate;
                long currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                long elapsedTime = currentTime - lastOnline;
    
                if (writeAddonLogOfflineRewards)
                {
                    // Convert Unix timestamps to DateTimeOffset
                    DateTimeOffset lastOnlineTime = DateTimeOffset.FromUnixTimeSeconds(lastOnline);
                    DateTimeOffset currentDateTime = DateTimeOffset.FromUnixTimeSeconds(currentTime);
    
                    Debug.Log($"[DEVEXT] [{name}] - {characterData.CharacterName}");
                    Debug.Log($"[DEVEXT] [{name}] - Last Online: {lastOnline} (Unix Timestamp) / {lastOnlineTime}");
                    Debug.Log($"[DEVEXT] [{name}] - Current Time: {currentTime} (Unix Timestamp) / {currentDateTime}");
                    Debug.Log($"[DEVEXT] [{name}] - Offline Time: {elapsedTime} seconds");
                }
            }
  3. Notice invalid date/time.

  4. See error

Expected behavior image

Wrong behavior Screenshots image image

Desktop (please complete the following information):

Solution Specify kind before casting. image Kind is unspecified so the cast treats the date wrong.