timespan 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source :rubygems
3
3
  gem 'chronic'
4
4
  gem 'chronic_duration'
5
5
  gem 'spanner'
6
- gem 'ruby-duration', :git => 'git://github.com/kristianmandrup/ruby-duration.git'
6
+ gem 'ruby-duration', '~> 2.2.1', :git => 'git://github.com/kristianmandrup/ruby-duration.git'
7
7
 
8
8
  group :test, :development do
9
9
  gem "rspec", ">= 2.8.0"
@@ -1,8 +1,8 @@
1
1
  GIT
2
2
  remote: git://github.com/kristianmandrup/ruby-duration.git
3
- revision: 002f43a5ad5b6191ae5ee218e532176005279384
3
+ revision: c9b47be02e4a35f7ed3bf7de909d583d14272be8
4
4
  specs:
5
- ruby-duration (2.1.4)
5
+ ruby-duration (2.2.1)
6
6
  activesupport (>= 3.0.0)
7
7
  i18n
8
8
 
@@ -65,7 +65,7 @@ GEM
65
65
  activemodel (~> 3.1)
66
66
  mongo (~> 1.3)
67
67
  tzinfo (~> 0.3.22)
68
- multi_json (1.3.2)
68
+ multi_json (1.3.4)
69
69
  numerizer (0.1.1)
70
70
  polyglot (0.3.3)
71
71
  rack (1.4.1)
@@ -130,6 +130,6 @@ DEPENDENCIES
130
130
  rails (~> 3.2)
131
131
  rdoc (>= 3.12)
132
132
  rspec (>= 2.8.0)
133
- ruby-duration!
133
+ ruby-duration (~> 2.2.1)!
134
134
  simplecov (>= 0.5)
135
135
  spanner
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -49,10 +49,12 @@ class Timespan
49
49
 
50
50
  def +(other)
51
51
  self.duration += Duration.new(other)
52
+ self
52
53
  end
53
54
 
54
55
  def -(other)
55
56
  self.duration -= Duration.new(other)
57
+ self
56
58
  end
57
59
 
58
60
 
@@ -13,18 +13,21 @@ class Timespan
13
13
 
14
14
  alias_method :to_secs, :seconds
15
15
  alias_method :to_seconds, :seconds
16
+ alias_method :secs, :seconds
16
17
 
17
18
  def to_minutes
18
19
  @to_minutes ||= (to_seconds / 60.0).round
19
20
  end
20
21
  alias_method :to_m, :to_minutes
21
22
  alias_method :to_mins, :to_minutes
23
+ alias_method :mins, :to_minutes
22
24
  alias_method :minutes, :to_minutes
23
25
 
24
26
  def to_hours
25
27
  @to_hours ||= (to_minutes / 60.0).round
26
28
  end
27
29
  alias_method :to_h, :to_hours
30
+ alias_method :to_hrs, :to_hours
28
31
  alias_method :hrs, :to_hours
29
32
  alias_method :hours, :to_hours
30
33
 
@@ -38,7 +41,7 @@ class Timespan
38
41
  @to_weeks ||= (to_days / 7.0).round
39
42
  end
40
43
  alias_method :to_w, :to_weeks
41
- alias_method :weeks, :to_days
44
+ alias_method :weeks, :to_weeks
42
45
 
43
46
  def to_months
44
47
  @to_months ||= (to_days / 30.0).round
@@ -50,6 +53,8 @@ class Timespan
50
53
  @to_years ||= (to_days.to_f / 365.25).round
51
54
  end
52
55
  alias_method :to_y, :to_years
56
+ alias_method :yrs, :to_years
57
+ alias_method :to_yrs, :to_years
53
58
  alias_method :years, :to_years
54
59
 
55
60
  def to_decades
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'duration/macros'
3
+
4
+ describe Timespan do
5
+ subject { timespan }
6
+
7
+ let(:from) { Chronic.parse("1 day ago") }
8
+ let(:to) { Time.now }
9
+
10
+ context '3 hrs duration + 3hrs duration' do
11
+ let(:timespan) { Timespan.new("3 hrs") + 3.dhours }
12
+
13
+ describe '.start_date' do
14
+ its(:start_date) { should be }
15
+ its(:end_date) { should be }
16
+ its(:duration) { should be_a Duration }
17
+ specify { subject.hours.should be 6 }
18
+ end
19
+ end
20
+
21
+ context '3 hrs duration + 2hrs' do
22
+ let(:timespan) { Timespan.new("3 hrs") + 2.hours }
23
+
24
+ describe '.start_date' do
25
+ its(:start_date) { should be }
26
+ its(:end_date) { should be }
27
+ its(:duration) { should be_a Duration }
28
+ specify { subject.hours.should be 5 }
29
+ end
30
+ end
31
+ end
@@ -20,7 +20,7 @@ describe Timespan::Units do
20
20
  it "spans 1 day" do
21
21
  timespan.to_d.should == 1
22
22
  end
23
- its(:days) { seconds.should == 1 }
23
+ its(:days) { should == 1 }
24
24
  end
25
25
 
26
26
  describe '.hours' do
@@ -26,7 +26,6 @@ describe Timespan do
26
26
  end
27
27
  end
28
28
 
29
-
30
29
  context 'From and To with 1 day apart' do
31
30
  let(:timespan) { Timespan.new :from => from, :to => to}
32
31
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timespan"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
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"]
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/timespan/units.rb",
36
36
  "spec/spec_helper.rb",
37
37
  "spec/timespan/compare_spec.rb",
38
+ "spec/timespan/duration_macros_spec.rb",
38
39
  "spec/timespan/locales/duration_da.yml",
39
40
  "spec/timespan/mongoid/account.rb",
40
41
  "spec/timespan/mongoid/mongoid_timespan_spec.rb",
@@ -58,7 +59,7 @@ Gem::Specification.new do |s|
58
59
  s.add_runtime_dependency(%q<chronic>, [">= 0"])
59
60
  s.add_runtime_dependency(%q<chronic_duration>, [">= 0"])
60
61
  s.add_runtime_dependency(%q<spanner>, [">= 0"])
61
- s.add_runtime_dependency(%q<ruby-duration>, [">= 0"])
62
+ s.add_runtime_dependency(%q<ruby-duration>, ["~> 2.2.1"])
62
63
  s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
63
64
  s.add_development_dependency(%q<rails>, ["~> 3.2"])
64
65
  s.add_development_dependency(%q<mongoid>, ["~> 2.4"])
@@ -71,7 +72,7 @@ Gem::Specification.new do |s|
71
72
  s.add_dependency(%q<chronic>, [">= 0"])
72
73
  s.add_dependency(%q<chronic_duration>, [">= 0"])
73
74
  s.add_dependency(%q<spanner>, [">= 0"])
74
- s.add_dependency(%q<ruby-duration>, [">= 0"])
75
+ s.add_dependency(%q<ruby-duration>, ["~> 2.2.1"])
75
76
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
76
77
  s.add_dependency(%q<rails>, ["~> 3.2"])
77
78
  s.add_dependency(%q<mongoid>, ["~> 2.4"])
@@ -85,7 +86,7 @@ Gem::Specification.new do |s|
85
86
  s.add_dependency(%q<chronic>, [">= 0"])
86
87
  s.add_dependency(%q<chronic_duration>, [">= 0"])
87
88
  s.add_dependency(%q<spanner>, [">= 0"])
88
- s.add_dependency(%q<ruby-duration>, [">= 0"])
89
+ s.add_dependency(%q<ruby-duration>, ["~> 2.2.1"])
89
90
  s.add_dependency(%q<rspec>, [">= 2.8.0"])
90
91
  s.add_dependency(%q<rails>, ["~> 3.2"])
91
92
  s.add_dependency(%q<mongoid>, ["~> 2.4"])
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.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -64,17 +64,17 @@ dependencies:
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 2.2.1
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 2.2.1
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rspec
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -229,6 +229,7 @@ files:
229
229
  - lib/timespan/units.rb
230
230
  - spec/spec_helper.rb
231
231
  - spec/timespan/compare_spec.rb
232
+ - spec/timespan/duration_macros_spec.rb
232
233
  - spec/timespan/locales/duration_da.yml
233
234
  - spec/timespan/mongoid/account.rb
234
235
  - spec/timespan/mongoid/mongoid_timespan_spec.rb
@@ -253,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
254
  version: '0'
254
255
  segments:
255
256
  - 0
256
- hash: -3275887994789672968
257
+ hash: 4000809282305753750
257
258
  required_rubygems_version: !ruby/object:Gem::Requirement
258
259
  none: false
259
260
  requirements: