Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
5 changes: 5 additions & 0 deletions lib/date_time_precision/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/date_time_precision_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -214,4 +231,4 @@
end

end
end
end