timespan 0.2.6 → 0.2.7

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/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.6
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 Numeric, Duration, String
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'}
@@ -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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timespan"
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
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.6
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: -2757811782922718549
257
+ hash: 1077927940562943309
258
258
  required_rubygems_version: !ruby/object:Gem::Requirement
259
259
  none: false
260
260
  requirements: