Skip to content
Browse files

total minutes with unit and total seconds with unit now work

  • Loading branch information...
1 parent 8a11a12 commit 38cf673ce7648b46eff2244197083956aaf6ea9b @gdavison gdavison committed Apr 5, 2012
Showing with 15 additions and 8 deletions.
  1. +5 −3 lib/duration.rb
  2. +10 −5 test/test_duration.rb
View
8 lib/duration.rb
@@ -159,11 +159,13 @@ def format(format_str)
'~h' => i18n_for(:hour),
'~d' => i18n_for(:day),
'~w' => i18n_for(:week),
- '~ts'=> Proc.new { i18n_for(:total) },
- '~tm'=> Proc.new { i18n_for(:total_minute) }
+# '~ts'=> Proc.new { i18n_for(:total) },
+# '~tm'=> Proc.new { i18n_for(:total_minute) }
+ 'tmu'=> Proc.new { "#{total_minutes} #{i18n_for(:total_minute)}"},
+ 'tsu'=> Proc.new { "#{total} #{i18n_for(:total)}"}
}
- format_str.gsub(/%?%(w|d|h|m|s|tm?|H|M|S|~(?:s|m|h|d|w|ts|tm))/) do |match|
+ format_str.gsub(/%?%(w|d|h|m|s|(tmu)|(tsu)|(tm)|t|H|M|S|~(?:s|m|h|d|w))/) do |match|
match['%%'] ? match : (identifiers[match[1..-1]].class == Proc ? identifiers[match[1..-1]].call : identifiers[match[1..-1]])
end.gsub('%%', '%')
end
View
15 test/test_duration.rb
@@ -65,22 +65,27 @@
it "should display total seconds" do
d = Duration.new(:hours => 1, :minutes => 15)
- assert_equal "4500 seconds", d.format("%t %~ts")
+ assert_equal "4500 seconds", d.format("%tsu")
end
it "should display total seconds in plural form when needed" do
d = Duration.new(:minutes => 1, :seconds => 1)
- assert_equal "61 seconds", d.format("%t %~ts")
+ assert_equal "61 seconds", d.format("%tsu")
end
- it "should display total minutes" do
+ it "should display total minutes as number" do
d = Duration.new(:hours => 1, :minutes => 15)
- assert_equal "75 minutes", d.format("%tm %~tm")
+ assert_equal "75", d.format("%tm")
end
+ it 'should display total minutes with unit' do
+ d = Duration.new(:hours => 1, :minutes => 15)
+ assert_equal "75 minutes", d.format("%tmu")
+ end
+
it "should display total minutes in plural form when needed" do
d = Duration.new(:hours => 1, :minutes => 1)
- assert_equal "61 minutes", d.format("%tm %~tm")
+ assert_equal "61 minutes", d.format("%tmu")
end
end

0 comments on commit 38cf673

Please sign in to comment.
Something went wrong with that request. Please try again.