diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb index a22012dd3a2..41777435c7e 100644 --- a/core/app/helpers/spree/base_helper.rb +++ b/core/app/helpers/spree/base_helper.rb @@ -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 = {}) diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml index 6d90434bb60..60c9c3c9481 100644 --- a/core/config/locales/en.yml +++ b/core/config/locales/en.yml @@ -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. diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb index 3db119fbe84..0a9e1608669 100644 --- a/core/spec/helpers/base_helper_spec.rb +++ b/core/spec/helpers/base_helper_spec.rb @@ -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