The (pretty much universal) problem with dates and times is that people
“date” and “time” to mean different things. There’s a java library
joda that provides a really clean vocabulary around this.
An instant 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.
probably something philosophical in there somewhere.)
A datetime is a type of instant with millisecond precision that can
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
A local date 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.
A duration is a length of time in milliseconds.
Given these atoms you can have fairly sensible conversations about times
dates. For instance, in the current example I might do this:
Instant = Time # make it clear what I’m using it for
Instant.new == Instant.new # false, but now I know why
ps. and as Aslak says, make sure you control “time” in your examples -
either by stubbing Time or by injecting your own Clock abstraction.
2008/5/5 Jarkko L. [email protected]: