Permalink
Browse files

today, show actual time; yesterday, show "yesterday" etc

Signed-off-by: rick <technoweenie@gmail.com>
  • Loading branch information...
1 parent 36c4353 commit 2ee5eb77b26e03799ebcbfe5d38a74c0e0fd6f2f @whatcould whatcould committed with Nov 18, 2008
Showing with 8 additions and 2 deletions.
  1. +2 −1 lib/active_reload/relative_time_helpers.rb
  2. +6 −1 test/relative_time_helpers_test.rb
@@ -11,14 +11,15 @@ module RelativeTimeHelpers
:tomorrow => 'tomorrow',
:initial_format => '%b %d',
:last_week_format => '%A',
+ :time_format => '%l:%M %p',
:year_format => ', %Y'
}
def relative_date(time, in_past = false)
date = time.to_date
today = time_class.now.to_date
if date == today
- time_output[:today]
+ time.respond_to?(:min) ? time.strftime(time_output[:time_format]) : time_output[:today]
elsif date == (today - 1)
time_output[:yesterday]
elsif date == (today + 1)
@@ -8,14 +8,19 @@ def setup
@current_time_class = ActiveReload::RelativeTimeHelpers.time_class
ActiveReload::RelativeTimeHelpers.time_class = Time
Time.stubs(:now).returns(Time.utc(2007, 6, 1, 11))
+ Date.stubs(:now).returns(Date.new(2007, 6, 1))
end
def teardown
ActiveReload::RelativeTimeHelpers.time_class = @current_time_class
end
def test_should_show_today
- assert_equal 'today', relative_date(Time.now.utc)
+ assert_equal 'today', relative_date(Date.now)
+ end
+
+ def test_should_show_time_today
+ assert_equal '11:00 AM', relative_date(Time.now.utc)
end
def test_should_show_yesterday

0 comments on commit 2ee5eb7

Please sign in to comment.