# Bug in Time.parse?

**URL:** <https://www.ruby-forum.com/t/bug-in-time-parse/91568>\
**Category:** Ruby\
**Created:** [April 10, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/bug-in-time-parse/91568 "2007-04-10T16:06:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 10, 2007, 4:06pm UTC](https://www.ruby-forum.com/t/bug-in-time-parse/91568/1 "2007-04-10T16:06:16Z")

</div>

Hi,

I stumbled across some odd behavior when using Time.parse. Apparently  
\<=\> fails on Time objects generated by Time.parse when the compared  
objects are equal. The parsed object appears smaller to \<=\>.

> VERSION  
> =\> “1.8.4”

require ‘time’  
=\> true

> t = Time.now  
> =\> Tue Apr 10 15:42:40 CEST 2007  
> tt = t.dup  
> =\> Tue Apr 10 15:42:40 CEST 2007  
> t == tt  
> =\> true  
> tt =Time.parse(t.to\_s)  
> =\> Tue Apr 10 15:42:40 CEST 2007  
> t == tt  
> =\> false  
> tt \< t  
> =\> true  
> t.to\_s  
> =\> “Tue Apr 10 15:42:40 CEST 2007”  
> t == Time.parse(“Tue Apr 10 15:42:40 CEST 2007”)  
> =\> false  
> t \> Time.parse(“Tue Apr 10 15:42:40 CEST 2007”)  
> =\> true  
> t \> Time.parse(“Tue Apr 10 15:42:41 CEST 2007”)  
> =\> false  
> t \< Time.parse(“Tue Apr 10 15:42:41 CEST 2007”)  
> =\> true  
> t \> Time.parse(“Tue Apr 10 15:42:39 CEST 2007”)  
> =\> true

As Time#inspect is overridden i don’t know how to examine if there are  
any differences between the objects created with parse and dup  
respectively…

Is this known? Is it a bug or do I misunderstand something?

I could not find it mentioned in the bugtracker or on the 'net with  
google.

- Siemen B.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 10, 2007, 4:25pm UTC](https://www.ruby-forum.com/t/bug-in-time-parse/91568/2 "2007-04-10T16:25:18Z")

</div>

On 10.04.2007 16:03, removed\_email\_address@domain.invalid wrote:

> =\> true
> 
> > tt \< t  
> > =\> true  
> > t \> Time.parse(“Tue Apr 10 15:42:39 CEST 2007”)  
> > =\> true
> 
> As Time#inspect is overridden i don’t know how to examine if there are  
> any differences between the objects created with parse and dup  
> respectively…
> 
> Is this known? Is it a bug or do I misunderstand something?

This is not a bug. Time.parse can only parse what it gets to see:

> > require ‘time’  
> > =\> true
> 
> > t=Time.now  
> > =\> Tue Apr 10 16:19:27 +0200 2007
> 
> > t.to\_s  
> > =\> “Tue Apr 10 16:19:27 +0200 2007”
> 
> > tt=Time.parse(t.to\_s)  
> > =\> Tue Apr 10 16:19:27 +0200 2007
> 
> > t.to\_s  
> > =\> “Tue Apr 10 16:19:27 +0200 2007”
> 
> > tt.to\_s  
> > =\> “Tue Apr 10 16:19:27 +0200 2007”
> 
> > tt - t  
> > =\> -0.125357
> 
> > t.to\_f  
> > =\> 1176214767.12536
> 
> > tt.to\_f  
> > =\> 1176214767.0

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 10, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/bug-in-time-parse/91568/3 "2007-04-10T16:29:18Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I stumbled across some odd behavior when using Time.parse. Apparently  
> \<=\> fails on Time objects generated by Time.parse when the compared  
> objects are equal. The parsed object appears smaller to \<=\>.
> 
> Is this known? Is it a bug or do I misunderstand something?
> 
> I could not find it mentioned in the bugtracker or on the 'net with  
> google.

[http://www.ruby-doc.org/core/classes/Time.html#M000249](http://www.ruby-doc.org/core/classes/Time.html#M000249)

Looking into the Ruby documentation, I see a note regarding resolution:  
Time.now may be off by fractions of seconds, depending on your computer.

For example, \*nixes calculate the time using January 1st 1970 as  
starting point, and calculate the seconds passed since then (IIRC).  
Windows probably uses the CMOS clock on the motherboard, which can be  
off by a few seconds (or there’s latency when using NTP to sync times  
with a clock…)

AFAIK, this is a similar debate to random vs pseudo-random 😉

–  
Phillip “CynicalRyan” Gawlowski  
[http://cynicalryan.110mb.com/](http://cynicalryan.110mb.com/)

Rule of Open-Source Programming #15:

If you like it, let the author know. If you hate it, let the author  
know why.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 10, 2007, 4:36pm UTC](https://www.ruby-forum.com/t/bug-in-time-parse/91568/4 "2007-04-10T16:36:19Z")

</div>

> This is not a bug. Time.parse can only parse what it gets to see:

Of course! Thanks!

- Siemen
