Permalink
Browse files

added total minutes to format

  • Loading branch information...
1 parent a72335b commit f0d72d5d58606450744009c903a3ffed68cbbbb1 @gdavison gdavison committed Mar 23, 2012
Showing with 16 additions and 36 deletions.
  1. +0 −31 Gemfile.lock
  2. +2 −1 lib/duration.rb
  3. +14 −4 test/test_duration.rb
View
31 Gemfile.lock
@@ -1,31 +0,0 @@
-PATH
- remote: .
- specs:
- ruby-duration (2.0.1)
- activesupport (>= 3.0.0)
- i18n
-
-GEM
- remote: http://rubygems.org/
- specs:
- activesupport (3.0.9)
- bluecloth (2.0.9)
- i18n (0.5.0)
- minitest (1.7.2)
- rake (0.8.7)
- simplecov (0.3.6)
- simplecov-html (>= 0.3.7)
- simplecov-html (0.3.8)
- yard (0.6.1)
-
-PLATFORMS
- ruby
-
-DEPENDENCIES
- bluecloth (>= 0.3.5)
- bundler (>= 1.0.0)
- minitest
- rake
- ruby-duration!
- simplecov (>= 0.3.5)
- yard
View
3 lib/duration.rb
@@ -145,6 +145,7 @@ def format(format_str)
'm' => @minutes,
's' => @seconds,
't' => @total,
+ 'tm' => @total / 60,
'H' => @hours.to_s.rjust(2, '0'),
'M' => @minutes.to_s.rjust(2, '0'),
'S' => @seconds.to_s.rjust(2, '0'),
@@ -155,7 +156,7 @@ def format(format_str)
'~w' => i18n_for(:week)
}
- format_str.gsub(/%?%(w|d|h|m|s|t|H|M|S|~(?:s|m|h|d|w))/) do |match|
+ format_str.gsub(/%?%(w|d|h|m|s|tm?|H|M|S|~(?:s|m|h|d|w))/) do |match|
match['%%'] ? match : identifiers[match[1..-1]]
end.gsub('%%', '%')
end
View
18 test/test_duration.rb
@@ -29,22 +29,22 @@
assert_equal Duration.new(15), Duration.new(10) + Duration.new(5)
end
- it "sould -" do
+ it "should -" do
assert_equal Duration.new(5), Duration.new(10) - 5
assert_equal Duration.new(5), Duration.new(10) - Duration.new(5)
end
- it "sould *" do
+ it "should *" do
assert_equal Duration.new(20), Duration.new(10) * 2
assert_equal Duration.new(20), Duration.new(10) * Duration.new(2)
end
- it "sould /" do
+ it "should /" do
assert_equal Duration.new(5), Duration.new(10) / 2
assert_equal Duration.new(5), Duration.new(10) / Duration.new(2)
end
- it "sould %" do
+ it "should %" do
assert_equal Duration.new(1), Duration.new(10) % 3
assert_equal Duration.new(1), Duration.new(10) % Duration.new(3)
end
@@ -60,6 +60,16 @@
d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :minutes => 1, :seconds => 1)
assert_equal "1 week 1 day 1 hour 1 minute 1 second", d.format("%w %~w %d %~d %h %~h %m %~m %s %~s")
end
+
+ it "should display total seconds" do
+ d = Duration.new(:hours => 1, :minutes => 15)
+ assert_equal "4500 seconds", d.format("%t %~s")
+ end
+
+ it "should display total minutes" do
+ d = Duration.new(:hours => 1, :minutes => 15)
+ assert_equal "75 minutes", d.format("%tm %~m")
+ end
end
describe "#iso_6801" do

0 comments on commit f0d72d5

Please sign in to comment.