Skip to content

Commit

Permalink
Fix one application_helper fuzzy date error/2
Browse files Browse the repository at this point in the history
  • Loading branch information
ut committed Jan 9, 2025
1 parent 518ce9b commit 5ef5f45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ def smart_date_display_with_qualifier(startdate, enddate, startdate_qualifier =
startdate.strftime('%-d.%-m.%Y, %H:%M').to_s
elsif startdate == enddate
if startdate.strftime('%H:%M') == '00:00'
startdate.strftime('%-d.%-m.%Y').to_s
if startdate_qualifier == 'circa' && enddate_qualifier == 'circa'
# ca. 1980s
"ca. #{startdate.strftime('%Y')}"
else
# 1.1.1980
startdate.strftime('%-d.%-m.%Y').to_s
end
else
startdate.strftime('%-d.%-m.%Y, %H:%M').to_s
end
Expand Down
5 changes: 5 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@
enddate = '2015-12-31 00:00:00'.to_time
expect(helper.smart_date_display_with_qualifier(startdate, enddate, 'circa', 'circa')).to eq('ca. 2015')
end
it 'returns ca. %Y with qualifier/2' do
startdate = '2015-01-01 00:00:00'.to_time
enddate = '2015-01-01 00:00:00'.to_time
expect(helper.smart_date_display_with_qualifier(startdate, enddate, 'circa', 'circa')).to eq('ca. 2015')
end
it 'returns ca. %Ys with qualifier' do
startdate = '2010-01-01 00:00:00'.to_time
enddate = '2020-01-01 00:00:00'.to_time
Expand Down

0 comments on commit 5ef5f45

Please sign in to comment.