-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DateHelper and add new method in LocaleHelper
- Add new DateHelper to deal with the last updated date on help pages - Add page_text_direction to LocaleHelper Commit audit trail: - app/helpers/locale_helper.rb https://github.com/alphagov/government-frontend/blob/af54031948650448b965ac274c3248d23658c4f6/app/helpers/application_helper.rb - app/helpers/date_helper.rb https://github.com/alphagov/government-frontend/blob/af54031948650448b965ac274c3248d23658c4f6/app/presenters/content_item_presenter.rb
- Loading branch information
1 parent
d04f2ee
commit 1cb231d
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module DateHelper | ||
def display_date(timestamp, format = "%-d %B %Y") | ||
I18n.l(Time.zone.parse(timestamp), format:, locale: "en") if timestamp | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
RSpec.describe DateHelper do | ||
include DateHelper | ||
|
||
let(:timestamp) { "2024-10-03 19:30:22 +0100" } | ||
|
||
describe "#display_date" do | ||
it "returns a formatted date" do | ||
expect(display_date(timestamp)).to eq("3 October 2024") | ||
end | ||
|
||
it "returns nil if passed nil" do | ||
expect(display_date(nil)).to be_nil | ||
end | ||
end | ||
end |