timespan 0.5.6.1 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ ## 0.5.6
2
+
3
+ * Initial support for `time-lord` gem.
4
+ * Use `xduration` 3.0.0 gem
5
+
6
+ ## 0.5.5
7
+
8
+ * Better DurationRange specs
9
+ * DurationRange comparisons
10
+ * DurationRange Mongoid serialization works (and specs)
11
+
1
12
  ## 0.5.4
2
13
 
3
14
  - Added subclasses LongDurationRange and ShortDurationRange for long and short durations.
data/Gemfile CHANGED
@@ -1,14 +1,16 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'chronic'
4
4
  gem 'chronic_duration'
5
5
  gem 'activesupport', '>= 3.0.0'
6
6
  gem 'spanner'
7
7
  gem 'sugar-high', '>= 0.7.3' # for range intersect
8
- gem 'xduration', '>= 2.2'
8
+
9
+ gem 'xduration', '>= 3.0.0' # ruby-duration with extensions
10
+ gem 'time-lord', '>= 1.0.0'
9
11
 
10
12
  group :test, :development do
11
- gem "rspec", ">= 2.8.0"
13
+ gem "rspec", ">= 2.12.0"
12
14
  gem 'rails', '>= 3.1'
13
15
  # gem 'mongoid', '>= 2.4'
14
16
  # gem 'bson', '>= 1.6'
@@ -9,7 +9,7 @@ GIT
9
9
  rdoc
10
10
 
11
11
  GEM
12
- remote: http://rubygems.org/
12
+ remote: https://rubygems.org/
13
13
  specs:
14
14
  actionmailer (3.2.12)
15
15
  actionpack (= 3.2.12)
@@ -113,13 +113,14 @@ GEM
113
113
  sugar-high (0.7.3)
114
114
  thor (0.17.0)
115
115
  tilt (1.3.5)
116
+ time-lord (1.0.1)
116
117
  treetop (1.4.12)
117
118
  polyglot
118
119
  polyglot (>= 0.3.1)
119
120
  tzinfo (0.3.37)
120
- xduration (2.2.3)
121
+ xduration (3.0.0)
121
122
  activesupport (>= 3.0.0)
122
- i18n
123
+ i18n (>= 0.6)
123
124
 
124
125
  PLATFORMS
125
126
  ruby
@@ -133,8 +134,9 @@ DEPENDENCIES
133
134
  mongoid (>= 3.0)
134
135
  origin-selectable_ext (~> 0.1.1)
135
136
  rails (>= 3.1)
136
- rspec (>= 2.8.0)
137
+ rspec (>= 2.12.0)
137
138
  simplecov (>= 0.7)
138
139
  spanner
139
140
  sugar-high (>= 0.7.3)
140
- xduration (>= 2.2)
141
+ time-lord (>= 1.0.0)
142
+ xduration (>= 3.0.0)
data/README.md CHANGED
@@ -51,7 +51,9 @@ Internally Timespan uses Spanner to parse duration strings.
51
51
 
52
52
  `Spanner.parse('23 hours 12 minutes')
53
53
 
54
- ## Duration (ruby-duration)
54
+ ## Duration (xduration)
55
+
56
+ The type `Duration` is supported via the [xduration](https://github.com/kristianmandrup/xduration) gem, which extends `ruby-duration` with additional macros, specific time unit classes and supports longer duration time periods such as weeks, months and years.
55
57
 
56
58
  ```ruby
57
59
  Duration.new(100) => #<Duration: minutes=1, seconds=40, total=100>
@@ -89,7 +91,7 @@ require 'duration/mongoid'
89
91
 
90
92
  class MyModel
91
93
  include Mongoid::Document
92
- field :duration, type => Duration
94
+ field :duration, type => ::Duration
93
95
  end
94
96
  ```
95
97
 
@@ -253,6 +255,13 @@ class Account
253
255
 
254
256
  See the `mongoid_search_spec.rb` for examples:
255
257
 
258
+ ## Time lord
259
+
260
+ This gem can be used in combination with [Time lord](https://github.com/krainboltgreene/time-lord), which has a lot of functionality for time periods, conversions, calculations and outputting to strings etc.
261
+
262
+ Some initial support for `time-lord` has been added, but not yet tested.
263
+ Please help out ;)
264
+
256
265
  ## Chronic duration
257
266
 
258
267
  Is used to parse duration strings if Spanner can't be handle it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.6.1
1
+ 0.5.7
@@ -2,6 +2,7 @@ require 'duration'
2
2
  require 'chronic'
3
3
  require 'chronic_duration'
4
4
  require 'spanner'
5
+ require 'time-lord'
5
6
 
6
7
  # Range intersection that works with dates!
7
8
  require 'sugar-high/range'
@@ -57,7 +58,7 @@ class Timespan
57
58
  options = {:duration => options} if options.kind_of? Numeric
58
59
 
59
60
  case options
60
- when Duration, String
61
+ when TimeLord::Period, ::Duration, String
61
62
  options = {:duration => options}
62
63
  end
63
64
 
@@ -194,15 +195,23 @@ class Timespan
194
195
  time.to_time
195
196
  when Duration
196
197
  (Time.now + time).to_time
198
+ when TimeLord::Period
199
+ (Time.now + time).to_time
200
+ when TimeLord::Time
201
+ (Time.now + time.moment).to_time
197
202
  when Time
198
203
  time
199
204
  else
200
- raise ArgumentError, "A valid time must be either a String, Duration, Date, Time or DateTime, was: #{time.inspect} (#{time.class})"
205
+ raise ArgumentError, "A valid time must be one of #{valid_time_classes.inspect}, was: #{time.inspect} (#{time.class})"
201
206
  end
202
207
  end
203
208
 
204
209
  protected
205
210
 
211
+ def valid_time_classes
212
+ [String, Duration, Date, Time, DateTime, TimeLord::Period, TimeLord::Time]
213
+ end
214
+
206
215
  attr_reader :init_options
207
216
 
208
217
  def first_from keys, options = {}
@@ -56,6 +56,8 @@ class Timespan
56
56
  time.to_time.to_i
57
57
  when Integer
58
58
  seconds <=> time
59
+ when Timelord::Time
60
+ seconds <=> time.moment
59
61
  when ActiveSupport::Duration
60
62
  seconds <=> time.to_i
61
63
  end
@@ -13,6 +13,8 @@ class Timespan
13
13
  duration.duration
14
14
  when Duration
15
15
  duration
16
+ when TimeLord::Period
17
+ Duration.new start_date: duration.beginning, end_date: duration.ending
16
18
  when Hash
17
19
  Duration.new duration
18
20
  when String
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timespan"
8
- s.version = "0.5.6.1"
8
+ s.version = "0.5.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"]
@@ -84,8 +84,9 @@ Gem::Specification.new do |s|
84
84
  s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
85
85
  s.add_runtime_dependency(%q<spanner>, [">= 0"])
86
86
  s.add_runtime_dependency(%q<sugar-high>, [">= 0.7.3"])
87
- s.add_runtime_dependency(%q<xduration>, [">= 2.2"])
88
- s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
87
+ s.add_runtime_dependency(%q<xduration>, [">= 3.0.0"])
88
+ s.add_runtime_dependency(%q<time-lord>, [">= 1.0.0"])
89
+ s.add_development_dependency(%q<rspec>, [">= 2.12.0"])
89
90
  s.add_development_dependency(%q<rails>, [">= 3.1"])
90
91
  s.add_development_dependency(%q<mongoid>, [">= 3.0"])
91
92
  s.add_development_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
@@ -98,8 +99,9 @@ Gem::Specification.new do |s|
98
99
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
99
100
  s.add_dependency(%q<spanner>, [">= 0"])
100
101
  s.add_dependency(%q<sugar-high>, [">= 0.7.3"])
101
- s.add_dependency(%q<xduration>, [">= 2.2"])
102
- s.add_dependency(%q<rspec>, [">= 2.8.0"])
102
+ s.add_dependency(%q<xduration>, [">= 3.0.0"])
103
+ s.add_dependency(%q<time-lord>, [">= 1.0.0"])
104
+ s.add_dependency(%q<rspec>, [">= 2.12.0"])
103
105
  s.add_dependency(%q<rails>, [">= 3.1"])
104
106
  s.add_dependency(%q<mongoid>, [">= 3.0"])
105
107
  s.add_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
@@ -113,8 +115,9 @@ Gem::Specification.new do |s|
113
115
  s.add_dependency(%q<activesupport>, [">= 3.0.0"])
114
116
  s.add_dependency(%q<spanner>, [">= 0"])
115
117
  s.add_dependency(%q<sugar-high>, [">= 0.7.3"])
116
- s.add_dependency(%q<xduration>, [">= 2.2"])
117
- s.add_dependency(%q<rspec>, [">= 2.8.0"])
118
+ s.add_dependency(%q<xduration>, [">= 3.0.0"])
119
+ s.add_dependency(%q<time-lord>, [">= 1.0.0"])
120
+ s.add_dependency(%q<rspec>, [">= 2.12.0"])
118
121
  s.add_dependency(%q<rails>, [">= 3.1"])
119
122
  s.add_dependency(%q<mongoid>, [">= 3.0"])
120
123
  s.add_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
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.5.6.1
4
+ version: 0.5.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -98,7 +98,23 @@ dependencies:
98
98
  requirements:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
- version: '2.2'
101
+ version: 3.0.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 3.0.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: time-lord
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
102
118
  type: :runtime
103
119
  prerelease: false
104
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +122,7 @@ dependencies:
106
122
  requirements:
107
123
  - - ! '>='
108
124
  - !ruby/object:Gem::Version
109
- version: '2.2'
125
+ version: 1.0.0
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: rspec
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +130,7 @@ dependencies:
114
130
  requirements:
115
131
  - - ! '>='
116
132
  - !ruby/object:Gem::Version
117
- version: 2.8.0
133
+ version: 2.12.0
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +138,7 @@ dependencies:
122
138
  requirements:
123
139
  - - ! '>='
124
140
  - !ruby/object:Gem::Version
125
- version: 2.8.0
141
+ version: 2.12.0
126
142
  - !ruby/object:Gem::Dependency
127
143
  name: rails
128
144
  requirement: !ruby/object:Gem::Requirement
@@ -293,7 +309,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
309
  version: '0'
294
310
  segments:
295
311
  - 0
296
- hash: -334950470551913116
312
+ hash: -400546450151555613
297
313
  required_rubygems_version: !ruby/object:Gem::Requirement
298
314
  none: false
299
315
  requirements: