timespan 0.5.1 → 0.5.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/Gemfile +4 -4
- data/Gemfile.lock +3 -3
- data/VERSION +1 -1
- data/lib/timespan.rb +16 -6
- data/lib/timespan/core_ext/hash.rb +2 -1
- data/lib/timespan/core_ext/range.rb +25 -8
- data/lib/timespan/mongoid/mongoid_3x.rb +8 -1
- data/lib/timespan/mongoid/timespanned.rb +11 -1
- data/lib/timespan/printer.rb +8 -1
- data/spec/timespan/asap_spec.rb +32 -0
- data/spec/timespan/core_ext/duration_range_spec.rb +4 -4
- data/spec/timespan/core_ext/timespan_range_spec.rb +4 -4
- data/spec/timespan/mongoid/advanced_search_spec.rb +2 -2
- data/spec/timespan/mongoid/models/account_3x.rb +2 -1
- data/spec/timespan/mongoid/mongoid_asap_spec.rb +90 -0
- data/spec/timespan/mongoid/mongoid_duration_range_spec.rb +51 -0
- data/spec/timespan/mongoid/mongoid_timespan_spec.rb +20 -36
- data/timespan.gemspec +11 -8
- metadata +12 -9
data/Gemfile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
source
|
1
|
+
source 'http://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
|
-
gem 'sugar-high', '~> 0.7.
|
8
|
-
gem 'xduration',
|
7
|
+
gem 'sugar-high', '~> 0.7.3' # for range intersect
|
8
|
+
gem 'xduration', '~> 2.2'
|
9
9
|
|
10
10
|
group :test, :development do
|
11
11
|
gem "rspec", ">= 2.8.0"
|
12
|
-
gem 'rails', '
|
12
|
+
gem 'rails', '>= 3.2'
|
13
13
|
# gem 'mongoid', '>= 2.4'
|
14
14
|
# gem 'bson', '>= 1.6'
|
15
15
|
|
data/Gemfile.lock
CHANGED
@@ -104,7 +104,7 @@ GEM
|
|
104
104
|
hike (~> 1.2)
|
105
105
|
rack (~> 1.0)
|
106
106
|
tilt (~> 1.1, != 1.3.0)
|
107
|
-
sugar-high (0.7.
|
107
|
+
sugar-high (0.7.3)
|
108
108
|
thor (0.15.4)
|
109
109
|
tilt (1.3.3)
|
110
110
|
treetop (1.4.10)
|
@@ -126,10 +126,10 @@ DEPENDENCIES
|
|
126
126
|
jeweler (>= 1.8.3)
|
127
127
|
mongoid (~> 3.0)
|
128
128
|
origin-selectable_ext (~> 0.1.1)
|
129
|
-
rails (
|
129
|
+
rails (>= 3.2)
|
130
130
|
rdoc (>= 3.12)
|
131
131
|
rspec (>= 2.8.0)
|
132
132
|
simplecov (>= 0.5)
|
133
133
|
spanner
|
134
|
-
sugar-high (~> 0.7.
|
134
|
+
sugar-high (~> 0.7.3)
|
135
135
|
xduration (~> 2.2)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
data/lib/timespan.rb
CHANGED
@@ -43,9 +43,9 @@ class Timespan
|
|
43
43
|
alias_method :start_date, :start_time
|
44
44
|
alias_method :end_date, :end_time
|
45
45
|
|
46
|
-
START_KEYS = [:start, :from, :start_date]
|
47
|
-
END_KEYS = [:to, :end, :end_date]
|
48
|
-
DURATION_KEYS = [:duration, :lasting]
|
46
|
+
START_KEYS = [:start, :from, :start_date, :start_time, :start_from, :starting]
|
47
|
+
END_KEYS = [:to, :end, :end_date, :end_at, :ending]
|
48
|
+
DURATION_KEYS = [:duration, :lasting, :"for"]
|
49
49
|
|
50
50
|
ALL_KEYS = START_KEYS + END_KEYS + DURATION_KEYS
|
51
51
|
|
@@ -66,6 +66,14 @@ class Timespan
|
|
66
66
|
@is_new = false
|
67
67
|
end
|
68
68
|
|
69
|
+
def asap!
|
70
|
+
@asap = true
|
71
|
+
end
|
72
|
+
|
73
|
+
def asap= value
|
74
|
+
@asap = !!value
|
75
|
+
end
|
76
|
+
|
69
77
|
class << self
|
70
78
|
def max_date
|
71
79
|
@max_date ||= Time.now + 10.years
|
@@ -88,8 +96,10 @@ class Timespan
|
|
88
96
|
end
|
89
97
|
|
90
98
|
def from start, duration, options = {}
|
99
|
+
asap = false
|
91
100
|
start = case start.to_sym
|
92
101
|
when :now, :asap
|
102
|
+
asap = true
|
93
103
|
Time.now
|
94
104
|
when :today
|
95
105
|
Date.today
|
@@ -105,7 +115,7 @@ class Timespan
|
|
105
115
|
start
|
106
116
|
end
|
107
117
|
|
108
|
-
self.new start_date: start, duration: duration
|
118
|
+
self.new start_date: start, duration: duration, asap: asap
|
109
119
|
end
|
110
120
|
|
111
121
|
def untill ending
|
@@ -158,11 +168,11 @@ class Timespan
|
|
158
168
|
alias_method :end_date=, :end_time=
|
159
169
|
|
160
170
|
def asap?
|
161
|
-
|
171
|
+
!!@asap
|
162
172
|
end
|
163
173
|
|
164
174
|
def min
|
165
|
-
asap ? Time.now : start_time
|
175
|
+
asap? ? Time.now : start_time
|
166
176
|
end
|
167
177
|
|
168
178
|
def max
|
@@ -2,11 +2,12 @@ class Hash
|
|
2
2
|
def __evolve_to_timespan__
|
3
3
|
serializer = Mongoid::Fields::Timespan
|
4
4
|
object = self
|
5
|
+
# puts "evolve from: #{self}"
|
5
6
|
::Timespan.new :from => serializer.from(object), :to => serializer.to(object), asap: serializer.asap(object)
|
6
7
|
end
|
7
8
|
|
8
9
|
def __evolve_to_duration_range__
|
9
|
-
range = Range.new self['from'], self['to']
|
10
|
+
range = Range.new (self['from'] || self[:from]), (self['to'] || self[:to])
|
10
11
|
::DurationRange.new range, :seconds
|
11
12
|
end
|
12
13
|
end
|
@@ -1,22 +1,40 @@
|
|
1
1
|
class TimespanRange < DelegateDecorator
|
2
2
|
attr_accessor :unit, :range
|
3
3
|
|
4
|
-
def initialize range, unit
|
5
|
-
|
4
|
+
def initialize range, unit = :minutes
|
5
|
+
range = (0..60) if range.min == nil || range.max == nil
|
6
|
+
super(range, except: %w{to_s to_str})
|
6
7
|
@range = Timespan.new between: range
|
7
|
-
@unit = unit.to_s.
|
8
|
+
@unit = unit.to_s.pluralize.to_sym
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_str
|
12
|
+
to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
range.min.nil? ? 'no timespan range' : "#{range.min} to #{range.max} #{unit}"
|
8
17
|
end
|
9
18
|
end
|
10
19
|
|
11
20
|
class DurationRange < DelegateDecorator
|
12
21
|
attr_accessor :unit, :range
|
13
22
|
|
14
|
-
def initialize range, unit
|
15
|
-
|
16
|
-
|
23
|
+
def initialize range, unit = :minutes
|
24
|
+
range = (0..60) if range.min == nil || range.max == nil
|
25
|
+
super(range, except: %w{to_s to_str})
|
26
|
+
@unit = unit.to_s.pluralize.to_sym
|
17
27
|
@range = range
|
18
28
|
end
|
19
29
|
|
30
|
+
def to_str
|
31
|
+
to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
range.min.nil? ? 'no duration range' : "#{range.min} to #{range.max} #{unit}"
|
36
|
+
end
|
37
|
+
|
20
38
|
def __evolve_to_duration_range__
|
21
39
|
self
|
22
40
|
end
|
@@ -70,7 +88,7 @@ class DurationRange < DelegateDecorator
|
|
70
88
|
else
|
71
89
|
raise "Unable to demongoize DurationRange from: #{object}"
|
72
90
|
end
|
73
|
-
# puts "demongoized: #{demongoized} -
|
91
|
+
# puts "demongoized: #{demongoized} - #{demongoized.class}"
|
74
92
|
demongoized
|
75
93
|
end
|
76
94
|
|
@@ -108,7 +126,6 @@ class DurationRange < DelegateDecorator
|
|
108
126
|
end
|
109
127
|
end
|
110
128
|
|
111
|
-
|
112
129
|
class Range
|
113
130
|
[:seconds, :minutes, :hours, :days, :weeks, :months, :years].each do |unit|
|
114
131
|
define_method unit do |type = :duration|
|
@@ -17,7 +17,14 @@ class Timespan
|
|
17
17
|
# @param [Timespan, Hash, Integer, String] value
|
18
18
|
# @return [Hash] Timespan in seconds
|
19
19
|
def mongoize
|
20
|
-
|
20
|
+
hash = {
|
21
|
+
:from => Serializer.serialize_time(start_time),
|
22
|
+
:to => Serializer.serialize_time(end_time),
|
23
|
+
:duration => duration.total,
|
24
|
+
:asap => asap?
|
25
|
+
}
|
26
|
+
# puts "serialize: #{hash}"
|
27
|
+
hash
|
21
28
|
end
|
22
29
|
|
23
30
|
class << self
|
@@ -2,16 +2,26 @@ module Mongoid
|
|
2
2
|
module Timespanned
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
+
def asap_for tspan_field = :period
|
6
|
+
ts = ::Timespan.asap duration: send(tspan_field).duration
|
7
|
+
self.send("#{tspan_field}=", ts)
|
8
|
+
self.save!
|
9
|
+
end
|
10
|
+
|
5
11
|
class << self
|
6
12
|
attr_accessor :log
|
7
13
|
|
8
14
|
def log msg
|
9
|
-
puts msg
|
15
|
+
puts msg if log?
|
10
16
|
end
|
11
17
|
|
12
18
|
def log?
|
13
19
|
@log
|
14
20
|
end
|
21
|
+
|
22
|
+
def log!
|
23
|
+
@log = true
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
module ClassMethods
|
data/lib/timespan/printer.rb
CHANGED
@@ -16,13 +16,17 @@ class Timespan
|
|
16
16
|
# %td => total days
|
17
17
|
# %th => total hours
|
18
18
|
# %tm => total minutes
|
19
|
-
# %ts => total seconds
|
19
|
+
# %ts => total seconds
|
20
20
|
def to_s mode = :full
|
21
21
|
meth = "print_#{mode}"
|
22
22
|
raise ArgumentError, "Print mode not supported, was: #{mode}" unless respond_to?(meth)
|
23
23
|
send(meth)
|
24
24
|
end
|
25
25
|
|
26
|
+
def to_str
|
27
|
+
to_s
|
28
|
+
end
|
29
|
+
|
26
30
|
def print_dates
|
27
31
|
"#{i18n_t 'from'} #{print :start_time} #{i18n_t 'to'} #{print :end_time}"
|
28
32
|
end
|
@@ -44,6 +48,9 @@ class Timespan
|
|
44
48
|
def print type
|
45
49
|
return duration.format(duration_format) if type == :duration
|
46
50
|
raise ArgumentError, "Not a valid print type, was: #{type}" unless valid_print_type? type
|
51
|
+
|
52
|
+
return "ASAP" if type == :start_time && asap?
|
53
|
+
|
47
54
|
send(type).strftime(time_format)
|
48
55
|
end
|
49
56
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Timespan::Span do
|
4
|
+
subject { timespan }
|
5
|
+
|
6
|
+
let(:from) { Chronic.parse("1 day ago") }
|
7
|
+
let(:to) { Time.now }
|
8
|
+
|
9
|
+
describe '.asap factory method' do
|
10
|
+
let(:timespan) { Timespan.asap :to => to }
|
11
|
+
|
12
|
+
its(:asap?) { should be_true }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.asap=' do
|
16
|
+
before do
|
17
|
+
@timespan = Timespan.new :from => from, :to => to
|
18
|
+
@timespan.asap = true
|
19
|
+
end
|
20
|
+
|
21
|
+
specify { @timespan.asap?.should be_true }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '.asap!' do
|
25
|
+
before do
|
26
|
+
@timespan = Timespan.new :from => from, :to => to
|
27
|
+
@timespan.asap!
|
28
|
+
end
|
29
|
+
|
30
|
+
specify { @timespan.asap?.should be_true }
|
31
|
+
end
|
32
|
+
end
|
@@ -28,7 +28,7 @@ describe DurationRange do
|
|
28
28
|
its(:range) { should be_a Range }
|
29
29
|
its(:min) { should == 1.day }
|
30
30
|
its(:max) { should == 5.days }
|
31
|
-
its(:unit) { should == :
|
31
|
+
its(:unit) { should == :days }
|
32
32
|
|
33
33
|
specify { subject.between?(4.days).should be_true }
|
34
34
|
end
|
@@ -39,7 +39,7 @@ describe DurationRange do
|
|
39
39
|
its(:range) { should be_a Range }
|
40
40
|
its(:min) { should == 1.week }
|
41
41
|
its(:max) { should == 5.weeks }
|
42
|
-
its(:unit) { should == :
|
42
|
+
its(:unit) { should == :weeks }
|
43
43
|
end
|
44
44
|
|
45
45
|
context 'month range' do
|
@@ -47,7 +47,7 @@ describe DurationRange do
|
|
47
47
|
|
48
48
|
its(:min) { should == 1.month }
|
49
49
|
its(:max) { should == 5.months }
|
50
|
-
its(:unit) { should == :
|
50
|
+
its(:unit) { should == :months }
|
51
51
|
end
|
52
52
|
|
53
53
|
context 'year range' do
|
@@ -55,6 +55,6 @@ describe DurationRange do
|
|
55
55
|
|
56
56
|
its(:min) { should == 1.year }
|
57
57
|
its(:max) { should == 5.years }
|
58
|
-
its(:unit) { should == :
|
58
|
+
its(:unit) { should == :years }
|
59
59
|
end
|
60
60
|
end
|
@@ -25,7 +25,7 @@ describe TimespanRange do
|
|
25
25
|
its(:range) { should be_a Timespan }
|
26
26
|
its(:min) { should == 1.day }
|
27
27
|
its(:max) { should == 5.days }
|
28
|
-
its(:unit) { should == :
|
28
|
+
its(:unit) { should == :days }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'week range' do
|
@@ -34,7 +34,7 @@ describe TimespanRange do
|
|
34
34
|
its(:range) { should be_a Timespan }
|
35
35
|
its(:min) { should == 1.week }
|
36
36
|
its(:max) { should == 5.weeks }
|
37
|
-
its(:unit) { should == :
|
37
|
+
its(:unit) { should == :weeks }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'month range' do
|
@@ -43,7 +43,7 @@ describe TimespanRange do
|
|
43
43
|
its(:range) { should be_a Timespan }
|
44
44
|
its(:min) { should == 1.month }
|
45
45
|
its(:max) { should == 5.months }
|
46
|
-
its(:unit) { should == :
|
46
|
+
its(:unit) { should == :months }
|
47
47
|
end
|
48
48
|
|
49
49
|
context 'year range' do
|
@@ -52,6 +52,6 @@ describe TimespanRange do
|
|
52
52
|
its(:range) { should be_a Timespan }
|
53
53
|
its(:min) { should == 1.year }
|
54
54
|
its(:max) { should == 5.years }
|
55
|
-
its(:unit) { should == :
|
55
|
+
its(:unit) { should == :years }
|
56
56
|
end
|
57
57
|
end
|
@@ -68,11 +68,11 @@ describe TimeSpan do
|
|
68
68
|
# end
|
69
69
|
|
70
70
|
it 'should have custom max_asap' do
|
71
|
-
TimePeriod.max_asap.should
|
71
|
+
TimePeriod.max_asap.should be_within(2).of(14.days.from_now.to_i)
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'should have custom min_asap' do
|
75
|
-
TimePeriod.min_asap.should == 2.days.ago.to_i
|
75
|
+
TimePeriod.min_asap.should == be_within(2).of(2.days.ago.to_i)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'should find #1, #2, #3, #4, #5' do
|
@@ -13,9 +13,10 @@ class Account
|
|
13
13
|
|
14
14
|
timespan_container_delegates :time_period, :dates, :all
|
15
15
|
|
16
|
-
def self.create_it! duration
|
16
|
+
def self.create_it! duration, flex = nil
|
17
17
|
acc = self.new period: ::Timespan.new(duration: duration), time_period: ::TimePeriod.new
|
18
18
|
acc.time_period.dates_duration = 1.day
|
19
|
+
acc.time_period.flex = flex if flex
|
19
20
|
acc
|
20
21
|
end
|
21
22
|
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'timespan/mongoid/spec_helper'
|
2
|
+
|
3
|
+
Mongoid::Timespanned.log = true
|
4
|
+
load_models!
|
5
|
+
|
6
|
+
describe TimeSpan do
|
7
|
+
subject { account }
|
8
|
+
|
9
|
+
def tomorrow
|
10
|
+
@tmrw ||= today + 1.day
|
11
|
+
end
|
12
|
+
|
13
|
+
def today
|
14
|
+
@today ||= Date.today
|
15
|
+
end
|
16
|
+
|
17
|
+
def format_date date
|
18
|
+
DateTime.parse(date.to_s).strftime('%d %b %Y')
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:from) { Chronic.parse("1 day ago") }
|
22
|
+
let(:to) { Time.now }
|
23
|
+
|
24
|
+
# context 'Timespan.from' do
|
25
|
+
# let(:account) do
|
26
|
+
# Account.create period: Timespan.from(:asap, 5.days)
|
27
|
+
# end
|
28
|
+
|
29
|
+
# describe ':asap' do
|
30
|
+
|
31
|
+
# before :all do
|
32
|
+
# # puts subject.period.inspect
|
33
|
+
# end
|
34
|
+
|
35
|
+
# describe 'state' do
|
36
|
+
# specify { subject.period.asap?.should be_true }
|
37
|
+
# end
|
38
|
+
|
39
|
+
# describe '.start_date' do
|
40
|
+
# it 'should default to today' do
|
41
|
+
# format_date(subject.period.start_date).should == format_date(today)
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
|
45
|
+
# describe '.duration' do
|
46
|
+
# it 'should be 5 days' do
|
47
|
+
# subject.period.to_days.should == 5
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
|
51
|
+
# describe '.end_date' do
|
52
|
+
# it 'should be 5 days from today' do
|
53
|
+
# format_date(subject.period.end_date).should == format_date(today + 5.days)
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
|
58
|
+
# context 'Timespan.asap' do
|
59
|
+
# let(:account) do
|
60
|
+
# Account.create period: Timespan.asap(duration: 5.days)
|
61
|
+
# end
|
62
|
+
|
63
|
+
# describe ':asap' do
|
64
|
+
# before :all do
|
65
|
+
# # puts subject.period.inspect
|
66
|
+
# end
|
67
|
+
|
68
|
+
# describe 'state' do
|
69
|
+
# specify { subject.period.asap?.should be_true }
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
context 'Timespan.new' do
|
75
|
+
let(:account) do
|
76
|
+
Account.create period: Timespan.new(duration: 5.days)
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ':asap' do
|
80
|
+
before :all do
|
81
|
+
subject.asap_for :period
|
82
|
+
puts subject.period.inspect
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should update asap' do
|
86
|
+
subject.period.asap?.should be_true
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'timespan/mongoid/spec_helper'
|
2
|
+
|
3
|
+
Mongoid::Timespanned.log = true
|
4
|
+
load_models!
|
5
|
+
|
6
|
+
describe TimeSpan do
|
7
|
+
subject { account }
|
8
|
+
|
9
|
+
def tomorrow
|
10
|
+
Date.today + 1.day
|
11
|
+
end
|
12
|
+
|
13
|
+
def format_date date
|
14
|
+
DateTime.parse(date.to_s).strftime('%d %b %Y')
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:from) { Chronic.parse("1 day ago") }
|
18
|
+
let(:to) { Time.now }
|
19
|
+
|
20
|
+
context 'Mongoid' do
|
21
|
+
describe 'DurationRange'
|
22
|
+
|
23
|
+
let(:account) do
|
24
|
+
Account.create_it! 2.days, (0..3).minutes
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'set new start_date' do
|
28
|
+
|
29
|
+
specify do
|
30
|
+
subject.period_start = tomorrow
|
31
|
+
subject.period_end = tomorrow + 5.days
|
32
|
+
|
33
|
+
subject.time_period.dates_end = tomorrow + 3.days
|
34
|
+
subject.end_date = tomorrow + 3.days
|
35
|
+
|
36
|
+
subject.time_period.flex = (0..3).minutes
|
37
|
+
|
38
|
+
|
39
|
+
# puts "time period: #{subject.time_period}"
|
40
|
+
|
41
|
+
# puts "period: #{subject.period}"
|
42
|
+
|
43
|
+
# puts "time period"
|
44
|
+
# puts "dates: #{subject.time_period.dates}"
|
45
|
+
# puts "flex: #{subject.time_period.flex}"
|
46
|
+
|
47
|
+
format_date(subject.period.start_date).should == format_date(tomorrow)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -7,7 +7,15 @@ describe TimeSpan do
|
|
7
7
|
subject { account }
|
8
8
|
|
9
9
|
def tomorrow
|
10
|
-
|
10
|
+
@tmrw ||= today + 1.day
|
11
|
+
end
|
12
|
+
|
13
|
+
def today
|
14
|
+
@today ||= Date.today
|
15
|
+
end
|
16
|
+
|
17
|
+
def format_date date
|
18
|
+
DateTime.parse(date.to_s).strftime('%d %b %Y')
|
11
19
|
end
|
12
20
|
|
13
21
|
let(:from) { Chronic.parse("1 day ago") }
|
@@ -29,31 +37,7 @@ describe TimeSpan do
|
|
29
37
|
|
30
38
|
describe '.start_date' do
|
31
39
|
it 'should default to today' do
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '.duration' do
|
37
|
-
it 'should be 5 days' do
|
38
|
-
subject.period.to_days.should == 5
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe '.end_date' do
|
43
|
-
it 'should be 5 days from today' do
|
44
|
-
DateTime.parse(subject.period.end_date.to_s).strftime('%d %b %Y').should == (Date.today + 5.days).strftime('%d %b %Y')
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ':asap' do
|
50
|
-
let(:account) do
|
51
|
-
Account.create period: Timespan.from(:asap, 5.days)
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '.start_date' do
|
55
|
-
it 'should default to today' do
|
56
|
-
DateTime.parse(subject.period.start_date.to_s).strftime('%d %b %Y').should == Date.today.strftime('%d %b %Y')
|
40
|
+
format_date(subject.period.start_date).should == format_date(today)
|
57
41
|
end
|
58
42
|
end
|
59
43
|
|
@@ -65,7 +49,7 @@ describe TimeSpan do
|
|
65
49
|
|
66
50
|
describe '.end_date' do
|
67
51
|
it 'should be 5 days from today' do
|
68
|
-
|
52
|
+
format_date(subject.period.end_date).should == format_date(today + 5.days)
|
69
53
|
end
|
70
54
|
end
|
71
55
|
end
|
@@ -77,7 +61,7 @@ describe TimeSpan do
|
|
77
61
|
|
78
62
|
describe '.start_date' do
|
79
63
|
it 'should be tomorrow' do
|
80
|
-
|
64
|
+
format_date(subject.period.start_date).should == format_date(Date.tomorrow)
|
81
65
|
end
|
82
66
|
end
|
83
67
|
|
@@ -89,7 +73,7 @@ describe TimeSpan do
|
|
89
73
|
|
90
74
|
describe '.end_date' do
|
91
75
|
it 'should be 5 days from tomorrow' do
|
92
|
-
|
76
|
+
format_date(subject.period.end_date).should == format_date(Date.tomorrow + 5.days)
|
93
77
|
end
|
94
78
|
end
|
95
79
|
end
|
@@ -101,7 +85,7 @@ describe TimeSpan do
|
|
101
85
|
|
102
86
|
describe '.start_date' do
|
103
87
|
it 'should be 1 week from today' do
|
104
|
-
|
88
|
+
format_date(subject.period.start_date).should == format_date(Date.next_week)
|
105
89
|
end
|
106
90
|
end
|
107
91
|
|
@@ -113,7 +97,7 @@ describe TimeSpan do
|
|
113
97
|
|
114
98
|
describe '.end_date' do
|
115
99
|
it 'should be 5 days from next week' do
|
116
|
-
|
100
|
+
format_date(subject.period.end_date).should == format_date(Date.next_week + 5.days)
|
117
101
|
end
|
118
102
|
end
|
119
103
|
end
|
@@ -126,7 +110,7 @@ describe TimeSpan do
|
|
126
110
|
|
127
111
|
describe '.start_date' do
|
128
112
|
it 'should default to today' do
|
129
|
-
|
113
|
+
format_date(subject.period.start_date).should == format_date(Date.today)
|
130
114
|
end
|
131
115
|
end
|
132
116
|
end
|
@@ -138,7 +122,7 @@ describe TimeSpan do
|
|
138
122
|
|
139
123
|
describe '.start_date' do
|
140
124
|
it 'should default to today' do
|
141
|
-
|
125
|
+
format_date(subject.period.start_date).should == format_date(Date.today)
|
142
126
|
end
|
143
127
|
end
|
144
128
|
end
|
@@ -150,7 +134,7 @@ describe TimeSpan do
|
|
150
134
|
|
151
135
|
describe '.start_date' do
|
152
136
|
it 'should default to today' do
|
153
|
-
|
137
|
+
format_date(subject.period.start_date).should == format_date(Date.today)
|
154
138
|
end
|
155
139
|
end
|
156
140
|
end
|
@@ -170,7 +154,7 @@ describe TimeSpan do
|
|
170
154
|
end
|
171
155
|
|
172
156
|
specify do
|
173
|
-
|
157
|
+
format_date(subject.time_period.end_date).should == format_date(tomorrow + 3.days)
|
174
158
|
end
|
175
159
|
|
176
160
|
specify do
|
@@ -186,7 +170,7 @@ describe TimeSpan do
|
|
186
170
|
end
|
187
171
|
|
188
172
|
specify do
|
189
|
-
|
173
|
+
format_date(subject.start_date).should == format_date(tomorrow)
|
190
174
|
end
|
191
175
|
end
|
192
176
|
end
|
data/timespan.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "timespan"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.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"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-11-19"
|
13
13
|
s.description = "Makes it easy to calculate time distance in different units"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/timespan/span.rb",
|
41
41
|
"lib/timespan/units.rb",
|
42
42
|
"spec/spec_helper.rb",
|
43
|
+
"spec/timespan/asap_spec.rb",
|
43
44
|
"spec/timespan/compare_spec.rb",
|
44
45
|
"spec/timespan/core_ext/duration_range_spec.rb",
|
45
46
|
"spec/timespan/core_ext/timespan_range_spec.rb",
|
@@ -49,6 +50,8 @@ Gem::Specification.new do |s|
|
|
49
50
|
"spec/timespan/mongoid/models/account_2x.rb",
|
50
51
|
"spec/timespan/mongoid/models/account_3x.rb",
|
51
52
|
"spec/timespan/mongoid/models/time_period.rb",
|
53
|
+
"spec/timespan/mongoid/mongoid_asap_spec.rb",
|
54
|
+
"spec/timespan/mongoid/mongoid_duration_range_spec.rb",
|
52
55
|
"spec/timespan/mongoid/mongoid_search_spec.rb",
|
53
56
|
"spec/timespan/mongoid/mongoid_setup.rb",
|
54
57
|
"spec/timespan/mongoid/mongoid_timespan_spec.rb",
|
@@ -76,10 +79,10 @@ Gem::Specification.new do |s|
|
|
76
79
|
s.add_runtime_dependency(%q<chronic_duration>, [">= 0"])
|
77
80
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
|
78
81
|
s.add_runtime_dependency(%q<spanner>, [">= 0"])
|
79
|
-
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.7.
|
82
|
+
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.7.3"])
|
80
83
|
s.add_runtime_dependency(%q<xduration>, ["~> 2.2"])
|
81
84
|
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
82
|
-
s.add_development_dependency(%q<rails>, ["
|
85
|
+
s.add_development_dependency(%q<rails>, [">= 3.2"])
|
83
86
|
s.add_development_dependency(%q<mongoid>, ["~> 3.0"])
|
84
87
|
s.add_development_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
|
85
88
|
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
@@ -91,10 +94,10 @@ Gem::Specification.new do |s|
|
|
91
94
|
s.add_dependency(%q<chronic_duration>, [">= 0"])
|
92
95
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
93
96
|
s.add_dependency(%q<spanner>, [">= 0"])
|
94
|
-
s.add_dependency(%q<sugar-high>, ["~> 0.7.
|
97
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.7.3"])
|
95
98
|
s.add_dependency(%q<xduration>, ["~> 2.2"])
|
96
99
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
97
|
-
s.add_dependency(%q<rails>, ["
|
100
|
+
s.add_dependency(%q<rails>, [">= 3.2"])
|
98
101
|
s.add_dependency(%q<mongoid>, ["~> 3.0"])
|
99
102
|
s.add_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
|
100
103
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
@@ -107,10 +110,10 @@ Gem::Specification.new do |s|
|
|
107
110
|
s.add_dependency(%q<chronic_duration>, [">= 0"])
|
108
111
|
s.add_dependency(%q<activesupport>, [">= 3.0.0"])
|
109
112
|
s.add_dependency(%q<spanner>, [">= 0"])
|
110
|
-
s.add_dependency(%q<sugar-high>, ["~> 0.7.
|
113
|
+
s.add_dependency(%q<sugar-high>, ["~> 0.7.3"])
|
111
114
|
s.add_dependency(%q<xduration>, ["~> 2.2"])
|
112
115
|
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
113
|
-
s.add_dependency(%q<rails>, ["
|
116
|
+
s.add_dependency(%q<rails>, [">= 3.2"])
|
114
117
|
s.add_dependency(%q<mongoid>, ["~> 3.0"])
|
115
118
|
s.add_dependency(%q<origin-selectable_ext>, ["~> 0.1.1"])
|
116
119
|
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
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.
|
4
|
+
version: 0.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chronic
|
@@ -82,7 +82,7 @@ dependencies:
|
|
82
82
|
requirements:
|
83
83
|
- - ~>
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.7.
|
85
|
+
version: 0.7.3
|
86
86
|
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -90,7 +90,7 @@ dependencies:
|
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: 0.7.
|
93
|
+
version: 0.7.3
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
95
|
name: xduration
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,17 +128,17 @@ dependencies:
|
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
none: false
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - ! '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 3.2
|
133
|
+
version: '3.2'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
none: false
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version: 3.2
|
141
|
+
version: '3.2'
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: mongoid
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,6 +266,7 @@ files:
|
|
266
266
|
- lib/timespan/span.rb
|
267
267
|
- lib/timespan/units.rb
|
268
268
|
- spec/spec_helper.rb
|
269
|
+
- spec/timespan/asap_spec.rb
|
269
270
|
- spec/timespan/compare_spec.rb
|
270
271
|
- spec/timespan/core_ext/duration_range_spec.rb
|
271
272
|
- spec/timespan/core_ext/timespan_range_spec.rb
|
@@ -275,6 +276,8 @@ files:
|
|
275
276
|
- spec/timespan/mongoid/models/account_2x.rb
|
276
277
|
- spec/timespan/mongoid/models/account_3x.rb
|
277
278
|
- spec/timespan/mongoid/models/time_period.rb
|
279
|
+
- spec/timespan/mongoid/mongoid_asap_spec.rb
|
280
|
+
- spec/timespan/mongoid/mongoid_duration_range_spec.rb
|
278
281
|
- spec/timespan/mongoid/mongoid_search_spec.rb
|
279
282
|
- spec/timespan/mongoid/mongoid_setup.rb
|
280
283
|
- spec/timespan/mongoid/mongoid_timespan_spec.rb
|
@@ -302,7 +305,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
302
305
|
version: '0'
|
303
306
|
segments:
|
304
307
|
- 0
|
305
|
-
hash:
|
308
|
+
hash: 4516363936943259477
|
306
309
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
307
310
|
none: false
|
308
311
|
requirements:
|