# Marshal format for Time

**URL:** <https://www.ruby-forum.com/t/marshal-format-for-time/148669>\
**Category:** IronRuby\
**Created:** [September 16, 2008, 1:53am UTC](https://www.ruby-forum.com/t/marshal-format-for-time/148669 "2008-09-16T01:53:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![curthibbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ac91a4/32.png) [@curthibbs](https://www.ruby-forum.com/u/curthibbs)\
**Post date:** [September 16, 2008, 1:53am UTC](https://www.ruby-forum.com/t/marshal-format-for-time/148669/1 "2008-09-16T01:53:28Z")

</div>

Can someone help me by summarizing the Marshal format for Time in Ruby  
1.8.6?

Here’s what I’ve worked out:

1. 

```
 The time is always based on the UNIX epoch

```

2. 

```
 When the fourth byte is less than 128, it implies some kind of 

```

older format. This format is read but not written

a. The first four bytes _seem_ to represent the standard UNIX time  
value

1. 

```
 When the fourth byte is equal to 128, it implies the "1.8.6 

```

format". The implications are

a. The first byte represents number of hours

b. The second byte represents number of 8-day blocks

c. The third byte represents 4-year blocks

d. The eighth byte represents 4-second blocks

e. Bytes 5-7 represent microseconds as a 3-byte little-endian value

1. 

```
 When the fourth byte is greater than 128, or if the byte count 

```

is not 8, an error is raised

What I’d like to understand is

a) How this works with leap years

b) What kinds of legacy formats are supported, as I seem to be  
getting inconsistent answers when the fourth byte is less than 128

I’d appreciate any assistance, as this format appears to be totally  
undocumented. Please don’t post any actual source code, as I would be  
required by our lawyers to “do an Oedipus” on my eyeballs if I so much  
as glance at it :).

Thanks,  
-Curt

---

<div class="post-metadata">

**Author:** ![curthibbs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ac91a4/32.png) [@curthibbs](https://www.ruby-forum.com/u/curthibbs)\
**Post date:** [September 17, 2008, 12:27am UTC](https://www.ruby-forum.com/t/marshal-format-for-time/148669/2 "2008-09-17T00:27:22Z")

</div>

In case anyone was wondering, here’s a partial decoding:

dword 1, little-endian  
bits 0-4: Hour  
bits 5-9: Day, 1=1st  
bits 10-13: Month, 0=January  
bits 14-29: Year, 0=1900  
bit 30: 0=Local, 1=Utc. 1.8.6 always writes 0 here  
bit 31: 1 to indicate this format

dword 2, little-endian  
bits 0-19: Microseconds  
bits 20-25: Seconds  
bits 26-31: Minutes

From: removed\_email\_address@domain.invalid  
[[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf Of Curt  
Hagenlocher  
Sent: Montag, 15. September 2008 16:52  
To: removed\_email\_address@domain.invalid  
Subject: [Ironruby-core] Marshal format for Time

Can someone help me by summarizing the Marshal format for Time in Ruby  
1.8.6?

Here’s what I’ve worked out:

1. 

```
 The time is always based on the UNIX epoch

```

2. 

```
 When the fourth byte is less than 128, it implies some kind of 

```

older format. This format is read but not written

a. The first four bytes _seem_ to represent the standard UNIX time  
value

1. 

```
 When the fourth byte is equal to 128, it implies the "1.8.6 

```

format". The implications are

a. The first byte represents number of hours

b. The second byte represents number of 8-day blocks

c. The third byte represents 4-year blocks

d. The eighth byte represents 4-second blocks

e. Bytes 5-7 represent microseconds as a 3-byte little-endian value

1. 

```
 When the fourth byte is greater than 128, or if the byte count 

```

is not 8, an error is raised

What I’d like to understand is

a) How this works with leap years

b) What kinds of legacy formats are supported, as I seem to be  
getting inconsistent answers when the fourth byte is less than 128

I’d appreciate any assistance, as this format appears to be totally  
undocumented. Please don’t post any actual source code, as I would be  
required by our lawyers to “do an Oedipus” on my eyeballs if I so much  
as glance at it :).

Thanks,  
-Curt
