chronological 0.0.5 → 0.0.6
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/lib/chronological.rb +5 -116
- data/lib/chronological/absolute_timeframe.rb +98 -0
- data/lib/chronological/base.rb +41 -0
- data/lib/chronological/relative_timeframe.rb +57 -0
- data/lib/chronological/version.rb +1 -1
- data/spec/{chronological_spec.rb → absolute_timeframe_spec.rb} +72 -218
- data/spec/base_spec.rb +230 -0
- data/spec/relative_timeframe_spec.rb +207 -0
- data/spec/spec_helper.rb +15 -2
- metadata +11 -4
data/lib/chronological.rb
CHANGED
@@ -1,118 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
# and that both should validate timeliness
|
6
|
-
def chronological(options = {})
|
7
|
-
start_time_field = options[:start_utc] || options[:start]
|
8
|
-
start_date_field = start_time_field.to_s.gsub(/_at/, '_on')
|
9
|
-
end_time_field = options[:end_utc] || options[:end]
|
10
|
-
end_date_field = end_time_field.to_s.gsub(/_at/, '_on')
|
11
|
-
time_zone = options[:time_zone]
|
12
|
-
start_time_field_is_utc = options.has_key? :start_utc
|
13
|
-
end_time_field_is_utc = options.has_key? :end_utc
|
14
|
-
start_time_field_utc_suffix = start_time_field_is_utc ? '_utc' : ''
|
15
|
-
end_time_field_utc_suffix = end_time_field_is_utc ? '_utc' : ''
|
16
|
-
|
17
|
-
define_method(start_date_field) do
|
18
|
-
return nil unless send(start_time_field).respond_to? :to_date
|
19
|
-
|
20
|
-
send(start_time_field).to_date
|
21
|
-
end
|
22
|
-
|
23
|
-
define_method(end_date_field) do
|
24
|
-
return nil unless send(end_time_field).respond_to? :to_date
|
25
|
-
|
26
|
-
send(end_time_field).to_date
|
27
|
-
end
|
28
|
-
|
29
|
-
define_method(:in_progress?) do
|
30
|
-
return false unless send(start_time_field).present? && send(end_time_field).present?
|
31
|
-
|
32
|
-
(send(start_time_field) <= Time.now.utc) && send(end_time_field).future?
|
33
|
-
end
|
34
|
-
|
35
|
-
define_method(:inactive?) do
|
36
|
-
!active?
|
37
|
-
end
|
38
|
-
|
39
|
-
define_method(:scheduled?) do
|
40
|
-
optional_time_zone = !options[:time_zone].nil? ? send(time_zone) : true
|
41
|
-
|
42
|
-
send(start_time_field).present? && send(end_time_field).present? && optional_time_zone
|
43
|
-
end
|
44
|
-
|
45
|
-
define_method(:partially_scheduled?) do
|
46
|
-
optional_time_zone = !options[:time_zone].nil? ? send(time_zone) : false
|
47
|
-
|
48
|
-
send(start_time_field).present? || send(end_time_field).present? || optional_time_zone
|
49
|
-
end
|
50
|
-
|
51
|
-
define_method(:duration) do
|
52
|
-
hours = (duration_in_seconds / 3600).to_i
|
53
|
-
minutes = ((duration_in_seconds % 3600) / 60).to_i
|
54
|
-
seconds = (duration_in_seconds % 60).to_i
|
1
|
+
require 'chronological/version'
|
2
|
+
require 'chronological/base'
|
3
|
+
require 'chronological/absolute_timeframe'
|
4
|
+
require 'chronological/relative_timeframe'
|
55
5
|
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
###
|
60
|
-
# Scopes
|
61
|
-
#
|
62
|
-
self.class.send(:define_method, :by_date) do
|
63
|
-
order "#{table_name}.#{start_time_field} ASC, #{table_name}.#{end_time_field} ASC"
|
64
|
-
end
|
65
|
-
|
66
|
-
self.class.send(:define_method, :by_date_reversed) do
|
67
|
-
order "#{table_name}.#{start_time_field} DESC, #{table_name}.#{end_time_field} DESC"
|
68
|
-
end
|
69
|
-
|
70
|
-
self.class.send(:define_method, :expired) do
|
71
|
-
where("#{end_time_field} <= :now", :now => Time.now.utc)
|
72
|
-
end
|
73
|
-
|
74
|
-
self.class.send(:define_method, :current) do
|
75
|
-
where("#{end_time_field} > :now", :now => Time.now.utc)
|
76
|
-
end
|
77
|
-
|
78
|
-
self.class.send(:define_method, :in_progress) do
|
79
|
-
where("#{start_time_field} <= :now AND #{end_time_field} > :now", :now => Time.now.utc)
|
80
|
-
end
|
81
|
-
|
82
|
-
self.class.send(:define_method, :started) do
|
83
|
-
where("#{start_time_field} <= :now", :now => Time.now.utc)
|
84
|
-
end
|
85
|
-
|
86
|
-
self.class.send(:define_method, :in_progress?) do
|
87
|
-
in_progress.any?
|
88
|
-
end
|
89
|
-
|
90
|
-
instance_eval do
|
91
|
-
alias active? in_progress?
|
92
|
-
alias active in_progress
|
93
|
-
end
|
94
|
-
|
95
|
-
###
|
96
|
-
# Aliases
|
97
|
-
#
|
98
|
-
# Aliasing date methods to make code more readable
|
99
|
-
class_eval do
|
100
|
-
alias_attribute :"starts_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
101
|
-
alias_attribute :"starting_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
102
|
-
alias_attribute :"ends_at#{start_time_field_utc_suffix}", end_time_field.to_sym
|
103
|
-
alias_attribute :"ending_at#{start_time_field_utc_suffix}", end_time_field.to_sym
|
104
|
-
|
105
|
-
alias active? in_progress?
|
106
|
-
end
|
107
|
-
|
108
|
-
private
|
109
|
-
define_method(:duration_in_seconds) do
|
110
|
-
(send(end_time_field) - send(start_time_field))
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def self.included(base)
|
116
|
-
base.extend ClassMethods
|
117
|
-
end
|
6
|
+
module Chronological
|
118
7
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Chronological
|
2
|
+
module AbsoluteTimeframe
|
3
|
+
module ClassMethods
|
4
|
+
# TODO: Needs to be able to add a validation option which can do the
|
5
|
+
# typical timeliness validation such as ended_at should be after started_at
|
6
|
+
# and that both should validate timeliness
|
7
|
+
def absolute_timeframe(options = {})
|
8
|
+
start_time_field = options[:start_utc] || options[:start]
|
9
|
+
start_date_field = start_time_field.to_s.gsub(/_at/, '_on')
|
10
|
+
end_time_field = options[:end_utc] || options[:end]
|
11
|
+
end_date_field = end_time_field.to_s.gsub(/_at/, '_on')
|
12
|
+
time_zone = options[:time_zone]
|
13
|
+
start_time_field_is_utc = options.has_key? :start_utc
|
14
|
+
end_time_field_is_utc = options.has_key? :end_utc
|
15
|
+
start_time_field_utc_suffix = start_time_field_is_utc ? '_utc' : ''
|
16
|
+
end_time_field_utc_suffix = end_time_field_is_utc ? '_utc' : ''
|
17
|
+
|
18
|
+
define_method(:scheduled?) do
|
19
|
+
optional_time_zone = !options[:time_zone].nil? ? send(time_zone) : true
|
20
|
+
|
21
|
+
send(start_time_field).present? && send(end_time_field).present? && optional_time_zone
|
22
|
+
end
|
23
|
+
|
24
|
+
define_method(:partially_scheduled?) do
|
25
|
+
optional_time_zone = !options[:time_zone].nil? ? send(time_zone) : false
|
26
|
+
|
27
|
+
send(start_time_field).present? || send(end_time_field).present? || optional_time_zone
|
28
|
+
end
|
29
|
+
|
30
|
+
###
|
31
|
+
# Scopes
|
32
|
+
#
|
33
|
+
self.class.send(:define_method, :by_date) do
|
34
|
+
order "#{table_name}.#{start_time_field} ASC, #{table_name}.#{end_time_field} ASC"
|
35
|
+
end
|
36
|
+
|
37
|
+
self.class.send(:define_method, :by_date_reversed) do
|
38
|
+
order "#{table_name}.#{start_time_field} DESC, #{table_name}.#{end_time_field} DESC"
|
39
|
+
end
|
40
|
+
|
41
|
+
self.class.send(:define_method, :expired) do
|
42
|
+
where("#{end_time_field} <= :now", :now => Time.now.utc)
|
43
|
+
end
|
44
|
+
|
45
|
+
self.class.send(:define_method, :current) do
|
46
|
+
where("#{end_time_field} > :now", :now => Time.now.utc)
|
47
|
+
end
|
48
|
+
|
49
|
+
self.class.send(:define_method, :in_progress) do
|
50
|
+
where("#{start_time_field} <= :now AND #{end_time_field} > :now", :now => Time.now.utc)
|
51
|
+
end
|
52
|
+
|
53
|
+
self.class.send(:define_method, :started) do
|
54
|
+
where("#{start_time_field} <= :now", :now => Time.now.utc)
|
55
|
+
end
|
56
|
+
|
57
|
+
self.class.send(:define_method, :in_progress?) do
|
58
|
+
in_progress.any?
|
59
|
+
end
|
60
|
+
|
61
|
+
instance_eval do
|
62
|
+
alias active? in_progress?
|
63
|
+
alias active in_progress
|
64
|
+
end
|
65
|
+
|
66
|
+
###
|
67
|
+
# Aliases
|
68
|
+
#
|
69
|
+
# Aliasing date methods to make code more readable
|
70
|
+
class_eval do
|
71
|
+
alias_attribute :"starts_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
72
|
+
alias_attribute :"starting_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
73
|
+
alias_attribute :"ends_at#{start_time_field_utc_suffix}", end_time_field.to_sym
|
74
|
+
alias_attribute :"ending_at#{start_time_field_utc_suffix}", end_time_field.to_sym
|
75
|
+
end
|
76
|
+
|
77
|
+
base_timeframe start_date_field: start_date_field,
|
78
|
+
start_time_field: start_time_field,
|
79
|
+
end_date_field: end_date_field,
|
80
|
+
end_time_field: end_time_field
|
81
|
+
|
82
|
+
private
|
83
|
+
define_method(:has_absolute_timeframe?) do
|
84
|
+
send(start_time_field).present? && send(end_time_field).present?
|
85
|
+
end
|
86
|
+
|
87
|
+
define_method(:duration_in_seconds) do
|
88
|
+
(send(end_time_field) - send(start_time_field))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.included(base)
|
94
|
+
base.extend Chronological::Base
|
95
|
+
base.extend ClassMethods
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Chronological
|
2
|
+
module Base
|
3
|
+
def base_timeframe(options = {})
|
4
|
+
define_method(options[:start_date_field]) do
|
5
|
+
return nil unless send(options[:start_time_field]).respond_to? :to_date
|
6
|
+
|
7
|
+
send(options[:start_time_field]).to_date
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method(options[:end_date_field]) do
|
11
|
+
return nil unless send(options[:end_time_field]).respond_to? :to_date
|
12
|
+
|
13
|
+
send(options[:end_time_field]).to_date
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method(:inactive?) do
|
17
|
+
!active?
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method(:duration) do
|
21
|
+
return Hash.new unless duration_in_seconds.present?
|
22
|
+
|
23
|
+
hours = (duration_in_seconds / 3600).to_i
|
24
|
+
minutes = ((duration_in_seconds % 3600) / 60).to_i
|
25
|
+
seconds = (duration_in_seconds % 60).to_i
|
26
|
+
|
27
|
+
{ :hours => hours, :minutes => minutes, :seconds => seconds }
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method(:in_progress?) do
|
31
|
+
return false unless has_absolute_timeframe?
|
32
|
+
|
33
|
+
(send(options[:start_time_field]) <= Time.now.utc) && send(options[:end_time_field]).future?
|
34
|
+
end
|
35
|
+
|
36
|
+
class_eval do
|
37
|
+
alias active? in_progress?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Chronological
|
2
|
+
module RelativeTimeframe
|
3
|
+
module ClassMethods
|
4
|
+
def relative_timeframe(options = {})
|
5
|
+
base_time_field = options[:base_utc] || options[:base]
|
6
|
+
base_time_field_is_utc = options.has_key? :base_utc
|
7
|
+
time_field_utc_suffix = base_time_field_is_utc ? 'utc' : nil
|
8
|
+
|
9
|
+
start_time_field = ['started_at', time_field_utc_suffix].join('_')
|
10
|
+
end_time_field = ['ended_at', time_field_utc_suffix].join('_')
|
11
|
+
start_date_field = ['started_on', time_field_utc_suffix].join('_')
|
12
|
+
end_date_field = ['ended_on', time_field_utc_suffix].join('_')
|
13
|
+
|
14
|
+
define_method(start_time_field) do
|
15
|
+
return nil unless send(base_time_field).present? && send(options[:start]).present?
|
16
|
+
|
17
|
+
send(base_time_field) - send(options[:start])
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method(end_time_field) do
|
21
|
+
return nil unless send(base_time_field).present? && send(options[:end]).present?
|
22
|
+
|
23
|
+
send(base_time_field) - send(options[:end])
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method(:scheduled?) do
|
27
|
+
send(base_time_field).present? && send(options[:start]).present? && send(options[:end]).present?
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method(:partially_scheduled?) do
|
31
|
+
send(base_time_field).present? || send(options[:start]).present? || send(options[:end]).present?
|
32
|
+
end
|
33
|
+
|
34
|
+
base_timeframe start_date_field: start_date_field,
|
35
|
+
start_time_field: start_time_field,
|
36
|
+
end_date_field: end_date_field,
|
37
|
+
end_time_field: end_time_field
|
38
|
+
|
39
|
+
private
|
40
|
+
define_method(:has_absolute_timeframe?) do
|
41
|
+
scheduled?
|
42
|
+
end
|
43
|
+
|
44
|
+
define_method(:duration_in_seconds) do
|
45
|
+
return nil unless send(options[:start]).present? && send(options[:end]).present?
|
46
|
+
|
47
|
+
send(options[:start]) - send(options[:end])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.included(base)
|
53
|
+
base.extend Chronological::Base
|
54
|
+
base.extend ClassMethods
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class
|
4
|
-
include Chronological
|
3
|
+
class AbsoluteChronologicable < ActiveRecord::Base
|
4
|
+
include Chronological::AbsoluteTimeframe
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
absolute_timeframe :start_utc => :started_at_utc,
|
7
|
+
:end_utc => :ended_at_utc
|
8
8
|
end
|
9
9
|
|
10
10
|
class ChronologicableWithTimeZone < ActiveRecord::Base
|
11
|
-
include Chronological
|
11
|
+
include Chronological::AbsoluteTimeframe
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
absolute_timeframe :start_utc => :started_at_utc,
|
14
|
+
:end_utc => :ended_at_utc,
|
15
|
+
:time_zone => :time_zone
|
16
16
|
end
|
17
17
|
|
18
|
-
describe Chronological, :timecop => true do
|
18
|
+
describe Chronological::AbsoluteTimeframe, :timecop => true do
|
19
19
|
let(:later) { Time.local(2012, 7, 26, 6, 0, 26) }
|
20
20
|
let(:now) { Time.local(2012, 7, 26, 6, 0, 25) }
|
21
21
|
let(:past) { Time.local(2012, 7, 26, 6, 0, 24) }
|
@@ -23,13 +23,13 @@ describe Chronological, :timecop => true do
|
|
23
23
|
before { Timecop.freeze(now) }
|
24
24
|
|
25
25
|
let(:chronologicable) do
|
26
|
-
|
26
|
+
AbsoluteChronologicable.create(
|
27
27
|
:started_at_utc => start_time,
|
28
28
|
:ended_at_utc => end_time)
|
29
29
|
end
|
30
30
|
|
31
31
|
let(:chronologicable_without_enabled_time_zone) do
|
32
|
-
|
32
|
+
AbsoluteChronologicable.new(
|
33
33
|
:started_at_utc => start_time,
|
34
34
|
:ended_at_utc => end_time)
|
35
35
|
end
|
@@ -41,50 +41,50 @@ describe Chronological, :timecop => true do
|
|
41
41
|
:time_zone => time_zone)
|
42
42
|
end
|
43
43
|
|
44
|
-
it {
|
45
|
-
it {
|
46
|
-
it {
|
47
|
-
it {
|
48
|
-
it {
|
44
|
+
it { AbsoluteChronologicable.new.respond_to?(:starts_at_utc).should be_true }
|
45
|
+
it { AbsoluteChronologicable.new.respond_to?(:starting_at_utc).should be_true }
|
46
|
+
it { AbsoluteChronologicable.new.respond_to?(:ends_at_utc).should be_true }
|
47
|
+
it { AbsoluteChronologicable.new.respond_to?(:ending_at_utc).should be_true }
|
48
|
+
it { AbsoluteChronologicable.new.respond_to?(:active?).should be_true }
|
49
49
|
|
50
|
-
it {
|
51
|
-
it {
|
50
|
+
it { AbsoluteChronologicable.respond_to?(:active?).should be_true }
|
51
|
+
it { AbsoluteChronologicable.respond_to?(:active).should be_true }
|
52
52
|
|
53
53
|
context 'when there are two chronologicables that start at the same time' do
|
54
54
|
context 'but end at different times' do
|
55
|
-
let!(:chronologicable_1) {
|
56
|
-
let!(:chronologicable_2) {
|
55
|
+
let!(:chronologicable_1) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => past }
|
56
|
+
let!(:chronologicable_2) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => now }
|
57
57
|
|
58
58
|
describe '.by_date' do
|
59
59
|
it 'properly sorts them' do
|
60
|
-
|
61
|
-
|
60
|
+
AbsoluteChronologicable.by_date.first.should eql chronologicable_1
|
61
|
+
AbsoluteChronologicable.by_date.last.should eql chronologicable_2
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
65
|
describe '.by_date_reversed' do
|
66
66
|
it 'sorts them backwards by the start date' do
|
67
|
-
|
68
|
-
|
67
|
+
AbsoluteChronologicable.by_date_reversed.first.should eql chronologicable_2
|
68
|
+
AbsoluteChronologicable.by_date_reversed.last.should eql chronologicable_1
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'and end at the same time' do
|
74
|
-
let!(:chronologicable_1) {
|
75
|
-
let!(:chronologicable_2) {
|
74
|
+
let!(:chronologicable_1) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => now }
|
75
|
+
let!(:chronologicable_2) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => now }
|
76
76
|
|
77
77
|
describe '.by_date' do
|
78
78
|
it 'does not matter what order they are in as long as they are all there' do
|
79
|
-
|
80
|
-
|
79
|
+
AbsoluteChronologicable.by_date.should include chronologicable_1
|
80
|
+
AbsoluteChronologicable.by_date.should include chronologicable_2
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe '.by_date_reversed' do
|
85
85
|
it 'does not matter what order they are in as long as they are all there' do
|
86
|
-
|
87
|
-
|
86
|
+
AbsoluteChronologicable.by_date.should include chronologicable_1
|
87
|
+
AbsoluteChronologicable.by_date.should include chronologicable_2
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -92,84 +92,44 @@ describe Chronological, :timecop => true do
|
|
92
92
|
|
93
93
|
context 'when there are two chronologicables that start at different times' do
|
94
94
|
context 'and end at different times' do
|
95
|
-
let!(:chronologicable_1) {
|
96
|
-
let!(:chronologicable_2) {
|
95
|
+
let!(:chronologicable_1) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => now }
|
96
|
+
let!(:chronologicable_2) { AbsoluteChronologicable.create :started_at_utc => now, :ended_at_utc => later }
|
97
97
|
|
98
98
|
describe '.by_date' do
|
99
99
|
it 'sorts them by the start date' do
|
100
|
-
|
101
|
-
|
100
|
+
AbsoluteChronologicable.by_date.first.should eql chronologicable_1
|
101
|
+
AbsoluteChronologicable.by_date.last.should eql chronologicable_2
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
describe '.by_date_reversed' do
|
106
106
|
it 'sorts them backwards by the start date' do
|
107
|
-
|
108
|
-
|
107
|
+
AbsoluteChronologicable.by_date_reversed.first.should eql chronologicable_2
|
108
|
+
AbsoluteChronologicable.by_date_reversed.last.should eql chronologicable_1
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
113
|
context 'but end at the same time' do
|
114
|
-
let!(:chronologicable_1) {
|
115
|
-
let!(:chronologicable_2) {
|
114
|
+
let!(:chronologicable_1) { AbsoluteChronologicable.create :started_at_utc => past, :ended_at_utc => later }
|
115
|
+
let!(:chronologicable_2) { AbsoluteChronologicable.create :started_at_utc => now, :ended_at_utc => later }
|
116
116
|
|
117
117
|
describe '.by_date' do
|
118
118
|
it 'sorts them by the start date' do
|
119
|
-
|
120
|
-
|
119
|
+
AbsoluteChronologicable.by_date.first.should eql chronologicable_1
|
120
|
+
AbsoluteChronologicable.by_date.last.should eql chronologicable_2
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
describe '.by_date_reversed' do
|
125
125
|
it 'sorts them backwards by the start date' do
|
126
|
-
|
127
|
-
|
126
|
+
AbsoluteChronologicable.by_date_reversed.first.should eql chronologicable_2
|
127
|
+
AbsoluteChronologicable.by_date_reversed.last.should eql chronologicable_1
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
describe '#started_on_utc' do
|
134
|
-
context 'when the date field is set to a string' do
|
135
|
-
let(:start_time) { '2012-07-26 03:15:12' }
|
136
|
-
let(:end_time) { nil }
|
137
|
-
|
138
|
-
it 'properly converts the date' do
|
139
|
-
chronologicable.started_on_utc.should eql Time.utc(2012, 7, 26, 3, 15, 12).to_date
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'when the date field is set to a date' do
|
144
|
-
let(:start_time) { Time.utc(2012, 7, 26, 3, 15, 12) }
|
145
|
-
let(:end_time) { nil }
|
146
|
-
|
147
|
-
it 'properly converts the date' do
|
148
|
-
chronologicable.started_on_utc.should eql Time.utc(2012, 7, 26, 3, 15, 12).to_date
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '#ended_on_utc' do
|
154
|
-
context 'when the date field is set to a string' do
|
155
|
-
let(:start_time) { nil }
|
156
|
-
let(:end_time) { '2012-07-26 03:15:12' }
|
157
|
-
|
158
|
-
it 'properly converts the date' do
|
159
|
-
chronologicable.ended_on_utc.should eql Time.utc(2012, 7, 26, 3, 15, 12).to_date
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
context 'when the date field is set to a date' do
|
164
|
-
let(:start_time) { nil }
|
165
|
-
let(:end_time) { Time.utc(2012, 7, 26, 3, 15, 12) }
|
166
|
-
|
167
|
-
it 'properly converts the date' do
|
168
|
-
chronologicable.ended_on_utc.should eql Time.utc(2012, 7, 26, 3, 15, 12).to_date
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
133
|
context 'when a start time is set' do
|
174
134
|
let(:start_time) { Time.now }
|
175
135
|
|
@@ -333,40 +293,34 @@ describe Chronological, :timecop => true do
|
|
333
293
|
context 'and has already ended' do
|
334
294
|
let(:end_time) { past }
|
335
295
|
|
336
|
-
describe '#in_progress?' do
|
337
|
-
it 'is false' do
|
338
|
-
chronologicable.should_not be_in_progress
|
339
|
-
end
|
340
|
-
end
|
341
|
-
|
342
296
|
describe '.in_progress?' do
|
343
297
|
it 'is false' do
|
344
298
|
chronologicable
|
345
|
-
|
299
|
+
AbsoluteChronologicable.should_not be_in_progress
|
346
300
|
end
|
347
301
|
end
|
348
302
|
|
349
303
|
describe '.expired' do
|
350
304
|
it 'includes that chronologicable' do
|
351
|
-
|
305
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
352
306
|
end
|
353
307
|
end
|
354
308
|
|
355
309
|
describe '.started' do
|
356
310
|
it 'includes that chronologicable' do
|
357
|
-
|
311
|
+
AbsoluteChronologicable.started.should include chronologicable
|
358
312
|
end
|
359
313
|
end
|
360
314
|
|
361
315
|
describe '.current' do
|
362
316
|
it 'does not include that chronologicable' do
|
363
|
-
|
317
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
364
318
|
end
|
365
319
|
end
|
366
320
|
|
367
321
|
describe '.in_progress' do
|
368
322
|
it 'does not include that chronologicable' do
|
369
|
-
|
323
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
370
324
|
end
|
371
325
|
end
|
372
326
|
end
|
@@ -374,40 +328,34 @@ describe Chronological, :timecop => true do
|
|
374
328
|
context 'and ends now' do
|
375
329
|
let(:end_time) { now }
|
376
330
|
|
377
|
-
describe '#in_progress?' do
|
378
|
-
it 'is false' do
|
379
|
-
chronologicable.should_not be_in_progress
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
331
|
describe '.in_progress?' do
|
384
332
|
it 'is false' do
|
385
333
|
chronologicable
|
386
|
-
|
334
|
+
AbsoluteChronologicable.should_not be_in_progress
|
387
335
|
end
|
388
336
|
end
|
389
337
|
|
390
338
|
describe '.expired' do
|
391
339
|
it 'does include that chronologicable' do
|
392
|
-
|
340
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
393
341
|
end
|
394
342
|
end
|
395
343
|
|
396
344
|
describe '.started' do
|
397
345
|
it 'includes that chronologicable' do
|
398
|
-
|
346
|
+
AbsoluteChronologicable.started.should include chronologicable
|
399
347
|
end
|
400
348
|
end
|
401
349
|
|
402
350
|
describe '.current' do
|
403
351
|
it 'does not include that chronologicable' do
|
404
|
-
|
352
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
405
353
|
end
|
406
354
|
end
|
407
355
|
|
408
356
|
describe '.in_progress' do
|
409
357
|
it 'does not include that chronologicable' do
|
410
|
-
|
358
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
411
359
|
end
|
412
360
|
end
|
413
361
|
end
|
@@ -415,40 +363,34 @@ describe Chronological, :timecop => true do
|
|
415
363
|
context 'and ends later' do
|
416
364
|
let(:end_time) { later }
|
417
365
|
|
418
|
-
describe '#in_progress?' do
|
419
|
-
it 'is true' do
|
420
|
-
chronologicable.should be_in_progress
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
366
|
describe '.in_progress?' do
|
425
367
|
it 'is true' do
|
426
368
|
chronologicable
|
427
|
-
|
369
|
+
AbsoluteChronologicable.should be_in_progress
|
428
370
|
end
|
429
371
|
end
|
430
372
|
|
431
373
|
describe '.expired' do
|
432
374
|
it 'does not include that chronologicable' do
|
433
|
-
|
375
|
+
AbsoluteChronologicable.expired.should_not include chronologicable
|
434
376
|
end
|
435
377
|
end
|
436
378
|
|
437
379
|
describe '.started' do
|
438
380
|
it 'includes that chronologicable' do
|
439
|
-
|
381
|
+
AbsoluteChronologicable.started.should include chronologicable
|
440
382
|
end
|
441
383
|
end
|
442
384
|
|
443
385
|
describe '.current' do
|
444
386
|
it 'includes that chronologicable' do
|
445
|
-
|
387
|
+
AbsoluteChronologicable.current.should include chronologicable
|
446
388
|
end
|
447
389
|
end
|
448
390
|
|
449
391
|
describe '.in_progress' do
|
450
392
|
it 'includes that chronologicable' do
|
451
|
-
|
393
|
+
AbsoluteChronologicable.in_progress.should include chronologicable
|
452
394
|
end
|
453
395
|
end
|
454
396
|
end
|
@@ -460,40 +402,34 @@ describe Chronological, :timecop => true do
|
|
460
402
|
context 'and ends now' do
|
461
403
|
let(:end_time) { now }
|
462
404
|
|
463
|
-
describe '#in_progress?' do
|
464
|
-
it 'is false' do
|
465
|
-
chronologicable.should_not be_in_progress
|
466
|
-
end
|
467
|
-
end
|
468
|
-
|
469
405
|
describe '.in_progress?' do
|
470
406
|
it 'is false' do
|
471
407
|
chronologicable
|
472
|
-
|
408
|
+
AbsoluteChronologicable.should_not be_in_progress
|
473
409
|
end
|
474
410
|
end
|
475
411
|
|
476
412
|
describe '.expired' do
|
477
413
|
it 'does include that chronologicable' do
|
478
|
-
|
414
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
479
415
|
end
|
480
416
|
end
|
481
417
|
|
482
418
|
describe '.started' do
|
483
419
|
it 'includes that chronologicable' do
|
484
|
-
|
420
|
+
AbsoluteChronologicable.started.should include chronologicable
|
485
421
|
end
|
486
422
|
end
|
487
423
|
|
488
424
|
describe '.current' do
|
489
425
|
it 'does not include that chronologicable' do
|
490
|
-
|
426
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
491
427
|
end
|
492
428
|
end
|
493
429
|
|
494
430
|
describe '.in_progress' do
|
495
431
|
it 'does not include that chronologicable' do
|
496
|
-
|
432
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
497
433
|
end
|
498
434
|
end
|
499
435
|
end
|
@@ -501,40 +437,34 @@ describe Chronological, :timecop => true do
|
|
501
437
|
context 'and ends later' do
|
502
438
|
let(:end_time) { later }
|
503
439
|
|
504
|
-
describe '#in_progress?' do
|
505
|
-
it 'is true' do
|
506
|
-
chronologicable.should be_in_progress
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
440
|
describe '.in_progress?' do
|
511
441
|
it 'is true' do
|
512
442
|
chronologicable
|
513
|
-
|
443
|
+
AbsoluteChronologicable.should be_in_progress
|
514
444
|
end
|
515
445
|
end
|
516
446
|
|
517
447
|
describe '.expired' do
|
518
448
|
it 'does not include that chronologicable' do
|
519
|
-
|
449
|
+
AbsoluteChronologicable.expired.should_not include chronologicable
|
520
450
|
end
|
521
451
|
end
|
522
452
|
|
523
453
|
describe '.started' do
|
524
454
|
it 'includes that chronologicable' do
|
525
|
-
|
455
|
+
AbsoluteChronologicable.started.should include chronologicable
|
526
456
|
end
|
527
457
|
end
|
528
458
|
|
529
459
|
describe '.current' do
|
530
460
|
it 'includes that chronologicable' do
|
531
|
-
|
461
|
+
AbsoluteChronologicable.current.should include chronologicable
|
532
462
|
end
|
533
463
|
end
|
534
464
|
|
535
465
|
describe '.in_progress' do
|
536
466
|
it 'includes that chronologicable' do
|
537
|
-
|
467
|
+
AbsoluteChronologicable.in_progress.should include chronologicable
|
538
468
|
end
|
539
469
|
end
|
540
470
|
end
|
@@ -544,110 +474,34 @@ describe Chronological, :timecop => true do
|
|
544
474
|
let(:start_time) { later }
|
545
475
|
let(:end_time) { later }
|
546
476
|
|
547
|
-
describe '#in_progress?' do
|
548
|
-
it 'is false' do
|
549
|
-
chronologicable.should_not be_in_progress
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
477
|
describe '.in_progress?' do
|
554
478
|
it 'is false' do
|
555
479
|
chronologicable
|
556
|
-
|
480
|
+
AbsoluteChronologicable.should_not be_in_progress
|
557
481
|
end
|
558
482
|
end
|
559
483
|
|
560
484
|
describe '.expired' do
|
561
485
|
it 'does not include that chronologicable' do
|
562
|
-
|
486
|
+
AbsoluteChronologicable.expired.should_not include chronologicable
|
563
487
|
end
|
564
488
|
end
|
565
489
|
|
566
490
|
describe '.started' do
|
567
491
|
it 'does not include that chronologicable' do
|
568
|
-
|
492
|
+
AbsoluteChronologicable.started.should_not include chronologicable
|
569
493
|
end
|
570
494
|
end
|
571
495
|
|
572
496
|
describe '.current' do
|
573
497
|
it 'includes that chronologicable' do
|
574
|
-
|
498
|
+
AbsoluteChronologicable.current.should include chronologicable
|
575
499
|
end
|
576
500
|
end
|
577
501
|
|
578
502
|
describe '.in_progress' do
|
579
503
|
it 'does not include that chronologicable' do
|
580
|
-
|
581
|
-
end
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
|
-
describe '#duration' do
|
586
|
-
context 'when the chronologicable represents something with a complex time duration' do
|
587
|
-
let(:start_time) { Time.local(2012, 7, 26, 14, 13, 16) }
|
588
|
-
let(:end_time) { Time.local(2012, 7, 26, 15, 57, 39) }
|
589
|
-
|
590
|
-
it 'is a hash with the correct hours' do
|
591
|
-
chronologicable.duration[:hours].should eql 1
|
592
|
-
end
|
593
|
-
|
594
|
-
it 'is a hash with the correct minutes' do
|
595
|
-
chronologicable.duration[:minutes].should eql 44
|
596
|
-
end
|
597
|
-
|
598
|
-
it 'is a hash with the correct seconds' do
|
599
|
-
chronologicable.duration[:seconds].should eql 23
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
context 'when the chronologicable represents something with an even second time duration' do
|
604
|
-
let(:start_time) { Time.local(2012, 7, 26, 14, 13, 16) }
|
605
|
-
let(:end_time) { Time.local(2012, 7, 26, 15, 57, 16) }
|
606
|
-
|
607
|
-
it 'is a hash with the correct hours' do
|
608
|
-
chronologicable.duration[:hours].should eql 1
|
609
|
-
end
|
610
|
-
|
611
|
-
it 'is a hash with the correct minutes' do
|
612
|
-
chronologicable.duration[:minutes].should eql 44
|
613
|
-
end
|
614
|
-
|
615
|
-
it 'is a hash with the correct seconds' do
|
616
|
-
chronologicable.duration[:seconds].should eql 0
|
617
|
-
end
|
618
|
-
end
|
619
|
-
|
620
|
-
context 'when the chronologicable represents something with an even minute time duration' do
|
621
|
-
let(:start_time) { Time.local(2012, 7, 26, 14, 13, 16) }
|
622
|
-
let(:end_time) { Time.local(2012, 7, 26, 15, 13, 16) }
|
623
|
-
|
624
|
-
it 'is a hash with the correct hours' do
|
625
|
-
chronologicable.duration[:hours].should eql 1
|
626
|
-
end
|
627
|
-
|
628
|
-
it 'is a hash with the correct minutes' do
|
629
|
-
chronologicable.duration[:minutes].should eql 0
|
630
|
-
end
|
631
|
-
|
632
|
-
it 'is a hash with the correct seconds' do
|
633
|
-
chronologicable.duration[:seconds].should eql 0
|
634
|
-
end
|
635
|
-
end
|
636
|
-
|
637
|
-
context 'when the chronologicable represents something with a zero duration' do
|
638
|
-
let(:start_time) { Time.local(2012, 7, 26, 14, 13, 16) }
|
639
|
-
let(:end_time) { Time.local(2012, 7, 26, 14, 13, 16) }
|
640
|
-
|
641
|
-
it 'is a hash with the correct hours' do
|
642
|
-
chronologicable.duration[:hours].should eql 0
|
643
|
-
end
|
644
|
-
|
645
|
-
it 'is a hash with the correct minutes' do
|
646
|
-
chronologicable.duration[:minutes].should eql 0
|
647
|
-
end
|
648
|
-
|
649
|
-
it 'is a hash with the correct seconds' do
|
650
|
-
chronologicable.duration[:seconds].should eql 0
|
504
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
651
505
|
end
|
652
506
|
end
|
653
507
|
end
|