diff --git a/README.md b/README.md index 1cb44c0..640a5e7 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ The gem adds the following (possibly missing) methods to Date, Time, and/or Date * precision * precision= * partial_match? +* is_complete? * year? * month? * day? diff --git a/lib/date_time_precision/lib.rb b/lib/date_time_precision/lib.rb index 2226835..ac80142 100644 --- a/lib/date_time_precision/lib.rb +++ b/lib/date_time_precision/lib.rb @@ -126,6 +126,11 @@ def partial_match?(date2) self.class::partial_match?(self, date2) end + # Returns true if date complete (has year, month and day) + def is_complete? + @precision == 3 + end + def normalize_new_args(args) self.class.normalize_new_args(args) end diff --git a/spec/date_time_precision_spec.rb b/spec/date_time_precision_spec.rb index de7ef57..6ebb488 100644 --- a/spec/date_time_precision_spec.rb +++ b/spec/date_time_precision_spec.rb @@ -179,6 +179,23 @@ end end + describe '#is_complete?' do + it 'returns true when date has year, month and day' do + d1 = Date.new(2001,3,2) + expect(d1.is_complete?).to be true + end + + it 'returns false when date day missing' do + d1 = Date.new(2001,3) + expect(d1.is_complete?).to be false + end + + it 'returns false when date day and month missing' do + d1 = Date.new(2001) + expect(d1.is_complete?).to be false + end + end + context 'Decades and Centuries' do it 'should have the proper precision when outputting decades or centuries' do no_date = Date.new @@ -214,4 +231,4 @@ end end -end \ No newline at end of file +end