diff options
-rw-r--r-- | app/helpers/date_time_helper.rb | 12 | ||||
-rw-r--r-- | spec/helpers/date_time_helper_spec.rb | 18 |
2 files changed, 29 insertions, 1 deletions
diff --git a/app/helpers/date_time_helper.rb b/app/helpers/date_time_helper.rb index c96265006..5fcec5a87 100644 --- a/app/helpers/date_time_helper.rb +++ b/app/helpers/date_time_helper.rb @@ -53,8 +53,18 @@ module DateTimeHelper I18n.l(date, :format => date_format) end + # Strips the date from a DateTime + # + # date - a DateTime, Date or Time + # + # Examples + # + # simple_time(Time.now) + # # => "10:46:54" + # + # Returns a String def simple_time(date) - return date.strftime("%H:%M:%S").strip + date.strftime("%H:%M:%S").strip end # Return the year component from a date diff --git a/spec/helpers/date_time_helper_spec.rb b/spec/helpers/date_time_helper_spec.rb index 67d2efdd3..6b55a11d1 100644 --- a/spec/helpers/date_time_helper_spec.rb +++ b/spec/helpers/date_time_helper_spec.rb @@ -51,6 +51,24 @@ describe DateTimeHelper do end + describe :simple_time do + + it 'returns 00:00:00 for a date' do + simple_time(Date.new(2012, 11, 21)).should == '00:00:00' + end + + it 'returns the time component of a datetime' do + date = DateTime.new(2012, 11, 21, 10, 34, 56) + simple_time(date).should == '10:34:56' + end + + it 'returns the time component of a time' do + time = Time.utc(2000, 'jan', 1, 20, 15, 1) + simple_time(time).should == '20:15:01' + end + + end + describe :year_from_date do it 'returns the year component of a date' do |