edtf 3.2.0 → 4.0.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.
@@ -1,131 +0,0 @@
1
- Feature: Print uncertain or approximate dates
2
- As a Ruby programmer
3
- I want to convert Date/Time objects to EDTF strings
4
-
5
- @201 @level2
6
- Scenario Outline: Prints uncertain or approximate dates
7
- Given the date "<date>" with precision set to "<precision>"
8
- When the year is uncertain: "<?-year>"
9
- And the month is uncertain: "<?-month>"
10
- And the day is uncertain: "<?-day>"
11
- And the year is approximate: "<~-year>"
12
- And the month is approximate: "<~-month>"
13
- And the day is approximate "<~-day>"
14
- When I convert the date
15
- Then the EDTF string should be "<string>"
16
-
17
- Scenarios: Uncertain or approximate dates, day precision
18
- | date | precision | string | ?-year | ?-month | ?-day | ~-year | ~-month | ~-day |
19
- | 2004-06-01 | day | 2004-06-01?~ | yes | yes | yes | yes | yes | yes |
20
- | 2004-06-01 | day | 2004-06~-01? | yes | yes | yes | yes | yes | no |
21
- # | 2004-06-01 | day | (2004~-06-(01)~)? | yes | yes | yes | yes | no | yes |
22
- | 2004-06-01 | day | 2004~-06?-(01)?~ | yes | yes | yes | yes | no | yes |
23
- | 2004-06-01 | day | 2004~-06-01? | yes | yes | yes | yes | no | no |
24
- # | 2004-06-01 | day | (2004-(06-01)~)? | yes | yes | yes | no | yes | yes |
25
- | 2004-06-01 | day | 2004?-(06-01)?~ | yes | yes | yes | no | yes | yes |
26
- # | 2004-06-01 | day | (2004-(06)~-01)? | yes | yes | yes | no | yes | no |
27
- | 2004-06-01 | day | 2004?-(06)?~-01? | yes | yes | yes | no | yes | no |
28
- # | 2004-06-01 | day | (2004-06-(01)~)? | yes | yes | yes | no | no | yes |
29
- | 2004-06-01 | day | 2004-06?-(01)?~ | yes | yes | yes | no | no | yes |
30
- | 2004-06-01 | day | 2004-06-01? | yes | yes | yes | no | no | no |
31
- | 2004-06-01 | day | 2004-06?-01~ | yes | yes | no | yes | yes | yes |
32
- | 2004-06-01 | day | 2004-06?~-01 | yes | yes | no | yes | yes | no |
33
- | 2004-06-01 | day | 2004~-06?-(01)~ | yes | yes | no | yes | no | yes |
34
- | 2004-06-01 | day | 2004~-06?-01 | yes | yes | no | yes | no | no |
35
- # | 2004-06-01 | day | 2004-(06?-01)~ | yes | yes | no | no | yes | yes | is this correct?
36
- # | 2004-06-01 | day | 2004?-((06)?-01)~ | yes | yes | no | no | yes | yes |
37
- | 2004-06-01 | day | 2004?-(06)?~-01~ | yes | yes | no | no | yes | yes |
38
- # | 2004-06-01 | day | (2004-(06)~)?-01 | yes | yes | no | no | yes | no |
39
- | 2004-06-01 | day | 2004?-(06)?~-01 | yes | yes | no | no | yes | no |
40
- | 2004-06-01 | day | 2004-06?-(01)~ | yes | yes | no | no | no | yes |
41
- | 2004-06-01 | day | 2004-06?-01 | yes | yes | no | no | no | no |
42
- # | 2004-06-01 | day | (2004?-06-(01)?)~ | yes | no | yes | yes | yes | yes |
43
- | 2004-06-01 | day | 2004?-06~-(01)?~ | yes | no | yes | yes | yes | yes |
44
- | 2004-06-01 | day | 2004?-06~-(01)? | yes | no | yes | yes | yes | no |
45
- | 2004-06-01 | day | 2004?~-06-(01)?~ | yes | no | yes | yes | no | yes |
46
- | 2004-06-01 | day | 2004?~-06-(01)? | yes | no | yes | yes | no | no |
47
- # | 2004-06-01 | day | 2004?-(06-(01)?)~ | yes | no | yes | no | yes | yes |
48
- | 2004-06-01 | day | 2004?-(06)~-01?~ | yes | no | yes | no | yes | yes |
49
- | 2004-06-01 | day | 2004?-(06)~-01? | yes | no | yes | no | yes | no |
50
- | 2004-06-01 | day | 2004?-06-(01)?~ | yes | no | yes | no | no | yes |
51
- | 2004-06-01 | day | 2004?-06-(01)? | yes | no | yes | no | no | no |
52
- | 2004-06-01 | day | 2004?-06-01~ | yes | no | no | yes | yes | yes |
53
- | 2004-06-01 | day | 2004?-06~-01 | yes | no | no | yes | yes | no |
54
- | 2004-06-01 | day | 2004?~-06-(01)~ | yes | no | no | yes | no | yes |
55
- | 2004-06-01 | day | 2004?~-06-01 | yes | no | no | yes | no | no |
56
- | 2004-06-01 | day | 2004?-(06-01)~ | yes | no | no | no | yes | yes |
57
- | 2004-06-01 | day | 2004?-(06)~-01 | yes | no | no | no | yes | no |
58
- | 2004-06-01 | day | 2004?-06-(01)~ | yes | no | no | no | no | yes |
59
- | 2004-06-01 | day | 2004?-06-01 | yes | no | no | no | no | no |
60
- # | 2004-06-01 | day | (2004-(06-01)?)~ | no | yes | yes | yes | yes | yes |
61
- | 2004-06-01 | day | 2004~-(06-01)?~ | no | yes | yes | yes | yes | yes |
62
- # | 2004-06-01 | day | 2004-(06~-01)? | no | yes | yes | yes | yes | no | is this correct?
63
- # | 2004-06-01 | day | 2004~-((06)~-01)? | no | yes | yes | yes | yes | no |
64
- | 2004-06-01 | day | 2004~-(06)?~-01? | no | yes | yes | yes | yes | no |
65
- # | 2004-06-01 | day | 2004~-(06-(01)~)? | no | yes | yes | yes | no | yes |
66
- | 2004-06-01 | day | 2004~-(06)?-01?~ | no | yes | yes | yes | no | yes |
67
- | 2004-06-01 | day | 2004~-(06-01)? | no | yes | yes | yes | no | no |
68
- | 2004-06-01 | day | 2004-(06-01)?~ | no | yes | yes | no | yes | yes |
69
- # | 2004-06-01 | day | 2004-((06)~-01)? | no | yes | yes | no | yes | no |
70
- | 2004-06-01 | day | 2004-(06)?~-01? | no | yes | yes | no | yes | no |
71
- # | 2004-06-01 | day | 2004-(06-(01)~)? | no | yes | yes | no | no | yes |
72
- | 2004-06-01 | day | 2004-(06)?-01?~ | no | yes | yes | no | no | yes |
73
- | 2004-06-01 | day | 2004-(06-01)? | no | yes | yes | no | no | no |
74
- # | 2004-06-01 | day | (2004-(06)?-01)~ | no | yes | no | yes | yes | yes |
75
- | 2004-06-01 | day | 2004~-(06)?~-01~ | no | yes | no | yes | yes | yes |
76
- # | 2004-06-01 | day | (2004-(06)?)~-01 | no | yes | no | yes | yes | no |
77
- | 2004-06-01 | day | 2004~-(06)?~-01 | no | yes | no | yes | yes | no |
78
- | 2004-06-01 | day | 2004~-(06)?-01~ | no | yes | no | yes | no | yes |
79
- | 2004-06-01 | day | 2004~-(06)?-01 | no | yes | no | yes | no | no |
80
- # | 2004-06-01 | day | 2004-((06)?-01)~ | no | yes | no | no | yes | yes |
81
- | 2004-06-01 | day | 2004-(06)?~-01~ | no | yes | no | no | yes | yes |
82
- | 2004-06-01 | day | 2004-(06)?~-01 | no | yes | no | no | yes | no |
83
- | 2004-06-01 | day | 2004-(06)?-01~ | no | yes | no | no | no | yes |
84
- | 2004-06-01 | day | 2004-(06)?-01 | no | yes | no | no | no | no |
85
- # | 2004-06-01 | day | (2004-06-(01)?)~ | no | no | yes | yes | yes | yes |
86
- | 2004-06-01 | day | 2004-06~-(01)?~ | no | no | yes | yes | yes | yes |
87
- | 2004-06-01 | day | 2004-06~-(01)? | no | no | yes | yes | yes | no |
88
- | 2004-06-01 | day | 2004~-06-(01)?~ | no | no | yes | yes | no | yes |
89
- | 2004-06-01 | day | 2004~-06-(01)? | no | no | yes | yes | no | no |
90
- # | 2004-06-01 | day | 2004-(06-(01)?)~ | no | no | yes | no | yes | yes |
91
- | 2004-06-01 | day | 2004-(06)~-01?~ | no | no | yes | no | yes | yes |
92
- | 2004-06-01 | day | 2004-(06)~-01? | no | no | yes | no | yes | no |
93
- | 2004-06-01 | day | 2004-06-(01)?~ | no | no | yes | no | no | yes |
94
- | 2004-06-01 | day | 2004-06-(01)? | no | no | yes | no | no | no |
95
- | 2004-06-01 | day | 2004-06-01~ | no | no | no | yes | yes | yes |
96
- | 2004-06-01 | day | 2004-06~-01 | no | no | no | yes | yes | no |
97
- | 2004-06-01 | day | 2004~-06-(01)~ | no | no | no | yes | no | yes |
98
- | 2004-06-01 | day | 2004~-06-01 | no | no | no | yes | no | no |
99
- | 2004-06-01 | day | 2004-(06-01)~ | no | no | no | no | yes | yes |
100
- | 2004-06-01 | day | 2004-(06)~-01 | no | no | no | no | yes | no |
101
- | 2004-06-01 | day | 2004-06-(01)~ | no | no | no | no | no | yes |
102
- | 2004-06-01 | day | 2004-06-01 | no | no | no | no | no | no |
103
-
104
- Scenarios: Uncertain or approximate dates, month precision
105
- | date | precision | string | ?-year | ?-month | ?-day | ~-year | ~-month | ~-day |
106
- | 2004-06-01 | month | 2004-06?~ | yes | yes | no | yes | yes | no |
107
- | 2004-06-01 | month | 2004~-06? | yes | yes | no | yes | no | no |
108
- # | 2004-06-01 | month | (2004-(06)~)? | yes | yes | no | no | yes | no |
109
- | 2004-06-01 | month | 2004?-(06)?~ | yes | yes | no | no | yes | no |
110
- | 2004-06-01 | month | 2004-06? | yes | yes | no | no | no | no |
111
- | 2004-06-01 | month | 2004?-06~ | yes | no | no | yes | yes | no |
112
- | 2004-06-01 | month | 2004?~-06 | yes | no | no | yes | no | no |
113
- | 2004-06-01 | month | 2004?-(06)~ | yes | no | no | no | yes | no |
114
- | 2004-06-01 | month | 2004?-06 | yes | no | no | no | no | no |
115
- # | 2004-06-01 | month | (2004-(06)?)~ | no | yes | no | yes | yes | no |
116
- | 2004-06-01 | month | 2004~-(06)?~ | no | yes | no | yes | yes | no |
117
- | 2004-06-01 | month | 2004~-(06)? | no | yes | no | yes | no | no |
118
- | 2004-06-01 | month | 2004-(06)?~ | no | yes | no | no | yes | no |
119
- | 2004-06-01 | month | 2004-(06)? | no | yes | no | no | no | no |
120
- | 2004-06-01 | month | 2004-06~ | no | no | no | yes | yes | no |
121
- | 2004-06-01 | month | 2004~-06 | no | no | no | yes | no | no |
122
- | 2004-06-01 | month | 2004-(06)~ | no | no | no | no | yes | no |
123
- | 2004-06-01 | month | 2004-06 | no | no | no | no | no | no |
124
-
125
-
126
- Scenarios: Uncertain or approximate dates, year precision
127
- | date | precision | string | ?-year | ?-month | ?-day | ~-year | ~-month | ~-day |
128
- | 2004-06-01 | year | 2004?~ | yes | no | no | yes | no | no |
129
- | 2004-06-01 | year | 2004? | yes | no | no | no | no | no |
130
- | 2004-06-01 | year | 2004~ | no | no | no | yes | no | no |
131
- | 2004-06-01 | year | 2004 | no | no | no | no | no | no |
@@ -1,148 +0,0 @@
1
- Given /^the date "([^"]*)"(?: with precision set to "([^"]*)")?$/ do |date, precision|
2
- @date = Date.parse(date)
3
- @date.precision = precision unless precision.nil?
4
- end
5
-
6
- When /^I convert the date$/ do
7
- @string = @date.edtf
8
- end
9
-
10
- Then /^the EDTF String should be "([^"]*)"$/i do |edtf|
11
- expect(@string).to eq(edtf)
12
- end
13
-
14
- When /^I parse the string "([^"]*)"$/ do |string|
15
- @date = EDTF.parse!(string)
16
- end
17
-
18
- Then /^the year should be "([^"]*)"$/ do |year|
19
- expect(@date.year).to eq(year.to_i)
20
- end
21
-
22
- Then /^the month should be "([^"]*)"$/ do |month|
23
- expect(@date.month).to eq(month.to_i)
24
- end
25
-
26
- Then /^the day should be "([^"]*)"$/ do |day|
27
- expect(@date.day).to eq(day.to_i)
28
- end
29
-
30
- Then /^the hours should be "([^"]*)"$/ do |hours|
31
- expect(@date.hour).to eq(hours.to_i)
32
- end
33
-
34
- Then /^the year should be "([^"]*)" UTC$/ do |year|
35
- expect(@date.to_time.utc.year).to eq(year.to_i)
36
- end
37
-
38
- Then /^the month should be "([^"]*)" UTC$/ do |month|
39
- expect(@date.to_time.utc.month).to eq(month.to_i)
40
- end
41
-
42
- Then /^the day should be "([^"]*)" UTC$/ do |day|
43
- expect(@date.to_time.utc.day).to eq(day.to_i)
44
- end
45
-
46
- Then /^the hours should be "([^"]*)" UTC$/ do |hours|
47
- expect(@date.to_time.utc.hour).to eq(hours.to_i)
48
- end
49
-
50
-
51
- Then /^the minutes should be "([^"]*)"$/ do |minutes|
52
- expect(@date.min).to eq(minutes.to_i)
53
- end
54
-
55
- Then /^the seconds should be "([^"]*)"$/ do |seconds|
56
- expect(@date.sec).to eq(seconds.to_i)
57
- end
58
-
59
- Then /^the duration should range from "([^"]*)" to "([^"]*)"$/ do |from,to|
60
- expect([@date.begin.year.to_s, @date.end.year.to_s]).to eq([from,to])
61
- end
62
-
63
- Then /^the interval should start at "([^"]*)"$/ do |date|
64
- expect(@date.begin.to_s).to eq(date)
65
- end
66
-
67
- Then /^the interval should end at "([^"]*)"$/ do |date|
68
- expect(@date.end.to_s).to eq(date)
69
- end
70
-
71
- Then /^the interval should include the date "([^"]*)"$/ do |date|
72
- expect(@date).to include(Date.parse(date))
73
- end
74
-
75
- Then /^the interval should cover the date "([^"]*)"$/ do |date|
76
- expect(@date).to be_cover(Date.parse(date))
77
- end
78
-
79
-
80
- Then /^the date should be uncertain\? "([^"]*)"$/ do |arg1|
81
- expect(@date.uncertain?).to eq(!!(arg1 =~ /y(es)?/i))
82
- end
83
-
84
- Then /^the year should be uncertain\? "([^"]*)"$/ do |arg1|
85
- expect(@date.uncertain?(:year)).to eq(!!(arg1 =~ /y(es)?/i))
86
- end
87
-
88
- Then /^the month should be uncertain\? "([^"]*)"$/ do |arg1|
89
- expect(@date.uncertain?(:month)).to eq(!!(arg1 =~ /y(es)?/i))
90
- end
91
-
92
- Then /^the day should be uncertain\? "([^"]*)"$/ do |arg1|
93
- expect(@date.uncertain?(:day)).to eq(!!(arg1 =~ /y(es)?/i))
94
- end
95
-
96
- Then /^the date should be approximate\? "([^"]*)"$/ do |arg1|
97
- expect(@date.approximate?).to eq(!!(arg1 =~ /y(es)?/i))
98
- end
99
-
100
- Then /^the year should be approximate\? "([^"]*)"$/ do |arg1|
101
- expect(@date.approximate?(:year)).to eq(!!(arg1 =~ /y(es)?/i))
102
- end
103
-
104
- Then /^the month should be approximate\? "([^"]*)"$/ do |arg1|
105
- expect(@date.approximate?(:month)).to eq(!!(arg1 =~ /y(es)?/i))
106
- end
107
-
108
- Then /^the day should be approximate\? "([^"]*)"$/ do |arg1|
109
- expect(@date.approximate?(:day)).to eq(!!(arg1 =~ /y(es)?/i))
110
- end
111
-
112
- Then /^the result should be an Unknown$/ do
113
- expect(@date).to be_an(EDTF::Unknown)
114
- end
115
-
116
- Then /^the unspecified string code be "([^"]*)"$/ do |arg1|
117
- expect(@date.unspecified.to_s).to eq(arg1)
118
- end
119
-
120
- When /^I parse the following strings an error should be raised:$/ do |table|
121
- table.raw.each do |row|
122
- expect { Date.edtf!(row[0]) }.to raise_error(ArgumentError)
123
- end
124
- end
125
-
126
- When /^the year is uncertain: "([^"]*)"$/ do |arg1|
127
- @date.uncertain!(:year) if arg1 =~ /y(es)?/i
128
- end
129
-
130
- When /^the month is uncertain: "([^"]*)"$/ do |arg1|
131
- @date.uncertain!(:month) if arg1 =~ /y(es)?/i
132
- end
133
-
134
- When /^the day is uncertain: "([^"]*)"$/ do |arg1|
135
- @date.uncertain!(:day) if arg1 =~ /y(es)?/i
136
- end
137
-
138
- When /^the year is approximate: "([^"]*)"$/ do |arg1|
139
- @date.approximate!(:year) if arg1 =~ /y(es)?/i
140
- end
141
-
142
- When /^the month is approximate: "([^"]*)"$/ do |arg1|
143
- @date.approximate!(:month) if arg1 =~ /y(es)?/i
144
- end
145
-
146
- When /^the day is approximate "([^"]*)"$/ do |arg1|
147
- @date.approximate!(:day) if arg1 =~ /y(es)?/i
148
- end
@@ -1,13 +0,0 @@
1
- begin
2
- require 'simplecov'
3
- rescue LoadError
4
- # ignore
5
- end
6
-
7
- begin
8
- require 'debug' unless RUBY_PLATFORM == 'java'
9
- rescue LoadError
10
- # ignore
11
- end
12
-
13
- require 'edtf'
@@ -1,245 +0,0 @@
1
- describe 'Date/DateTime' do
2
-
3
- describe 'class methods' do
4
- it 'responds to edtf' do
5
- expect(Date).to respond_to(:edtf)
6
- end
7
- end
8
-
9
- describe 'instance methods' do
10
- [:uncertain?, :approximate?, :unspecified?, :uncertain, :approximate, :unspecified].each do |method|
11
- it "responds to #{method}" do
12
- expect(Date.new.respond_to?(method)).to eq(true)
13
- end
14
- end
15
- end
16
-
17
- describe '#dup' do
18
- let(:date) { Date.edtf('2004-09?~') }
19
-
20
- it 'copies all date values' do
21
- date.dup.to_s == '2004-09-01'
22
- end
23
-
24
- it 'copies uncertainty' do
25
- expect(date.dup).to be_uncertain
26
- end
27
-
28
- it 'copies approximate' do
29
- expect(date.dup).to be_approximate
30
- end
31
-
32
- it 'copies precision' do
33
- expect(date.dup.precision).to eq(:month)
34
- end
35
-
36
- it 'copies uncertainty by value' do
37
- expect { date.dup.certain! }.not_to change { date.uncertain? }
38
- end
39
-
40
- end
41
-
42
- describe 'precisions' do
43
- let(:date) { Date.today }
44
-
45
- it 'has day precision by default' do
46
- expect(date).to be_day_precision
47
- end
48
-
49
- it '#day_precison returns a new date object' do
50
- expect(date.day_precision).not_to equal(date)
51
- expect(date.day_precision).to eq(date)
52
- end
53
-
54
- end
55
-
56
-
57
- describe '#negate' do
58
- let(:date) { Date.edtf('2004?') }
59
-
60
- it 'returns a new date with the negated year' do
61
- expect(date.negate.year).to eq(date.year * -1)
62
- end
63
-
64
- it 'returns a new date with the same month' do
65
- expect(date.negate.month).to eq(date.month)
66
- end
67
-
68
- it 'returns a new date with the same day' do
69
- expect(date.negate.day).to eq(date.day)
70
- end
71
-
72
- it 'returns a new date with the same precision' do
73
- expect(date.negate.precision).to eq(date.precision)
74
- end
75
- end
76
-
77
- describe '#succ' do
78
-
79
- it 'the successor of 2004 is 2005' do
80
- expect(Date.edtf('2004').succ.year).to eq(2005)
81
- end
82
-
83
- it 'the successor of 2004-03 is 2004-04' do
84
- expect(Date.edtf('2004-03').succ.strftime('%Y-%m')).to eq('2004-04')
85
- end
86
-
87
- it 'the successor of 2004-03-01 is 2004-03-02' do
88
- expect(Date.edtf('2004-03-01').succ.strftime('%Y-%m-%d')).to eq('2004-03-02')
89
- end
90
-
91
- it "the successor of 1999 has year precision" do
92
- expect(Date.edtf('1999').succ).to be_year_precision
93
- end
94
-
95
- end
96
-
97
- describe '#next' do
98
-
99
- it 'returns the successor when given no argument' do
100
- expect(Date.edtf('1999').next[0].year).to eq(2000)
101
- end
102
-
103
- it 'returns an array of the next 3 elements when passed 3 as an argument' do
104
- Date.edtf('1999').next(3).map(&:year) == [2000, 2001, 2002]
105
- end
106
-
107
- end
108
-
109
-
110
- describe '#change' do
111
- let(:date) { Date.edtf('2004-09?~') }
112
-
113
- it 'returns a copy of the date if given empty option hash' do
114
- expect(date.change({})).to eq(date)
115
- end
116
-
117
- it 'the returned copy is not identical at object level' do
118
- expect(date.change({})).not_to equal(date)
119
- end
120
-
121
- describe 'when given a new year' do
122
- let(:changeset) { { :year => 1999 } }
123
-
124
- it 'returns a new date instance with the changed year' do
125
- expect(date.change(changeset).year).to eq(1999)
126
- end
127
-
128
- end
129
-
130
- describe 'when given a new precision' do
131
- let(:changeset) { { :precision => :year } }
132
-
133
- it 'returns a new date instance with the changed precision' do
134
- expect(date.change(changeset).precision).to eq(:year)
135
- end
136
-
137
- end
138
-
139
- it 'copies extended values by value' do
140
- expect { date.change({}).approximate! }.not_to change { date.approximate? }
141
- end
142
-
143
- end
144
-
145
- describe '#uncertain?' do
146
-
147
- let(:date) { Date.new }
148
-
149
- it { expect(Date.new).not_to be_uncertain }
150
-
151
- [:year, :month, :day].each do |part|
152
- it "should not be uncertain by default (#{part})" do
153
- expect(Date.new.uncertain?(part)).to eq(false)
154
- end
155
-
156
- it "should be uncertain if set to uncertain (#{part})" do
157
- date.uncertain.send("#{part}=", true)
158
- expect(date.uncertain?(part)).to eq(true)
159
- end
160
-
161
- ([:year, :month, :day] - [part]).each do |other|
162
- it "#{other} should not be uncertain if #{part} is uncertain" do
163
- date.uncertain.send("#{part}=", true)
164
- expect(date.uncertain?(other)).to eq(false)
165
- end
166
- end
167
-
168
- end
169
-
170
- end
171
-
172
- describe 'uncertain/approximate hash' do
173
-
174
- it 'is 0 by default' do
175
- expect(Date.new().send(:ua_hash)).to eq(0)
176
- end
177
-
178
- it 'is 8 for approximate year' do
179
- expect(Date.new.approximate!(:year).send(:ua_hash)).to eq(8)
180
- end
181
-
182
- end
183
-
184
- describe 'sorting and comparisons' do
185
- let(:xmas) { Date.new(2011, 12, 24) }
186
- let(:new_years_eve) { Date.new(2011, 12, 31) }
187
-
188
- describe '#values' do
189
-
190
- it 'returns [2011,12,24] for christmas' do
191
- expect(xmas.values).to eq([2011,12,24])
192
- end
193
-
194
- it 'returns [2011,12] for christmas with month precision' do
195
- expect(xmas.month_precision!.values).to eq([2011,12])
196
- end
197
-
198
- it 'returns [2011] for christmas with year precision' do
199
- expect(xmas.year_precision!.values).to eq([2011])
200
- end
201
-
202
- end
203
-
204
- describe '#<=>' do
205
-
206
- it '2009-12-24 should be less than 2011-12-31' do
207
- expect(Date.new(2009,12,24)).to be < Date.new(2011,12,31)
208
- end
209
-
210
- it '2009-12-24 should be less than 2011-12' do
211
- expect(Date.new(2009,12,24)).to be < Date.edtf('2011-12')
212
- end
213
-
214
- it '2009-12-24 should be less than 2011' do
215
- expect(Date.new(2009,12,24)).to be < Date.edtf('2011')
216
- end
217
-
218
-
219
- end
220
-
221
- describe '#==' do
222
-
223
- it "xmas and new year's eve are not equal" do
224
- expect(xmas).not_to eq(new_years_eve)
225
- end
226
-
227
- it "xmas and new year's eve are equal using month percision" do
228
- expect(xmas.month_precision!).to eq(new_years_eve.month_precision!)
229
- end
230
-
231
- it "xmas and january 24 are not equal using month percision" do
232
- expect(xmas.month_precision!).not_to eq(xmas.month_precision!.next)
233
- end
234
-
235
-
236
- it "xmas and new year's eve are equal using year percision" do
237
- expect(xmas.year_precision!).to eq(new_years_eve.year_precision!)
238
- end
239
-
240
- end
241
-
242
- end
243
-
244
-
245
- end
@@ -1,88 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module EDTF
4
-
5
- describe Decade do
6
-
7
- it { is_expected.not_to be nil }
8
-
9
- describe '.current' do
10
- it 'creates the current decade' do
11
- expect(Decade.current.year).to eq((Time.now.year / 10) * 10)
12
- end
13
- end
14
-
15
- describe '#min' do
16
- it 'the year 1990 should be the minimum of the 1990s' do
17
- expect(Decade.new(1999).min).to eq(Date.new(1990).year_precision!)
18
- end
19
- end
20
-
21
- describe '#max' do
22
- it 'the year 1999 should be the maximum of the 1990s' do
23
- expect(Decade.new(1999).max).to eq(Date.new(1999).year_precision!)
24
- end
25
-
26
- it 'has year precision' do
27
- expect(Decade.new(1999).max).to be_year_precision
28
- end
29
- end
30
-
31
- describe '#cover?' do
32
- it '1989-12-31 should be covered by the 1980s' do
33
- expect(Decade.new(1980)).to be_cover(Date.new(1989,12,31))
34
- end
35
- end
36
-
37
- describe '#to_range' do
38
-
39
- it 'returns a range' do
40
- expect(Decade.new.to_range).to be_instance_of(::Range)
41
- end
42
-
43
- it 'the range starts with a date object' do
44
- expect(Decade.new.to_range.begin).to be_instance_of(::Date)
45
- end
46
-
47
- it 'the range ends with a date object' do
48
- expect(Decade.new.to_range.end).to be_instance_of(::Date)
49
- end
50
-
51
- it 'the range start has year precision' do
52
- expect(Decade.new.to_range.begin).to be_year_precision
53
- end
54
-
55
- it 'the range end has year precision' do
56
- expect(Decade.new.to_range.end).to be_year_precision
57
- end
58
-
59
- end
60
-
61
- describe 'enumeration' do
62
-
63
- it 'always covers ten years' do
64
- expect(Decade.new.to_a.size).to eq(10)
65
- end
66
-
67
- it 'the 1970s should map to the years [1970, 1971, ... , 1979]' do
68
- expect(Decade.new(1970).map(&:year)).to eq([1970, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979])
69
- end
70
-
71
- end
72
-
73
- end
74
-
75
- describe Century do
76
-
77
- it { is_expected.not_to be nil }
78
-
79
- describe '.current' do
80
- it 'creates the current century' do
81
- expect(Century.current.year).to eq((Time.now.year / 100) * 100)
82
- end
83
- end
84
-
85
- end
86
-
87
-
88
- end