Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

Signed-off-by: rick <technoweenie@gmail.com>
  • Loading branch information...
commit 2ee5eb77b26e03799ebcbfe5d38a74c0e0fd6f2f 1 parent 36c4353
@whatcould whatcould authored committed
View
3  lib/active_reload/relative_time_helpers.rb
@@ -11,6 +11,7 @@ module RelativeTimeHelpers
:tomorrow => 'tomorrow',
:initial_format => '%b %d',
:last_week_format => '%A',
+ :time_format => '%l:%M %p',
:year_format => ', %Y'
}
@@ -18,7 +19,7 @@ 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)
View
7 test/relative_time_helpers_test.rb
@@ -8,6 +8,7 @@ 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
@@ -15,7 +16,11 @@ def teardown
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
Please sign in to comment.
Something went wrong with that request. Please try again.