cheahjs / palworld-save-tools

Tools for converting Palworld .sav files to JSON and back
MIT License
776 stars 66 forks source link

Timestamp is u64 how to find the real date? #127

Closed cyrbil closed 5 months ago

cyrbil commented 5 months ago

Common issues before reporting

Have you modified the save files No

Have you tried the latest release Yes

Describe the bug Timestamp is u64 how to find the real date? It's too small to just be a simple timestamp as it gives me a date in the 90s.

>>> datetime.datetime.fromtimestamp(638424028570890000 / 10**9).isoformat()
'1990-03-26T04:00:28.570890'

Has anyone tried to convert the value?

Copy of .sav or .sav.json files

Example:

"Timestamp": {
      "struct_type": "DateTime",
      "struct_id": "00000000-0000-0000-0000-000000000000",
      "id": null,
      "value": 638424028570890000,
      "type": "StructProperty"
    },
cyrbil commented 5 months ago

The timestamp is from C# binary representation which starts at 0001-01-01T00:00:00Z and is represented as 100 nanoseconds where the Python timestamp starts at 1970-01-01T00:00:00Z and is in seconds.

def convert_timestamp(ts):
    unix_ts_offset = 621355968000000000  # 100th of nanoseconds from 0001-01-01T00:00:00Z to 1970-01-01T00:00:00Z
    return datetime.datetime.fromtimestamp((ts - unix_ts_offset ) / 10000000)

convert_timestamp(638424028570890000) 
# gives 2024-02-01 16:47:37.089000