Skip to content

Instantly share code, notes, and snippets.

@sh4dowb
Created May 15, 2023 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4dowb/2c3e952bd2f180ae5f24fc5602b98d5a to your computer and use it in GitHub Desktop.
Save sh4dowb/2c3e952bd2f180ae5f24fc5602b98d5a to your computer and use it in GitHub Desktop.
decode/unmarshal Ruby Date in python
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