Skip to content

Commit

Permalink
Trim leading zeroes when presenting hierarchical years
Browse files Browse the repository at this point in the history
  • Loading branch information
thatbudakguy committed Sep 13, 2024
1 parent 7fbf616 commit 68d9262
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/presenters/date_facet_item_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

# Format dates for display
class DateFacetItemPresenter < Blacklight::FacetItemPivotPresenter
# Choose the finest granularity available and trim leading zeroes
# 0100-0199 -> 100-199
def label
century, decade, year = value.split(':')
[year, decade, century].find(&:present?) # label is just the finest level of granularity available
finest = [year, decade, century].find(&:present?)
finest.sub!(/^0+(\d+)/, '\1')
finest.sub!(/-0+(\d+)/, '-\1')
finest
end
end

0 comments on commit 68d9262

Please sign in to comment.