Created
May 15, 2023 18:09
-
-
Save sh4dowb/2c3e952bd2f180ae5f24fc5602b98d5a to your computer and use it in GitHub Desktop.
decode/unmarshal Ruby Date in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, timedelta | |
from rubymarshal.classes import UsrMarshal | |
from rubymarshal.reader import loads | |
data = b'\x04\x08U:\tDate[\x0bi\x00i\x03\xe5R%i\x00i\x00i\x00f\x0c2299161' | |
# 1984-12-18 | |
data = loads(data) | |
if isinstance(data, UsrMarshal): | |
# data._private_data[1] is days since Julian Day (November 24, 4714 BC) | |
data = (date(1900, 1, 1) + timedelta(days=data._private_data[1] - 2415021)).strftime('%Y-%m-%d') | |
print(str(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment