Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use I18n date format for pretty_time helper #2419

Merged
merged 2 commits into from
Dec 12, 2017
Merged
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
5 changes: 2 additions & 3 deletions core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ def display_price(product_or_variant)
product_or_variant.price_for(current_pricing_options).to_html
end

def pretty_time(time)
[I18n.l(time.to_date, format: :long),
time.strftime("%l:%M %p")].join(" ")
def pretty_time(time, format = :long)
I18n.l(time, format: :"solidus.#{format}")
end

def link_to_tracking(shipment, options = {})
Expand Down
6 changes: 5 additions & 1 deletion core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,11 @@ en:
attributes:
payment_source:
has_to_be_payment_source_class: "has to be a Spree::PaymentSource"

time:
formats:
solidus:
long: '%B %d, %Y %-l:%M %p'
short: "%b %-d '%y %-l:%M%P"
devise:
confirmations:
confirmed: Your account was successfully confirmed. You are now signed in.
Expand Down
18 changes: 15 additions & 3 deletions core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,21 @@ def link_to_tracking_html(options = {})
end
end

context "pretty_time" do
it "prints in a format" do
expect(pretty_time(DateTime.new(2012, 5, 6, 13, 33))).to eq "May 06, 2012 1:33 PM"
describe "#pretty_time" do
subject { pretty_time(date) }

let(:date) { Time.new(2012, 11, 6, 13, 33) }

it "pretty prints time in long format" do
is_expected.to eq "November 06, 2012 1:33 PM"
end

context 'with format set to short' do
subject { pretty_time(date, :short) }

it "pretty prints time in short format" do
is_expected.to eq "Nov 6 '12 1:33pm"
end
end
end

Expand Down