diff --git a/app/helpers/answer_helper.rb b/app/helpers/answer_helper.rb
index b5b2736bc1..3d1f8737e8 100644
--- a/app/helpers/answer_helper.rb
+++ b/app/helpers/answer_helper.rb
@@ -6,7 +6,14 @@ def format_answer(answer)
when Date
answer = answer.to_formatted_s(:govuk_date)
when Time
- answer = answer.in_time_zone.to_formatted_s(:govuk_time)
+ local_time = answer.in_time_zone
+ answer = if local_time.hour.zero? && local_time.min.zero?
+ "Midnight"
+ elsif local_time.hour == 12 && local_time.min.zero?
+ "Midday"
+ else
+ local_time.to_formatted_s(:govuk_time_with_period)
+ end
end
safe_format(answer.to_s, wrapper_tag: "span")
diff --git a/spec/helpers/answer_helper_spec.rb b/spec/helpers/answer_helper_spec.rb
index f9e4921342..f31cd02b70 100644
--- a/spec/helpers/answer_helper_spec.rb
+++ b/spec/helpers/answer_helper_spec.rb
@@ -13,7 +13,17 @@
it "correctly formats a time" do
answer = Time.utc(2011, 1, 24, 10, 30)
- expect(helper.format_answer(answer)).to eq("10:30")
+ expect(helper.format_answer(answer)).to eq("10:30am")
+ end
+
+ it "correctly formats a time of midday" do
+ answer = Time.utc(2011, 1, 24, 12, 0)
+ expect(helper.format_answer(answer)).to eq("Midday")
+ end
+
+ it "correctly formats a time of midnight" do
+ answer = Time.utc(2011, 1, 24, 0, 0)
+ expect(helper.format_answer(answer)).to eq("Midnight")
end
it "calls safe_format" do
@@ -26,7 +36,7 @@
it "correctly formats a time" do
answer = Time.utc(2011, 1, 24, 10, 30)
- expect(helper.format_answer(answer)).to eq("00:30")
+ expect(helper.format_answer(answer)).to eq("12:30am")
end
end
end