ruby-duration 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/duration.rb +5 -9
- data/ruby-duration.gemspec +1 -1
- data/test/test_duration.rb +4 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/lib/duration.rb
CHANGED
@@ -64,21 +64,17 @@ class Duration
|
|
64
64
|
# Formats a duration in ISO8601.
|
65
65
|
# @see http://en.wikipedia.org/wiki/ISO_8601#Durations
|
66
66
|
def iso8601
|
67
|
-
output = ''
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
output << "#{weeks}W" if weeks > 0
|
72
|
-
output << "#{days}D" if days > 0
|
73
|
-
end
|
74
|
-
|
67
|
+
output = 'P'
|
68
|
+
|
69
|
+
output << "#{weeks}W" if weeks > 0
|
70
|
+
output << "#{days}D" if days > 0
|
75
71
|
if seconds > 0 || minutes > 0 || hours > 0
|
76
72
|
output << 'T'
|
77
73
|
output << "#{hours}H" if hours > 0
|
78
74
|
output << "#{minutes}M" if minutes > 0
|
79
75
|
output << "#{seconds}S" if seconds > 0
|
80
76
|
end
|
81
|
-
|
77
|
+
|
82
78
|
output
|
83
79
|
end
|
84
80
|
|
data/ruby-duration.gemspec
CHANGED
data/test/test_duration.rb
CHANGED
@@ -38,17 +38,17 @@ describe "Duration" do
|
|
38
38
|
describe "#iso_6801" do
|
39
39
|
it "should format seconds" do
|
40
40
|
d = Duration.new(:seconds => 1)
|
41
|
-
assert_equal("
|
41
|
+
assert_equal("PT1S", d.iso8601)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should format minutes" do
|
45
45
|
d = Duration.new(:minutes => 1)
|
46
|
-
assert_equal("
|
46
|
+
assert_equal("PT1M", d.iso8601)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should format hours" do
|
50
50
|
d = Duration.new(:hours => 1)
|
51
|
-
assert_equal("
|
51
|
+
assert_equal("PT1H", d.iso8601)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should format days" do
|
@@ -72,7 +72,7 @@ describe "Duration" do
|
|
72
72
|
assert_equal("P1W2D", d.iso8601)
|
73
73
|
|
74
74
|
d = Duration.new(:hours => 1, :seconds => 30)
|
75
|
-
assert_equal("
|
75
|
+
assert_equal("PT1H30S", d.iso8601)
|
76
76
|
end
|
77
77
|
|
78
78
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-duration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jose Peleteiro
|