timespan 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -0
- data/VERSION +1 -1
- data/lib/timespan.rb +3 -1
- data/spec/timespan/mongoid/mongoid_timespan_spec.rb +12 -0
- data/spec/timespan_spec.rb +9 -0
- data/timespan.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -12,6 +12,9 @@ Will calculate time diff between two dates, then allow you to get the time diffe
|
|
12
12
|
t.to_hours = 10800
|
13
13
|
|
14
14
|
t = Timespan.new("2 days") # from today
|
15
|
+
t = Timespan.new(2.days) # from today
|
16
|
+
t = Timespan.new(200) # 200 secs from today
|
17
|
+
t = Timespan.new(duration: 2.days) # specific use of :duration option
|
15
18
|
|
16
19
|
t = Timespan.new("3 hrs").from(2.days.from_now)
|
17
20
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.7
|
data/lib/timespan.rb
CHANGED
@@ -37,8 +37,10 @@ class Timespan
|
|
37
37
|
@init_options = options
|
38
38
|
validate! if options == {}
|
39
39
|
|
40
|
+
options = {:duration => options} if options.kind_of? Numeric
|
41
|
+
|
40
42
|
case options
|
41
|
-
when
|
43
|
+
when Duration, String
|
42
44
|
options = {:duration => options}
|
43
45
|
end
|
44
46
|
|
@@ -30,6 +30,18 @@ describe Timespan do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
context '2 days using integer' do
|
34
|
+
let(:account) do
|
35
|
+
Account.create :period => 2.days
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.start_date' do
|
39
|
+
it 'should default to today' do
|
40
|
+
DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
33
45
|
context '2 days duration (from now - default)' do
|
34
46
|
let(:account) do
|
35
47
|
Account.create :period => {:duration => '2 days'}
|
data/spec/timespan_spec.rb
CHANGED
@@ -18,6 +18,15 @@ describe Timespan do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
context '2 days duration using Integer' do
|
22
|
+
let(:timespan) { Timespan.new 2.days }
|
23
|
+
|
24
|
+
describe '.start_date' do
|
25
|
+
it 'should default to today' do
|
26
|
+
DateTime.parse(subject.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
31
|
context '2 days duration (from now - default)' do
|
23
32
|
let(:timespan) { Timespan.new :duration => "2 days"}
|
data/timespan.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timespan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
segments:
|
256
256
|
- 0
|
257
|
-
hash:
|
257
|
+
hash: 1077927940562943309
|
258
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
259
|
none: false
|
260
260
|
requirements:
|