edtf 2.0.0 → 2.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 +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +2 -1
- data/.simplecov +4 -0
- data/.travis.yml +4 -7
- data/Gemfile +14 -4
- data/README.md +18 -20
- data/Rakefile +14 -4
- data/edtf.gemspec +1 -1
- data/features/support/env.rb +22 -1
- data/lib/edtf/date.rb +65 -58
- data/lib/edtf/date_time.rb +1 -1
- data/lib/edtf/epoch.rb +105 -104
- data/lib/edtf/parser.rb +1793 -0
- data/lib/edtf/season.rb +84 -83
- data/lib/edtf/set.rb +80 -78
- data/lib/edtf/version.rb +1 -1
- data/spec/spec_helper.rb +21 -0
- metadata +28 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68aac723f31efd30a29639ccddba4f552d32f3e2
|
4
|
+
data.tar.gz: 0997aa8f2861ababa527f1f39b0811ef2db055c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fae111479f8b85e8d308e0075e62a713be2d651ad402c7867183fadb5d929541333d78baad12712b6a244b5dc890557bd9b331188656989508d657117401e9d8
|
7
|
+
data.tar.gz: 5d3ad065005556811991a501b1ad5f1a73210b0fa5c6e5bd88e4808145d24a5135d48f8bcd7b0d8c0de97634ac61a8e578bd830ffd4e2285f2a0e8874934b2d6
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.simplecov
ADDED
data/.travis.yml
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
bundler_args: --without debug extra
|
3
|
+
script: bundle exec rake test_with_coveralls
|
3
4
|
rvm:
|
4
5
|
- 2.0.0
|
5
|
-
- 1.9.2
|
6
6
|
- 1.9.3
|
7
|
-
|
8
|
-
|
9
|
-
- rbx
|
10
|
-
- rbx-19mode
|
11
|
-
- 1.8.7
|
12
|
-
- ree
|
7
|
+
- jruby-19mode
|
8
|
+
- rbx-2.1.1
|
9
|
+
- rbx
|
13
10
|
notifications:
|
14
11
|
email:
|
15
12
|
- sk@semicolon.at
|
data/Gemfile
CHANGED
@@ -2,15 +2,20 @@ source 'https://rubygems.org'
|
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
group :debug do
|
5
|
-
|
6
|
-
|
5
|
+
gem 'ruby-debug', :require => false, :platform => :jruby
|
6
|
+
gem 'debugger', ['~>1.6', '>=1.6.5'], :require => false, :platform => :mri
|
7
|
+
gem 'rubinius-compiler', '~>2.0', :require => false, :platform => :rbx
|
8
|
+
gem 'rubinius-debugger', '~>2.0', :require => false, :platform => :rbx
|
7
9
|
end
|
8
10
|
|
9
11
|
group :development do
|
10
12
|
gem 'rake'
|
11
|
-
gem 'racc'
|
13
|
+
gem 'racc', :platform => :ruby
|
12
14
|
gem 'cucumber'
|
13
15
|
gem 'rspec'
|
16
|
+
gem 'simplecov', '~>0.8', :require => false
|
17
|
+
gem 'rubinius-coverage', :platform => :rbx
|
18
|
+
gem 'coveralls', :require => false
|
14
19
|
end
|
15
20
|
|
16
21
|
group :extra do
|
@@ -18,4 +23,9 @@ group :extra do
|
|
18
23
|
end
|
19
24
|
|
20
25
|
# active_support requires this
|
21
|
-
gem 'i18n'
|
26
|
+
gem 'i18n'
|
27
|
+
|
28
|
+
platform :rbx do
|
29
|
+
gem 'rubysl', '~>2.0'
|
30
|
+
gem 'json'
|
31
|
+
end
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
EDTF-Ruby
|
2
2
|
=========
|
3
|
+
[](https://travis-ci.org/inukshuk/edtf-ruby)
|
4
|
+
[](https://coveralls.io/r/inukshuk/edtf-ruby)
|
3
5
|
|
4
6
|
EDTF-Ruby comprises a parser and an API implementation of the [Extended
|
5
7
|
Date/Time Format standard](http://www.loc.gov/standards/datetime/spec.html).
|
@@ -7,7 +9,6 @@ Date/Time Format standard](http://www.loc.gov/standards/datetime/spec.html).
|
|
7
9
|
|
8
10
|
Compatibility
|
9
11
|
-------------
|
10
|
-
|
11
12
|
EDTF-Ruby parser implements all levels and features of the EDTF specification
|
12
13
|
(version September 16, 2011). With the following known caveats:
|
13
14
|
|
@@ -20,14 +21,14 @@ EDTF-Ruby parser implements all levels and features of the EDTF specification
|
|
20
21
|
examples, though).
|
21
22
|
|
22
23
|
EDTF-Ruby has been confirmed to work on the following Ruby implementations:
|
23
|
-
2.0, 1.9.3,
|
24
|
+
2.1, 2.0, 1.9.3, Rubinius, and JRuby (1.8.7 and 1.9.2 were originally
|
25
|
+
we are not testing compatibility actively anymore). Active Support's date
|
24
26
|
extensions are currently listed as a dependency, because of many functional
|
25
|
-
overlaps.
|
27
|
+
overlaps (version 3.x and 4.x are supported).
|
26
28
|
|
27
29
|
|
28
30
|
Quickstart
|
29
31
|
----------
|
30
|
-
|
31
32
|
EDTF Ruby is implemented as an extension to the regular Ruby date/time classes.
|
32
33
|
You can parse EDTF strings either using `Date.edtf` or `EDTF.parse`
|
33
34
|
(both methods come with an alternative bang! version, that will raise an error
|
@@ -56,7 +57,7 @@ subtle difference that determines how many other methods work. For instance:
|
|
56
57
|
=> Fri, 11 Nov 2011
|
57
58
|
> Date.today.month_precision!.succ
|
58
59
|
=> Sat, 10 Dec 2011
|
59
|
-
|
60
|
+
|
60
61
|
As you can see, dates have day precision by default; after setting the date's
|
61
62
|
precision to month, however, the natural successor is not the next day, but
|
62
63
|
a day a month from now. Always keep precision in mind when comparing dates,
|
@@ -64,7 +65,7 @@ too:
|
|
64
65
|
|
65
66
|
> Date.new(1666).year_precision! == Date.new(1966)
|
66
67
|
=> false
|
67
|
-
|
68
|
+
|
68
69
|
The year 1666 is not equal to the January 1st, 1966. You can set a date's
|
69
70
|
precision directly, or else use the dedicated bang! methods:
|
70
71
|
|
@@ -167,30 +168,30 @@ functionality.
|
|
167
168
|
=> true
|
168
169
|
> d.include?(Date.new(1987,04,13))
|
169
170
|
=> false
|
170
|
-
|
171
|
+
|
171
172
|
The day is not included because interval has month precision. However:
|
172
173
|
|
173
174
|
> d.cover?(Date.new(1987,04,13))
|
174
175
|
=> true
|
175
|
-
|
176
|
+
|
176
177
|
The day is still covered by the interval. In general, optimized in the
|
177
178
|
same way that Ruby optimizes numeric ranges. Additionally, precision
|
178
179
|
plays into the way intervals are enumerated:
|
179
180
|
|
180
181
|
> d.length
|
181
182
|
=> 243
|
182
|
-
|
183
|
+
|
183
184
|
There are 243 months between 1984-06-01 and 2004-08-31.
|
184
185
|
|
185
186
|
> d.step(36).map(&:year)
|
186
187
|
=> [1984, 1987, 1990, 1993, 1996, 1999, 2002]
|
187
|
-
|
188
|
+
|
188
189
|
Here we iterate through the interval in 36-month steps and map each date to
|
189
190
|
the year.
|
190
191
|
|
191
192
|
> Date.edtf('1582-10-01/1582-10-31').length
|
192
193
|
=> 21
|
193
|
-
|
194
|
+
|
194
195
|
This interval has day precision, so 21 is the number of days in October 1582,
|
195
196
|
which was cut short because of the Gregorian calendar reform.
|
196
197
|
|
@@ -200,7 +201,7 @@ Intervals can be open or have unknown start or end dates.
|
|
200
201
|
=> true
|
201
202
|
> Date.edtf('2004/open').cover?(Date.today)
|
202
203
|
=> true
|
203
|
-
|
204
|
+
|
204
205
|
### Sets
|
205
206
|
|
206
207
|
EDTF supports two kind of sets: choice lists (meaning one date out of a list),
|
@@ -213,7 +214,7 @@ and the `choice` attribute.
|
|
213
214
|
> s.choice!
|
214
215
|
> s.edtf
|
215
216
|
=> "[1667, 1668, 1670..1672]"
|
216
|
-
|
217
|
+
|
217
218
|
As you can see above, EDTF-Ruby remembers which parts of the set were
|
218
219
|
specified as a range; ranges are however enumerated for membership tests:
|
219
220
|
|
@@ -221,19 +222,19 @@ specified as a range; ranges are however enumerated for membership tests:
|
|
221
222
|
=> false
|
222
223
|
> s.include?(Date.edtf('1671'))
|
223
224
|
=> true
|
224
|
-
|
225
|
+
|
225
226
|
Even though we're still aware that the year 1671 was is not directly an
|
226
227
|
element of the set:
|
227
228
|
|
228
229
|
> s.length
|
229
230
|
=> 3
|
230
|
-
|
231
|
+
|
231
232
|
When in doubt, you can always map the set to an array. This will also
|
232
233
|
enumerate all ranges:
|
233
234
|
|
234
235
|
> s.map(&:year)
|
235
236
|
=> [1667, 1668, 1670, 1671, 1672] # when enumerated there are 5 elements
|
236
|
-
|
237
|
+
|
237
238
|
EDTF sets also feature an `#earlier?` and `#later?` attribute:
|
238
239
|
|
239
240
|
> s.earlier?
|
@@ -308,17 +309,15 @@ extensive list of rspec examples.
|
|
308
309
|
|
309
310
|
Contributing
|
310
311
|
------------
|
311
|
-
|
312
312
|
The EDTF-Ruby source code is [hosted on GitHub](https://github.com/inukshuk/edtf-ruby).
|
313
313
|
You can check out a copy of the latest code using Git:
|
314
314
|
|
315
315
|
$ git clone https://github.com/inukshuk/edtf-ruby.git
|
316
|
-
|
316
|
+
|
317
317
|
To get started, generate the parser and run all tests:
|
318
318
|
|
319
319
|
$ cd edtf-ruby
|
320
320
|
$ bundle install
|
321
|
-
$ bundle exec rake racc_debug
|
322
321
|
$ bundle exec rspec spec
|
323
322
|
$ bundle exec cucumber
|
324
323
|
|
@@ -330,7 +329,6 @@ and submit a pull request.
|
|
330
329
|
|
331
330
|
Credits
|
332
331
|
-------
|
333
|
-
|
334
332
|
EDTF-Ruby was written by [Sylvester Keil](http://sylvester.keil.or.at) and
|
335
333
|
[Namyra](https://github.com/namyra).
|
336
334
|
|
data/Rakefile
CHANGED
@@ -13,7 +13,7 @@ require 'edtf/version'
|
|
13
13
|
|
14
14
|
require 'rake/clean'
|
15
15
|
|
16
|
-
task :default => [:
|
16
|
+
task :default => [:spec, :cucumber]
|
17
17
|
|
18
18
|
desc 'Run an IRB session with CiteProc loaded'
|
19
19
|
task :console, [:script] do |t,args|
|
@@ -21,7 +21,7 @@ task :console, [:script] do |t,args|
|
|
21
21
|
|
22
22
|
require 'irb'
|
23
23
|
require 'edtf'
|
24
|
-
|
24
|
+
|
25
25
|
IRB.conf[:SCRIPT] = args.script
|
26
26
|
IRB.start
|
27
27
|
end
|
@@ -46,11 +46,21 @@ require 'cucumber/rake/task'
|
|
46
46
|
Cucumber::Rake::Task.new(:cucumber)
|
47
47
|
|
48
48
|
desc 'Builds the gem file'
|
49
|
-
task :build => [:
|
49
|
+
task :build => [:check_warnings] do
|
50
50
|
system 'gem build edtf.gemspec'
|
51
51
|
end
|
52
52
|
|
53
|
-
task
|
53
|
+
require 'coveralls/rake/task'
|
54
|
+
Coveralls::RakeTask.new
|
55
|
+
task :test_with_coveralls => [:spec, :cucumber, 'coveralls:push']
|
56
|
+
|
57
|
+
task :check_warnings do
|
58
|
+
$VERBOSE = true
|
59
|
+
require 'edtf'
|
60
|
+
puts EDTF::VERSION
|
61
|
+
end
|
62
|
+
|
63
|
+
task :release => [ :build] do
|
54
64
|
system "git tag #{EDTF::VERSION}"
|
55
65
|
system "git push --tags"
|
56
66
|
system "gem push edtf-#{EDTF::VERSION}.gem"
|
data/edtf.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.description = 'A Ruby implementation of the Extended Date/Time Format (EDTF).'
|
16
16
|
s.license = 'FreeBSD'
|
17
17
|
|
18
|
-
s.add_runtime_dependency('activesupport',
|
18
|
+
s.add_runtime_dependency('activesupport', '>= 3.0', '< 5.0')
|
19
19
|
|
20
20
|
s.files = `git ls-files`.split("\n") << 'lib/edtf/parser.rb'
|
21
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/features/support/env.rb
CHANGED
@@ -1 +1,22 @@
|
|
1
|
-
|
1
|
+
begin
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls' if ENV['CI']
|
4
|
+
rescue LoadError
|
5
|
+
# ignore
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
case
|
10
|
+
when RUBY_PLATFORM < 'java'
|
11
|
+
require 'debug'
|
12
|
+
Debugger.start
|
13
|
+
when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
14
|
+
require 'rubinius/debugger'
|
15
|
+
else
|
16
|
+
require 'debugger'
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
# ignore
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'edtf'
|
data/lib/edtf/date.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Date
|
2
|
-
|
2
|
+
|
3
3
|
PRECISION = [:year, :month, :day].freeze
|
4
4
|
PRECISIONS = Hash[*PRECISION.map { |p| [p, "#{p}s".to_sym] }.flatten].freeze
|
5
|
-
|
5
|
+
|
6
6
|
FORMATS = %w{ %04d %02d %02d }.freeze
|
7
7
|
|
8
8
|
SYMBOLS = {
|
@@ -11,47 +11,50 @@ class Date
|
|
11
11
|
:calendar => '^',
|
12
12
|
:unspecified => 'u'
|
13
13
|
}.freeze
|
14
|
-
|
15
|
-
EXTENDED_ATTRIBUTES = %w{
|
16
|
-
unspecified
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
|
15
|
+
EXTENDED_ATTRIBUTES = %w{
|
16
|
+
calendar precision uncertain approximate unspecified
|
17
|
+
}.map(&:to_sym).freeze
|
18
|
+
|
19
|
+
extend Forwardable
|
20
|
+
|
20
21
|
class << self
|
21
|
-
|
22
|
+
|
22
23
|
def edtf(input, options = {})
|
23
24
|
edtf!(input, options)
|
24
25
|
rescue
|
25
26
|
nil
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
def edtf!(input, options = {})
|
29
30
|
::EDTF::Parser.new(options).parse!(input)
|
30
31
|
end
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
attr_accessor :calendar
|
34
|
-
|
35
|
+
|
35
36
|
PRECISION.each do |p|
|
36
37
|
define_method("#{p}_precision?") { precision == p }
|
37
|
-
|
38
|
+
|
38
39
|
define_method("#{p}_precision!") do
|
39
40
|
self.precision = p
|
40
41
|
self
|
41
42
|
end
|
42
|
-
|
43
|
+
|
43
44
|
define_method("#{p}_precision") do
|
44
45
|
change(:precision => p)
|
45
46
|
end
|
46
47
|
end
|
47
|
-
|
48
|
-
|
48
|
+
|
49
|
+
|
50
|
+
alias original_initialize_copy initialize_copy
|
51
|
+
|
49
52
|
def initialize_copy(other)
|
50
|
-
|
53
|
+
original_initialize_copy(other)
|
51
54
|
copy_extended_attributes(other)
|
52
55
|
end
|
53
|
-
|
54
|
-
|
56
|
+
|
57
|
+
|
55
58
|
# Alias advance method from Active Support.
|
56
59
|
alias original_advance advance
|
57
60
|
|
@@ -63,7 +66,7 @@ class Date
|
|
63
66
|
|
64
67
|
# Alias change method from Active Support.
|
65
68
|
alias original_change change
|
66
|
-
|
69
|
+
|
67
70
|
# Returns a new Date where one or more of the elements have been changed according to the +options+ parameter.
|
68
71
|
def change(options)
|
69
72
|
d = original_change(options)
|
@@ -72,13 +75,13 @@ class Date
|
|
72
75
|
end
|
73
76
|
d
|
74
77
|
end
|
75
|
-
|
76
|
-
|
78
|
+
|
79
|
+
|
77
80
|
# Returns this Date's precision.
|
78
81
|
def precision
|
79
82
|
@precision ||= :day
|
80
83
|
end
|
81
|
-
|
84
|
+
|
82
85
|
# Sets this Date/Time's precision to the passed-in value.
|
83
86
|
def precision=(precision)
|
84
87
|
precision = precision.to_sym
|
@@ -86,7 +89,7 @@ class Date
|
|
86
89
|
@precision = precision
|
87
90
|
update_precision_filter[-1]
|
88
91
|
end
|
89
|
-
|
92
|
+
|
90
93
|
def uncertain
|
91
94
|
@uncertain ||= EDTF::Uncertainty.new
|
92
95
|
end
|
@@ -98,14 +101,14 @@ class Date
|
|
98
101
|
def unspecified
|
99
102
|
@unspecified ||= EDTF::Unspecified.new
|
100
103
|
end
|
101
|
-
|
104
|
+
|
102
105
|
def_delegators :uncertain, :uncertain?, :certain?
|
103
106
|
|
104
107
|
def certain!(arguments = precision_filter)
|
105
108
|
uncertain.certain!(arguments)
|
106
109
|
self
|
107
110
|
end
|
108
|
-
|
111
|
+
|
109
112
|
def uncertain!(arguments = precision_filter)
|
110
113
|
uncertain.uncertain!(arguments)
|
111
114
|
self
|
@@ -114,20 +117,20 @@ class Date
|
|
114
117
|
def approximate?(arguments = precision_filter)
|
115
118
|
approximate.uncertain?(arguments)
|
116
119
|
end
|
117
|
-
|
120
|
+
|
118
121
|
alias approximately? approximate?
|
119
|
-
|
122
|
+
|
120
123
|
def approximate!(arguments = precision_filter)
|
121
124
|
approximate.uncertain!(arguments)
|
122
125
|
self
|
123
126
|
end
|
124
|
-
|
127
|
+
|
125
128
|
alias approximately! approximate!
|
126
|
-
|
129
|
+
|
127
130
|
def precise?(arguments = precision_filter)
|
128
131
|
!approximate?(arguments)
|
129
132
|
end
|
130
|
-
|
133
|
+
|
131
134
|
alias precisely? precise?
|
132
135
|
|
133
136
|
def precise!(arguments = precision_filter)
|
@@ -136,9 +139,9 @@ class Date
|
|
136
139
|
end
|
137
140
|
|
138
141
|
alias precisely! precise!
|
139
|
-
|
142
|
+
|
140
143
|
def_delegators :unspecified, :unspecified?, :specified?, :unspecific?, :specific?
|
141
|
-
|
144
|
+
|
142
145
|
def unspecified!(arguments = precision_filter)
|
143
146
|
unspecified.unspecified!(arguments)
|
144
147
|
self
|
@@ -152,10 +155,10 @@ class Date
|
|
152
155
|
end
|
153
156
|
|
154
157
|
alias specific! specified!
|
155
|
-
|
158
|
+
|
156
159
|
# Returns false for Dates.
|
157
160
|
def season?; false; end
|
158
|
-
|
161
|
+
|
159
162
|
# Returns true if the Date has an EDTF calendar string attached.
|
160
163
|
def calendar?; !!@calendar; end
|
161
164
|
|
@@ -163,11 +166,11 @@ class Date
|
|
163
166
|
def season
|
164
167
|
Season.new(self)
|
165
168
|
end
|
166
|
-
|
169
|
+
|
167
170
|
# Returns the Date's EDTF string.
|
168
171
|
def edtf
|
169
172
|
return "y#{year}" if long_year?
|
170
|
-
|
173
|
+
|
171
174
|
s = FORMATS.take(values.length).zip(values).map { |f,v| f % v }
|
172
175
|
s = unspecified.mask(s)
|
173
176
|
|
@@ -183,11 +186,11 @@ class Date
|
|
183
186
|
# not covered by precision!
|
184
187
|
#
|
185
188
|
y, m, d = s
|
186
|
-
|
189
|
+
|
187
190
|
# ?/~ if true-false or true-true and other false-true
|
188
191
|
y << SYMBOLS[:uncertain] if 3&h==1 || 27&h==19
|
189
192
|
y << SYMBOLS[:approximate] if 24&h==8 || 27&h==26
|
190
|
-
|
193
|
+
|
191
194
|
|
192
195
|
# combine if false-true-true and other m == d
|
193
196
|
if 7&h==6 && (48&h==48 || 48&h==0) || 56&h==48 && (6&h==6 || 6&h==0)
|
@@ -199,21 +202,21 @@ class Date
|
|
199
202
|
when 3&h==2 || 24&h==16
|
200
203
|
m[0,0] = '('
|
201
204
|
m << ')'
|
202
|
-
|
205
|
+
|
203
206
|
# *-false-true
|
204
207
|
when 6&h==4 || 48&h==32
|
205
208
|
d[0,0] = '('
|
206
209
|
d << ')'
|
207
210
|
end
|
208
|
-
|
209
|
-
# ?/~ if *-true-false or *-true-true and other m != d
|
211
|
+
|
212
|
+
# ?/~ if *-true-false or *-true-true and other m != d
|
210
213
|
m << SYMBOLS[:uncertain] if h!=31 && (6&h==2 || 6&h==6 && (48&h==16 || 48&h==32))
|
211
214
|
m << SYMBOLS[:approximate] if h!=59 && (48&h==16 || 48&h==48 && (6&h==2 || 6&h==4))
|
212
215
|
end
|
213
|
-
|
216
|
+
|
214
217
|
# ?/~ if *-*-true
|
215
218
|
d << SYMBOLS[:uncertain] if 4&h==4
|
216
|
-
d << SYMBOLS[:approximate] if 32&h==32
|
219
|
+
d << SYMBOLS[:approximate] if 32&h==32
|
217
220
|
end
|
218
221
|
|
219
222
|
s = s.join('-')
|
@@ -222,13 +225,17 @@ class Date
|
|
222
225
|
end
|
223
226
|
|
224
227
|
alias to_edtf edtf
|
225
|
-
|
228
|
+
|
229
|
+
remove_method :next
|
230
|
+
|
226
231
|
# Returns an array of the next n days, months, or years depending on the
|
227
232
|
# current Date/Time's precision.
|
228
233
|
def next(n = 1)
|
229
234
|
1.upto(n).map { |by| advance(PRECISIONS[precision] => by) }
|
230
235
|
end
|
231
236
|
|
237
|
+
remove_method :succ
|
238
|
+
|
232
239
|
def succ
|
233
240
|
advance(PRECISIONS[precision] => 1)
|
234
241
|
end
|
@@ -242,7 +249,7 @@ class Date
|
|
242
249
|
advance(PRECISIONS[precision] => -1)
|
243
250
|
end
|
244
251
|
end
|
245
|
-
|
252
|
+
|
246
253
|
def <=>(other)
|
247
254
|
case other
|
248
255
|
when ::Date
|
@@ -254,36 +261,36 @@ class Date
|
|
254
261
|
end
|
255
262
|
end
|
256
263
|
|
257
|
-
|
264
|
+
|
258
265
|
# Returns an array of the current year, month, and day values filtered by
|
259
266
|
# the Date/Time's precision.
|
260
267
|
def values
|
261
268
|
precision_filter.map { |p| send(p) }
|
262
269
|
end
|
263
|
-
|
270
|
+
|
264
271
|
# Returns the same date but with negated year.
|
265
272
|
def negate
|
266
273
|
change(:year => year * -1)
|
267
274
|
end
|
268
|
-
|
275
|
+
|
269
276
|
alias -@ negate
|
270
|
-
|
277
|
+
|
271
278
|
# Returns true if this Date/Time has year precision and the year exceeds four digits.
|
272
279
|
def long_year?
|
273
280
|
year_precision? && year.abs > 9999
|
274
281
|
end
|
275
|
-
|
276
|
-
|
282
|
+
|
283
|
+
|
277
284
|
private
|
278
|
-
|
285
|
+
|
279
286
|
def ua_hash
|
280
287
|
uncertain.hash + approximate.hash
|
281
288
|
end
|
282
|
-
|
289
|
+
|
283
290
|
def precision_filter
|
284
291
|
@precision_filter ||= update_precision_filter
|
285
292
|
end
|
286
|
-
|
293
|
+
|
287
294
|
def update_precision_filter
|
288
295
|
@precision_filter = case precision
|
289
296
|
when :year
|
@@ -294,9 +301,9 @@ class Date
|
|
294
301
|
[:year,:month,:day]
|
295
302
|
end
|
296
303
|
end
|
297
|
-
|
304
|
+
|
298
305
|
protected
|
299
|
-
|
306
|
+
|
300
307
|
attr_writer :uncertain, :unspecified, :approximate
|
301
308
|
|
302
309
|
def copy_extended_attributes(other)
|
@@ -308,6 +315,6 @@ class Date
|
|
308
315
|
@precision = other.precision
|
309
316
|
|
310
317
|
self
|
311
|
-
end
|
318
|
+
end
|
312
319
|
|
313
320
|
end
|