timely 0.0.2 → 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -12
- data/README.md +5 -0
- data/Rakefile +1 -139
- data/gemfiles/rails3.gemfile +8 -0
- data/gemfiles/rails4.gemfile +9 -0
- data/lib/timely.rb +7 -3
- data/lib/timely/date.rb +20 -0
- data/lib/timely/date_chooser.rb +10 -5
- data/lib/timely/date_range.rb +47 -10
- data/lib/timely/rails.rb +10 -3
- data/lib/timely/rails/calendar_tag.rb +52 -0
- data/lib/timely/rails/date.rb +5 -0
- data/lib/timely/rails/date_group.rb +68 -99
- data/lib/timely/rails/date_range_validity_module.rb +27 -0
- data/lib/timely/rails/date_time.rb +20 -0
- data/lib/timely/rails/extensions.rb +23 -11
- data/lib/timely/rails/period.rb +31 -0
- data/lib/timely/rails/season.rb +65 -75
- data/lib/timely/railtie.rb +7 -0
- data/lib/timely/temporal_patterns/finder.rb +152 -0
- data/lib/timely/temporal_patterns/frequency.rb +108 -0
- data/lib/timely/temporal_patterns/interval.rb +67 -0
- data/lib/timely/temporal_patterns/pattern.rb +160 -0
- data/lib/timely/time_since.rb +17 -0
- data/lib/timely/version.rb +3 -0
- data/spec/calendar_tag_spec.rb +29 -0
- data/spec/date_chooser_spec.rb +36 -27
- data/spec/date_group_spec.rb +9 -9
- data/spec/date_range_spec.rb +58 -20
- data/spec/date_spec.rb +20 -12
- data/spec/extensions_spec.rb +32 -0
- data/spec/rails/date_spec.rb +16 -0
- data/spec/rails/date_time_spec.rb +20 -0
- data/spec/rails/period_spec.rb +17 -0
- data/spec/schema.rb +5 -0
- data/spec/season_spec.rb +21 -24
- data/spec/spec_helper.rb +5 -20
- data/spec/string_spec.rb +4 -3
- data/spec/support/coverage.rb +26 -0
- data/spec/temporal_patterns_spec.rb +28 -0
- data/spec/time_since_spec.rb +24 -0
- data/spec/time_spec.rb +14 -14
- data/spec/trackable_date_set_spec.rb +14 -14
- data/spec/week_days_spec.rb +18 -18
- data/timely.gemspec +34 -98
- metadata +244 -21
- data/lib/timely/temporal_patterns.rb +0 -441
@@ -0,0 +1,17 @@
|
|
1
|
+
module Timely
|
2
|
+
module TimeSince
|
3
|
+
def seconds_since
|
4
|
+
::DateTime.now.to_i - self.to_i
|
5
|
+
end
|
6
|
+
|
7
|
+
def minutes_since
|
8
|
+
seconds_since/60
|
9
|
+
end
|
10
|
+
|
11
|
+
def hours_since
|
12
|
+
minutes_since/60
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
DateTime.send :include, Timely::TimeSince
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ActionViewTest
|
4
|
+
include Timely::ActionViewHelpers::FormTagHelper
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Timely::ActionViewHelpers do
|
8
|
+
subject { ActionViewTest.new }
|
9
|
+
let(:string) { double(:string) }
|
10
|
+
let(:date) { Date.new(2000, 12, 25) }
|
11
|
+
before {
|
12
|
+
expect(date).to receive(:to_s).with(:calendar).and_return('25-12-2000')
|
13
|
+
expect(Timely).to receive(:current_date).and_return(date)
|
14
|
+
}
|
15
|
+
|
16
|
+
it 'should generate calendar tags' do
|
17
|
+
expect(string).to receive(:html_safe)
|
18
|
+
expect(subject).to receive(:tag).with(:input,
|
19
|
+
:id => 'test',
|
20
|
+
:class => 'datepicker input-small',
|
21
|
+
:size => 10,
|
22
|
+
:maxlength => 10,
|
23
|
+
:name => 'test',
|
24
|
+
:type => 'text',
|
25
|
+
:value => '25-12-2000'
|
26
|
+
).and_return(string)
|
27
|
+
subject.calendar_tag :test
|
28
|
+
end
|
29
|
+
end
|
data/spec/date_chooser_spec.rb
CHANGED
@@ -8,61 +8,70 @@ describe Timely::DateChooser do
|
|
8
8
|
|
9
9
|
#Validation
|
10
10
|
it "rejects blank FROM dates" do
|
11
|
-
|
11
|
+
expect { Timely::DateChooser.new({:from=>""}) }.to raise_error(
|
12
|
+
Timely::DateChooserException, 'A Start Date is required')
|
12
13
|
end
|
13
14
|
|
14
15
|
it "rejects TO dates later than FROM dates" do
|
15
|
-
|
16
|
+
expect {Timely::DateChooser.new(
|
16
17
|
:multiple_dates => true, :from => @from + 10, :to => @from
|
17
|
-
)}.
|
18
|
+
)}.to raise_error(Timely::DateChooserException, 'Start Date is after End Date')
|
18
19
|
end
|
19
20
|
|
20
21
|
#Operation
|
21
22
|
it "returns today if client only wants single date" do
|
22
|
-
Timely::DateChooser.new(
|
23
|
+
expect(Timely::DateChooser.new(
|
23
24
|
:multiple_dates => false, :from => @from
|
24
|
-
).choose_dates.
|
25
|
+
).choose_dates).to eq [@from]
|
25
26
|
end
|
26
27
|
|
27
28
|
#Test specific date of month
|
28
29
|
it "returns from and to as same (one) day in the case that only from date is given" do
|
29
|
-
Timely::DateChooser.new(
|
30
|
+
expect(Timely::DateChooser.new(
|
30
31
|
:multiple_dates => true, :from => @from, :to => ''
|
31
|
-
).choose_dates.
|
32
|
+
).choose_dates).to eq [@from]
|
32
33
|
end
|
33
34
|
|
34
35
|
it "returns all days between from and to days in the basic case" do
|
35
|
-
Timely::DateChooser.new(
|
36
|
+
expect(Timely::DateChooser.new(
|
36
37
|
:multiple_dates => true, :from => @from, :to => @to
|
37
|
-
).choose_dates.
|
38
|
+
).choose_dates).to eq (@from..@to).to_a
|
38
39
|
end
|
39
40
|
|
40
|
-
it "returns the
|
41
|
-
Timely::DateChooser.new(
|
41
|
+
it "returns the recurring dates within the range if this option is picked" do
|
42
|
+
expect(Timely::DateChooser.new(
|
42
43
|
:multiple_dates => true, :select => 'days', :dates => '1,11,3', :from => @from, :to => @to
|
43
|
-
).choose_dates.
|
44
|
+
).choose_dates).to eq [
|
44
45
|
"1-01-2011", "3-01-2011", "11-01-2011", "1-02-2011",
|
45
46
|
"3-02-2011", "11-02-2011", "1-03-2011"
|
46
47
|
].map(&:to_date)
|
47
48
|
end
|
48
49
|
|
50
|
+
it "returns the specific dates, within or outside of the range, if this option is picked" do
|
51
|
+
expect(Timely::DateChooser.new(
|
52
|
+
:multiple_dates => true, :select => 'specific_days', :specific_dates => '11-01-2011, 18-02-2011, 22-06-2011', :from => @from, :to => @to
|
53
|
+
).choose_dates).to eq [
|
54
|
+
"11-01-2011", "18-02-2011", "22-06-2011"
|
55
|
+
].map(&:to_date)
|
56
|
+
end
|
57
|
+
|
49
58
|
#Test days of week, every X weeks
|
50
59
|
it "returns every sunday correctly" do
|
51
|
-
Timely::DateChooser.new(
|
60
|
+
expect(Timely::DateChooser.new(
|
52
61
|
:multiple_dates => true, :select => 'weekdays', :from => @from, :to => @to,
|
53
|
-
:interval => {:level => "1", :unit => "
|
54
|
-
).choose_dates.
|
62
|
+
:interval => {:level => "1", :unit => "week"}, :weekdays => {:sun => true}
|
63
|
+
).choose_dates).to eq [
|
55
64
|
"2-01-2011", "9-01-2011", "16-01-2011", "23-01-2011", "30-01-2011",
|
56
65
|
"06-02-2011", "13-02-2011", "20-02-2011", "27-02-2011"
|
57
66
|
].map(&:to_date)
|
58
67
|
end
|
59
68
|
|
60
69
|
it "returns every thursday and sunday correctly" do
|
61
|
-
Timely::DateChooser.new(
|
70
|
+
expect(Timely::DateChooser.new(
|
62
71
|
:multiple_dates => true, :select => 'weekdays',
|
63
|
-
:interval => {:level => "1", :unit => "
|
72
|
+
:interval => {:level => "1", :unit => "week"},
|
64
73
|
:weekdays => {:sun => true, :thu => true}, :from => @from, :to => @to
|
65
|
-
).choose_dates.
|
74
|
+
).choose_dates).to eq [
|
66
75
|
"2-01-2011", "6-01-2011", "9-01-2011", "13-01-2011", "16-01-2011",
|
67
76
|
"20-01-2011", "23-01-2011", "27-01-2011", "30-01-2011", "3-02-2011",
|
68
77
|
"06-02-2011", "10-02-2011", "13-02-2011", "17-02-2011", "20-02-2011",
|
@@ -71,11 +80,11 @@ describe Timely::DateChooser do
|
|
71
80
|
end
|
72
81
|
|
73
82
|
it "returns every 2nd thursday and sunday correctly" do
|
74
|
-
Timely::DateChooser.new(
|
83
|
+
expect(Timely::DateChooser.new(
|
75
84
|
:multiple_dates => true, :select => 'weekdays',
|
76
|
-
:interval => {:level => "2", :unit => "
|
85
|
+
:interval => {:level => "2", :unit => "week"},
|
77
86
|
:weekdays => {:sun => "1", :thu => "1"}, :from => @from, :to => @to
|
78
|
-
).choose_dates.
|
87
|
+
).choose_dates).to eq [
|
79
88
|
"2-01-2011", "6-01-2011", "16-01-2011", "20-01-2011", "30-01-2011",
|
80
89
|
"3-02-2011", "13-02-2011", "17-02-2011", "27-02-2011"
|
81
90
|
].map(&:to_date)
|
@@ -83,18 +92,18 @@ describe Timely::DateChooser do
|
|
83
92
|
|
84
93
|
#Test correct results for every Nth week of month
|
85
94
|
it "returns every 1st Tuesday" do
|
86
|
-
Timely::DateChooser.new(
|
95
|
+
expect(Timely::DateChooser.new(
|
87
96
|
:multiple_dates => true, :select => 'weekdays', :from => @from, :to => @to,
|
88
|
-
:interval => {:level => "1", :unit => "
|
89
|
-
).choose_dates.
|
97
|
+
:interval => {:level => "1", :unit => "week_of_month"}, :weekdays => {:tue => true}
|
98
|
+
).choose_dates).to eq ["4-01-2011", "1-02-2011", "1-03-2011"].map(&:to_date)
|
90
99
|
end
|
91
100
|
|
92
101
|
it "returns every 3st Monday and Friday" do
|
93
|
-
Timely::DateChooser.new(
|
102
|
+
expect(Timely::DateChooser.new(
|
94
103
|
:multiple_dates => true, :select => 'weekdays',
|
95
|
-
:interval => {:level => "3", :unit => "
|
104
|
+
:interval => {:level => "3", :unit => "week_of_month"},
|
96
105
|
:weekdays => {:mon => true, :fri => true}, :from => @from, :to => @to
|
97
|
-
).choose_dates.
|
106
|
+
).choose_dates).to eq [
|
98
107
|
"17-01-2011", "21-01-2011", "18-02-2011", "21-02-2011"
|
99
108
|
].map(&:to_date)
|
100
109
|
end
|
data/spec/date_group_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
describe Timely::DateGroup do
|
3
3
|
before do
|
4
|
-
@date_group = Timely::DateGroup.
|
4
|
+
@date_group = Timely::DateGroup.new(
|
5
5
|
:start_date => '2000-01-01', :end_date => '2000-01-03', :weekdays => %w(1 1 1 1 1 1 1)
|
6
6
|
)
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should detect overlaps' do
|
10
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-01'.to_date)).
|
11
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-06'.to_date)).
|
12
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2001-01-01'.to_date, '2001-01-01'.to_date)).
|
13
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('1999-12-29'.to_date, '2000-01-05'.to_date)).
|
10
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-01'.to_date))).to be true
|
11
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-06'.to_date))).to be true
|
12
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2001-01-01'.to_date, '2001-01-01'.to_date))).to be false
|
13
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('1999-12-29'.to_date, '2000-01-05'.to_date))).to be true
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should detect overlaps when certain weekdays aren't selected" do
|
@@ -18,9 +18,9 @@ describe Timely::DateGroup do
|
|
18
18
|
:start_date => '2012-01-01', :end_date => '2012-01-07', :weekdays => %w(1 0 1 0 1 0 1)
|
19
19
|
)
|
20
20
|
# Note: 2012-01-1 is a Sunday
|
21
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-01'.to_date)).
|
22
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-02'.to_date, '2012-01-02'.to_date)).
|
23
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-03'.to_date, '2012-01-03'.to_date)).
|
24
|
-
@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-03'.to_date)).
|
21
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-01'.to_date))).to be true
|
22
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-02'.to_date, '2012-01-02'.to_date))).to be false
|
23
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-03'.to_date, '2012-01-03'.to_date))).to be true
|
24
|
+
expect(@date_group.applicable_for_duration?(Timely::DateRange.new('2012-01-01'.to_date, '2012-01-03'.to_date))).to be true
|
25
25
|
end
|
26
26
|
end
|
data/spec/date_range_spec.rb
CHANGED
@@ -3,38 +3,76 @@ require 'spec_helper'
|
|
3
3
|
describe Timely::DateRange do
|
4
4
|
|
5
5
|
it "should allow initialization with two dates" do
|
6
|
-
|
7
|
-
@date_range.start_date.
|
8
|
-
@date_range.end_date.
|
6
|
+
expect { @date_range = Timely::DateRange.new(Date.today, Date.today + 3) }.to_not raise_error
|
7
|
+
expect(@date_range.start_date).to eq Date.today
|
8
|
+
expect(@date_range.end_date).to eq Date.today + 3
|
9
|
+
expect(@date_range.number_of_nights).to eq 4
|
9
10
|
end
|
10
11
|
|
11
12
|
it "should allow initialization with one date" do
|
12
|
-
|
13
|
-
@date_range.start_date.
|
14
|
-
@date_range.end_date.
|
13
|
+
expect { @date_range = Timely::DateRange.new(Date.today) }.to_not raise_error
|
14
|
+
expect(@date_range.start_date).to eq Date.today
|
15
|
+
expect(@date_range.end_date).to eq Date.today
|
16
|
+
expect(@date_range.number_of_nights).to eq 1
|
15
17
|
end
|
16
18
|
|
17
19
|
it "should allow initialization with a range" do
|
18
|
-
|
19
|
-
@date_range.start_date.
|
20
|
-
@date_range.end_date.
|
20
|
+
expect { @date_range = Timely::DateRange.new(Date.today..Date.today + 3) }.to_not raise_error
|
21
|
+
expect(@date_range.start_date).to eq Date.today
|
22
|
+
expect(@date_range.end_date).to eq Date.today + 3
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should print a readable version of time between two dates' do
|
26
|
+
expect(Timely::DateRange.new('2000-01-04'.to_date, '2000-01-04'.to_date).to_s).to eq '2000-01-04'
|
27
|
+
expect(Timely::DateRange.new('2000-01-04'.to_date, '2000-01-06'.to_date).to_s).to eq '2000-01-04 to 2000-01-06 (inclusive)'
|
28
|
+
expect(Timely::DateRange.new('2000-01-01'.to_date, '2000-05-31'.to_date).to_s).to eq 'Jan 2000 to May 2000'
|
29
|
+
expect(Timely::DateRange.new('2000-01-01'.to_date, '2000-01-31'.to_date).to_s).to eq 'Jan 2000'
|
30
|
+
Date::DATE_FORMATS[:short] = '%Y-%m-%d'
|
31
|
+
expect(Timely::DateRange.to_s('2000-01-01'.to_date, nil)).to eq 'on or after 2000-01-01'
|
32
|
+
expect(Timely::DateRange.to_s(nil, '2000-01-31'.to_date)).to eq 'on or before 2000-01-31'
|
33
|
+
expect(Timely::DateRange.to_s(nil, nil)).to eq 'no date range'
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:fourth) { '2000-01-04'.to_date }
|
37
|
+
let(:fifth) { '2000-01-05'.to_date }
|
38
|
+
let(:sixth) { '2000-01-06'.to_date }
|
39
|
+
|
40
|
+
it 'should print a readable version of time between two times' do
|
41
|
+
expect(Timely::DateRange.to_s(fourth.at(9, 30), sixth.at(4, 20)))
|
42
|
+
.to eq '2000-01-04 09:30 to 2000-01-06 04:20'
|
43
|
+
expect(Timely::DateRange.to_s(fourth.at(9, 30)))
|
44
|
+
.to eq 'on or after 2000-01-04 09:30'
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should handle params' do
|
48
|
+
today = Timely::DateRange.from_params('2000-01-04')
|
49
|
+
expect(today.first).to eq '2000-01-04'.to_date
|
50
|
+
expect(today.last).to eq '2000-01-04'.to_date
|
51
|
+
|
52
|
+
today = Timely::DateRange.from_params('2000-01-04', '2')
|
53
|
+
expect(today.first).to eq '2000-01-04'.to_date
|
54
|
+
expect(today.last).to eq '2000-01-05'.to_date
|
55
|
+
|
56
|
+
today = Timely::DateRange.from_params('2000-01-04', 2)
|
57
|
+
expect(today.first).to eq '2000-01-04'.to_date
|
58
|
+
expect(today.last).to eq '2000-01-05'.to_date
|
21
59
|
end
|
22
60
|
|
23
61
|
it "should correctly find the interesection between two date ranges" do
|
24
62
|
@date_range = Timely::DateRange.new("2000-01-03".to_date, "2000-01-06".to_date)
|
25
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-07".to_date)).
|
26
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-02".to_date)).
|
27
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-03".to_date)).
|
28
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-06".to_date, "2000-01-07".to_date)).
|
29
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-06".to_date, "2000-01-07".to_date)).
|
30
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-05".to_date)).
|
31
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-05".to_date, "2000-01-05".to_date)).
|
63
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-07".to_date))).to eq ("2000-01-04".to_date.."2000-01-06".to_date)
|
64
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-02".to_date))).to eq []
|
65
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-03".to_date))).to eq ("2000-01-03".to_date.."2000-01-03".to_date)
|
66
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-06".to_date, "2000-01-07".to_date))).to eq ("2000-01-06".to_date.."2000-01-06".to_date)
|
67
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-06".to_date, "2000-01-07".to_date))).to eq ("2000-01-06".to_date.."2000-01-06".to_date)
|
68
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-05".to_date))).to eq ("2000-01-04".to_date.."2000-01-05".to_date)
|
69
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-05".to_date, "2000-01-05".to_date))).to eq ("2000-01-05".to_date.."2000-01-05".to_date)
|
32
70
|
|
33
71
|
@date_range = Timely::DateRange.new("2000-01-03".to_date, "2000-01-03".to_date)
|
34
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-07".to_date)).
|
35
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-03".to_date)).
|
36
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-03".to_date, "2000-01-05".to_date)).
|
37
|
-
@date_range.intersecting_dates(Timely::DateRange.new("2000-01-02".to_date, "2000-01-04".to_date)).
|
72
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-04".to_date, "2000-01-07".to_date))).to eq []
|
73
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-01".to_date, "2000-01-03".to_date))).to eq ("2000-01-03".to_date.."2000-01-03".to_date)
|
74
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-03".to_date, "2000-01-05".to_date))).to eq ("2000-01-03".to_date.."2000-01-03".to_date)
|
75
|
+
expect(@date_range.intersecting_dates(Timely::DateRange.new("2000-01-02".to_date, "2000-01-04".to_date))).to eq ("2000-01-03".to_date.."2000-01-03".to_date)
|
38
76
|
end
|
39
77
|
|
40
78
|
end
|
data/spec/date_spec.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
describe Date do
|
4
|
+
it 'should determine if date between' do
|
5
|
+
expect(Date.today.between?(nil, nil)).to be true
|
6
|
+
expect(Date.today.between?(Date.today - 1, Date.today - 1)).to be false
|
7
|
+
expect(Date.today.between?(Date.today - 1, nil)).to be true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
3
11
|
describe Date do
|
4
12
|
before :each do
|
5
13
|
@date = Date.today - 5
|
@@ -10,59 +18,59 @@ describe Date do
|
|
10
18
|
end
|
11
19
|
|
12
20
|
it 'should give a time on that date' do
|
13
|
-
@date.
|
21
|
+
expect(@date).to respond_to(:at_time)
|
14
22
|
end
|
15
23
|
|
16
24
|
describe 'giving a time on that date' do
|
17
25
|
it 'should accept hour, minute, and second' do
|
18
|
-
|
26
|
+
expect { @date.at_time(@hour, @minute, @second) }.to_not raise_error
|
19
27
|
end
|
20
28
|
|
21
29
|
it 'should accept hour and minute' do
|
22
|
-
|
30
|
+
expect { @date.at_time(@hour, @minute) }.to_not raise_error
|
23
31
|
end
|
24
32
|
|
25
33
|
it 'should accept hour' do
|
26
|
-
|
34
|
+
expect { @date.at_time(@hour) }.to_not raise_error
|
27
35
|
end
|
28
36
|
|
29
37
|
it 'should accept no arguments' do
|
30
|
-
|
38
|
+
expect { @date.at_time }.to_not raise_error
|
31
39
|
end
|
32
40
|
|
33
41
|
it 'should return a time for the given hour, minute, and second if all three are specified' do
|
34
42
|
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, @second)
|
35
|
-
@date.at_time(@hour, @minute, @second).
|
43
|
+
expect(@date.at_time(@hour, @minute, @second)).to eq expected
|
36
44
|
end
|
37
45
|
|
38
46
|
it 'should default second to 0 if unspecified' do
|
39
47
|
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, 0)
|
40
|
-
@date.at_time(@hour, @minute).
|
48
|
+
expect(@date.at_time(@hour, @minute)).to eq expected
|
41
49
|
end
|
42
50
|
|
43
51
|
it 'should default minute to 0 if unspecified' do
|
44
52
|
expected = Time.local(@date.year, @date.month, @date.day, @hour, 0, 0)
|
45
|
-
@date.at_time(@hour).
|
53
|
+
expect(@date.at_time(@hour)).to eq expected
|
46
54
|
end
|
47
55
|
|
48
56
|
it 'should default hour to 0 if unspecified' do
|
49
57
|
expected = Time.local(@date.year, @date.month, @date.day, 0, 0, 0)
|
50
|
-
@date.at_time.
|
58
|
+
expect(@date.at_time).to eq expected
|
51
59
|
end
|
52
60
|
|
53
61
|
it 'should accept a time' do
|
54
|
-
|
62
|
+
expect { @date.at_time(Time.now) }.to_not raise_error
|
55
63
|
end
|
56
64
|
|
57
65
|
it 'should return the passed-in time on the date' do
|
58
66
|
@time = Time.now - 12345
|
59
67
|
expected = Time.local(@date.year, @date.month, @date.day, @time.hour, @time.min, @time.sec)
|
60
|
-
@date.at_time(@time).
|
68
|
+
expect(@date.at_time(@time)).to eq expected
|
61
69
|
end
|
62
70
|
end
|
63
71
|
|
64
72
|
it "should provide 'at' as an alias" do
|
65
73
|
expected = Time.local(@date.year, @date.month, @date.day, @hour, @minute, @second)
|
66
|
-
@date.at(@hour, @minute, @second).
|
74
|
+
expect(@date.at(@hour, @minute, @second)).to eq expected
|
67
75
|
end
|
68
76
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timely/rails/extensions'
|
3
|
+
|
4
|
+
describe Timely::Extensions do
|
5
|
+
before do
|
6
|
+
class TimelyExtensionsTestSeasonal < ActiveRecord::Base
|
7
|
+
self.table_name = 'seasonals'
|
8
|
+
acts_as_seasonal
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
after { Object.send(:remove_const, 'TimelyExtensionsTestSeasonal') }
|
13
|
+
|
14
|
+
it 'should cache boundary start' do
|
15
|
+
season = Timely::Season.new
|
16
|
+
season.date_groups.build(:start_date => Date.current, :end_date => Date.current + 2)
|
17
|
+
season.date_groups.build(:start_date => Date.current - 1, :end_date => Date.current + 1)
|
18
|
+
season.save!
|
19
|
+
|
20
|
+
o = TimelyExtensionsTestSeasonal.new
|
21
|
+
o.season = season
|
22
|
+
o.save!
|
23
|
+
expect(o.boundary_start).to eq Date.current - 1
|
24
|
+
expect(o.boundary_end ).to eq Date.current + 2
|
25
|
+
|
26
|
+
expect(TimelyExtensionsTestSeasonal.season_on(Date.current + 3)).to be_empty
|
27
|
+
expect(TimelyExtensionsTestSeasonal.season_on(Date.current + 2)).to eq [o]
|
28
|
+
expect(TimelyExtensionsTestSeasonal.season_on(Date.current - 1)).to eq [o]
|
29
|
+
expect(TimelyExtensionsTestSeasonal.season_on(Date.current - 2)).to be_empty
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Date do
|
4
|
+
let(:date) { Date.parse("2010-01-01") }
|
5
|
+
|
6
|
+
before { Time.zone = ActiveSupport::TimeZone["Adelaide"] }
|
7
|
+
|
8
|
+
subject(:converted) { date.to_time_in_time_zone }
|
9
|
+
|
10
|
+
it "should convert to time in time zone" do
|
11
|
+
expect(converted.year).to eq date.year
|
12
|
+
expect(converted.month).to eq date.month
|
13
|
+
expect(converted.day).to eq date.day
|
14
|
+
expect(converted.time_zone).to eq Time.zone
|
15
|
+
end
|
16
|
+
end
|