The (pretty much universal) problem with dates and times is that people use "date" and "time" to mean different things. There's a java library called joda that provides a really clean vocabulary around this.<br>
<br>An <i>instant</i> is a point in time. You shouldn't be able to ask for two instants and get the same answer however close together you ask. (There's probably something philosophical in there somewhere.)<br><br>
A <i>datetime</i> is a type of instant with millisecond precision that can tell you the time and date it represents, based on a timezone. The Ruby Time class represents an instant but renders itself as a datetime, hence the confusion (it has microsecond precision that you only get to see if you know to ask).<br>
<br>A <i>local date</i> is a day when something happens, say 4th May 2008. My understanding of 4th May in the UK is bounded by different start and end instants than, say, David's in the US, because of timezones, but we both know what we "mean" by 4th May 2008.<br>
<br>A <i>duration</i> is a length of time in milliseconds.<br><br>Given these atoms you can have fairly sensible conversations about times and dates. For instance, in the current example I might do this:<br><br><span style="font-family: courier new,monospace;">Instant = Time # make it clear what I'm using it for<br>
...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Instant.new == Instant.new # false, but now I know why</span><br><br>Cheers,<br>Dan<br><br>ps. and as Aslak says, make sure you control "time" in your examples - either by stubbing Time or by injecting your own Clock abstraction.<br>
<br><div class="gmail_quote">2008/5/5 Jarkko Laine <<a href="mailto:jarkko@jlaine.net">jarkko@jlaine.net</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On 5.5.2008, at 11.02, Pat Maddox wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Yes, that was my first idea as well. The Time class is a little<br>
fucked up in that<br>
<br>
< a, b = Time.now, Time.now<br>
< a == b #=> false<br>
</blockquote>
<br></div>
That's definitely a gotcha but I wouldn't necessarily say it's fucked up. It's just that Time#now returns the current (exact) point of time, so running it successively on the same machine will by definition return different values (by a tiny margin but still).<br>
<br>
The fact that the textual representation of the two look exactly the same certainly makes it confusing the first time get bitten by it, though :-)<br>
<br>
Cheers,<br>
//jarkko<br><font color="#888888">
<br>
--<br>
Jarkko Laine<br>
<a href="http://jlaine.net" target="_blank">http://jlaine.net</a><br>
<a href="http://dotherightthing.com" target="_blank">http://dotherightthing.com</a><br>
<a href="http://www.railsecommerce.com" target="_blank">http://www.railsecommerce.com</a><br>
<a href="http://odesign.fi" target="_blank">http://odesign.fi</a><br>
<br>
<br>
</font><br>_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br>