That's definetely the most interesting article on timestamps I've read. I've never heard anyone choosing which timestamp they'd take on a desert island with them
.
Just a couple of suggestions. First, a lot the magic you're doing with strftime can be done more easily if you use DateTime's strftime (which is for some reason a lot more fully featured):
time.to_datetime.strftime "%a, %d %b %Y, %l:%M%P"
Also, it seems odd to reinvent the wheel and emulate the behaviour of distance_of_time_in_words, why not just call it directly (it would mean much shorter code):
def time_ago_or_time_stamp(from_time, to_time = Time.now, include_seconds = true, detail = false)
[from_time, to_time].each {|t| t = t.to_time if t.respond_to?(:to_time)}
if (((to_time - from_time).abs)/60).round > 2880 && detail
return timestamp(from_time)
else
return distance_of_time_in_words(from_time, to_time, include_seconds)
end
end
Alex
Last edited by alexpt (2007-07-29 12:30:07)