Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added total minutes to format

  • Loading branch information...
commit f0d72d5d58606450744009c903a3ffed68cbbbb1 1 parent a72335b
Graham Davison authored
31  Gemfile.lock
... ...
@@ -1,31 +0,0 @@
1  
-PATH
2  
-  remote: .
3  
-  specs:
4  
-    ruby-duration (2.0.1)
5  
-      activesupport (>= 3.0.0)
6  
-      i18n
7  
-
8  
-GEM
9  
-  remote: http://rubygems.org/
10  
-  specs:
11  
-    activesupport (3.0.9)
12  
-    bluecloth (2.0.9)
13  
-    i18n (0.5.0)
14  
-    minitest (1.7.2)
15  
-    rake (0.8.7)
16  
-    simplecov (0.3.6)
17  
-      simplecov-html (>= 0.3.7)
18  
-    simplecov-html (0.3.8)
19  
-    yard (0.6.1)
20  
-
21  
-PLATFORMS
22  
-  ruby
23  
-
24  
-DEPENDENCIES
25  
-  bluecloth (>= 0.3.5)
26  
-  bundler (>= 1.0.0)
27  
-  minitest
28  
-  rake
29  
-  ruby-duration!
30  
-  simplecov (>= 0.3.5)
31  
-  yard
3  lib/duration.rb
@@ -145,6 +145,7 @@ def format(format_str)
145 145
       'm'  => @minutes,
146 146
       's'  => @seconds,
147 147
       't'  => @total,
  148
+      'tm' => @total / 60,
148 149
       'H'  => @hours.to_s.rjust(2, '0'),
149 150
       'M'  => @minutes.to_s.rjust(2, '0'),
150 151
       'S'  => @seconds.to_s.rjust(2, '0'),
@@ -155,7 +156,7 @@ def format(format_str)
155 156
       '~w' => i18n_for(:week)
156 157
     }
157 158
 
158  
-    format_str.gsub(/%?%(w|d|h|m|s|t|H|M|S|~(?:s|m|h|d|w))/) do |match|
  159
+    format_str.gsub(/%?%(w|d|h|m|s|tm?|H|M|S|~(?:s|m|h|d|w))/) do |match|
159 160
       match['%%'] ? match : identifiers[match[1..-1]]
160 161
     end.gsub('%%', '%')
161 162
   end
18  test/test_duration.rb
@@ -29,22 +29,22 @@
29 29
       assert_equal Duration.new(15), Duration.new(10) + Duration.new(5)
30 30
     end
31 31
     
32  
-    it "sould -" do
  32
+    it "should -" do
33 33
       assert_equal Duration.new(5), Duration.new(10) - 5
34 34
       assert_equal Duration.new(5), Duration.new(10) - Duration.new(5)
35 35
     end
36 36
     
37  
-    it "sould *" do
  37
+    it "should *" do
38 38
       assert_equal Duration.new(20), Duration.new(10) * 2
39 39
       assert_equal Duration.new(20), Duration.new(10) * Duration.new(2)
40 40
     end
41 41
     
42  
-    it "sould /" do
  42
+    it "should /" do
43 43
       assert_equal Duration.new(5), Duration.new(10) / 2
44 44
       assert_equal Duration.new(5), Duration.new(10) / Duration.new(2)
45 45
     end
46 46
     
47  
-    it "sould %" do
  47
+    it "should %" do
48 48
       assert_equal Duration.new(1), Duration.new(10) % 3
49 49
       assert_equal Duration.new(1), Duration.new(10) % Duration.new(3)
50 50
     end
@@ -60,6 +60,16 @@
60 60
       d = Duration.new(:weeks => 1, :days => 1, :hours => 1, :minutes => 1, :seconds => 1)
61 61
       assert_equal "1 week 1 day 1 hour 1 minute 1 second", d.format("%w %~w %d %~d %h %~h %m %~m %s %~s")
62 62
     end
  63
+    
  64
+    it "should display total seconds" do
  65
+      d = Duration.new(:hours => 1, :minutes => 15)
  66
+      assert_equal "4500 seconds", d.format("%t %~s")
  67
+    end
  68
+    
  69
+    it "should display total minutes" do
  70
+      d = Duration.new(:hours => 1, :minutes => 15)
  71
+      assert_equal "75 minutes", d.format("%tm %~m")
  72
+    end
63 73
   end
64 74
   
65 75
   describe "#iso_6801" do

0 notes on commit f0d72d5

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