Skip to content

Commit

Permalink
removed ordinal formatting (Nov 15, not Nov 15th)
Browse files Browse the repository at this point in the history
Signed-off-by: rick <technoweenie@gmail.com>
  • Loading branch information
whatcould authored and technoweenie committed Feb 4, 2009
1 parent ae74b0f commit ca41279
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions lib/active_reload/relative_time_helpers.rb
Expand Up @@ -25,7 +25,7 @@ def relative_date(time)
else
fmt = time_output[:initial_format].dup
fmt << time_output[:year_format] unless date.year == today.year
time.strftime_ordinalized(fmt)
time.strftime(fmt)
end
end

Expand All @@ -36,11 +36,11 @@ def relative_date_span(times)
relative_date(times.first)
else
first = times.first; last = times.last; now = time_class.now
returning [first.strftime_ordinalized('%b %d')] do |arr|
returning [first.strftime('%b %d')] do |arr|
arr << ", #{first.year}" unless first.year == last.year
arr << ' - '
arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
arr << last.day.ordinalize
arr << last.day
arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
end.to_s
end
Expand All @@ -59,13 +59,13 @@ def relative_time_span(times)
first = times.first; last = times.last; now = time_class.now
[prettier_time(first)].tap do |arr|
arr << ' '
arr << first.strftime_ordinalized('%b %d')
arr << first.strftime('%b %d')
arr << ", #{first.year}" unless first.year == last.year
arr << ' - '
arr << prettier_time(last)
arr << ' '
arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
arr << last.day.ordinalize
arr << last.day
arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
end.to_s
end
Expand Down
44 changes: 22 additions & 22 deletions test/relative_time_helpers_test.rb
Expand Up @@ -27,77 +27,77 @@ def test_should_show_tomorrow
end

def test_should_show_date_with_year
assert_equal 'Nov 15th, 2005', relative_date(Time.utc(2005, 11, 15))
assert_equal 'Nov 15, 2005', relative_date(Time.utc(2005, 11, 15))
end

def test_should_show_date
assert_equal 'Nov 15th', relative_date(Time.utc(2007, 11, 15))
assert_equal 'Nov 15', relative_date(Time.utc(2007, 11, 15))
end

def test_should_show_date_span_on_the_same_day
assert_equal 'Nov 15th', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 15)])
assert_equal 'Nov 15', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 15)])
end

def test_should_show_date_span_on_the_same_day_on_different_year
assert_equal 'Nov 15th, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 15)])
assert_equal 'Nov 15, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 15)])
end

def test_should_show_date_span_on_the_same_month
assert_equal 'Nov 15th - 16th', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 16)])
assert_equal 'Nov 15th - 16th', relative_date_span([Time.utc(2007, 11, 16), Time.utc(2007, 11, 15)])
assert_equal 'Nov 15 - 16', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 11, 16)])
assert_equal 'Nov 15 - 16', relative_date_span([Time.utc(2007, 11, 16), Time.utc(2007, 11, 15)])
end

def test_should_show_date_span_on_the_same_month_on_different_year
assert_equal 'Nov 15th - 16th, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 16)])
assert_equal 'Nov 15th - 16th, 2006', relative_date_span([Time.utc(2006, 11, 16), Time.utc(2006, 11, 15)])
assert_equal 'Nov 15 - 16, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 11, 16)])
assert_equal 'Nov 15 - 16, 2006', relative_date_span([Time.utc(2006, 11, 16), Time.utc(2006, 11, 15)])
end

def test_should_show_date_span_on_the_different_month
assert_equal 'Nov 15th - Dec 16th', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 12, 16)])
assert_equal 'Nov 15th - Dec 16th', relative_date_span([Time.utc(2007, 12, 16), Time.utc(2007, 11, 15)])
assert_equal 'Nov 15 - Dec 16', relative_date_span([Time.utc(2007, 11, 15), Time.utc(2007, 12, 16)])
assert_equal 'Nov 15 - Dec 16', relative_date_span([Time.utc(2007, 12, 16), Time.utc(2007, 11, 15)])
end

def test_should_show_date_span_on_the_different_month_on_different_year
assert_equal 'Nov 15th - Dec 16th, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 12, 16)])
assert_equal 'Nov 15th - Dec 16th, 2006', relative_date_span([Time.utc(2006, 12, 16), Time.utc(2006, 11, 15)])
assert_equal 'Nov 15 - Dec 16, 2006', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2006, 12, 16)])
assert_equal 'Nov 15 - Dec 16, 2006', relative_date_span([Time.utc(2006, 12, 16), Time.utc(2006, 11, 15)])
end

def test_should_show_date_span_on_the_different_year
assert_equal 'Nov 15th, 2006 - Dec 16th, 2007', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2007, 12, 16)])
assert_equal 'Nov 15th, 2006 - Dec 16th, 2007', relative_date_span([Time.utc(2007, 12, 16), Time.utc(2006, 11, 15)])
assert_equal 'Nov 15, 2006 - Dec 16, 2007', relative_date_span([Time.utc(2006, 11, 15), Time.utc(2007, 12, 16)])
assert_equal 'Nov 15, 2006 - Dec 16, 2007', relative_date_span([Time.utc(2007, 12, 16), Time.utc(2006, 11, 15)])
end

# Time, Single Date
def test_should_show_time_span_on_the_same_day_with_same_time
assert_equal '5:00 PM Nov 15th', relative_time_span([Time.utc(2007, 11, 15, 17, 00, 00), Time.utc(2007, 11, 15, 17, 00, 00)])
assert_equal '5:00 PM Nov 15', relative_time_span([Time.utc(2007, 11, 15, 17, 00, 00), Time.utc(2007, 11, 15, 17, 00, 00)])
end

def test_should_show_time_span_on_the_same_day_with_same_time_on_different_year
assert_equal '5:00 PM Nov 15th, 2006', relative_time_span([Time.utc(2006, 11, 15, 17, 0), Time.utc(2006, 11, 15, 17, 0)])
assert_equal '5:00 PM Nov 15, 2006', relative_time_span([Time.utc(2006, 11, 15, 17, 0), Time.utc(2006, 11, 15, 17, 0)])
end

def test_should_show_time_span_on_the_same_day_with_different_times_in_same_half_of_day
assert_equal '10:00 - 11:00 AM Nov 15th', relative_time_span([Time.utc(2007, 11, 15, 10), Time.utc(2007, 11, 15, 11, 0)])
assert_equal '10:00 - 11:00 AM Nov 15', relative_time_span([Time.utc(2007, 11, 15, 10), Time.utc(2007, 11, 15, 11, 0)])
end

def test_should_show_time_span_on_the_same_day_with_different_times_in_different_half_of_day
assert_equal '10:00 AM - 2:00 PM Nov 15th', relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 11, 15, 14, 0)])
assert_equal '10:00 AM - 2:00 PM Nov 15', relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 11, 15, 14, 0)])
end

def test_should_show_time_span_on_the_same_day_with_different_times_in_different_half_of_day_in_different_year
assert_equal '10:00 AM - 2:00 PM Nov 15th, 2006', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 11, 15, 14, 0)])
assert_equal '10:00 AM - 2:00 PM Nov 15, 2006', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 11, 15, 14, 0)])
end

def test_should_show_time_span_on_different_days_in_same_year
assert_equal '10:00 AM Nov 15th - 2:00 PM Dec 16th, 2006', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 12, 16, 14, 0)])
assert_equal '10:00 AM Nov 15 - 2:00 PM Dec 16, 2006', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2006, 12, 16, 14, 0)])
end

def test_should_show_time_span_on_different_days_in_different_years
assert_equal '10:00 AM Nov 15th, 2006 - 2:00 PM Dec 16th, 2007', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)])
assert_equal '10:00 AM Nov 15, 2006 - 2:00 PM Dec 16, 2007', relative_time_span([Time.utc(2006, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)])
end

def test_should_show_time_span_on_different_days_in_current_year
assert_equal '10:00 AM Nov 15th - 2:00 PM Dec 16th', relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)])
assert_equal '10:00 AM Nov 15 - 2:00 PM Dec 16', relative_time_span([Time.utc(2007, 11, 15, 10, 0), Time.utc(2007, 12, 16, 14, 0)])
end

# prettier_time
Expand Down

0 comments on commit ca41279

Please sign in to comment.