Skip to content

Commit

Permalink
Merge pull request #2175 from DFE-Digital/refactor-dates
Browse files Browse the repository at this point in the history
Refactor date/time formatting
  • Loading branch information
thomasleese authored Apr 26, 2024
2 parents 9a33b0b + 2c3afa8 commit efde255
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 37 deletions.
3 changes: 1 addition & 2 deletions app/components/check_your_answers_summary/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def format_value(value, field)
end

def format_date(date, field)
format = field[:format] == :without_day ? "%B %Y" : "%e %B %Y"
date.strftime(format).strip
field[:format] == :without_day ? date.to_fs(:month_and_year) : date.to_fs
end

def format_document(document, field)
Expand Down
2 changes: 1 addition & 1 deletion app/components/timeline_entry/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p class="moj-timeline__date">
<time datetime="<%= timeline_event.created_at.iso8601 %>">
<%= timeline_event.created_at.localtime.to_fs(:date_and_time) %>
<%= timeline_event.created_at.localtime.to_fs %>
</time>
</p>

Expand Down
3 changes: 1 addition & 2 deletions app/components/timeline_entry/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def requestable_requested_vars

def requestable_received_vars
{
requested_at:
timeline_event.requestable.created_at.to_fs(:date_and_time),
requested_at: timeline_event.requestable.created_at.to_fs,
location_note: timeline_event.requestable.try(:location_note),
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def application_form_summary_rows(
text: I18n.t("application_form.summary.submitted_at"),
},
value: {
text: application_form.submitted_at.strftime("%e %B %Y"),
text: application_form.submitted_at.to_date.to_fs,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions app/lib/consent_letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def document
pdf.text "Name: #{application_form_full_name(application_form)}"

pdf.pad(LINE_PAD * 2) do
pdf.text "Date of birth: #{application_form.date_of_birth.to_fs(:long_ordinal_uk)}"
pdf.text "Date of birth: #{application_form.date_of_birth.to_fs}"
end

pdf.text "Date of consent: #{date_of_consent.to_fs(:long_ordinal_uk)}"
pdf.text "Date of consent: #{date_of_consent.to_fs}"

pdf.pad(SECTION_PAD) do
pdf.text "The service is run by the Teaching Regulation Agency (TRA) an executive agency of the " \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def teacher_name_and_date_of_birth
[
application_form.given_names,
application_form.family_name,
"(#{application_form.date_of_birth.to_fs(:long_ordinal_uk)})",
"(#{application_form.date_of_birth.to_fs})",
].join(" ")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def further_information_request
end

def started_at
application_form.created_at.to_fs(:date).strip
application_form.created_at.to_date.to_fs
end

def expires_at
application_form.expires_at.to_fs(:date).strip
application_form.expires_at.to_date.to_fs
end

def task_list_sections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<%= govuk_warning_text(text: "Only resend reference requests if you have been asked to do so.") %>

<% if (timeline_event = @application_form.timeline_events.email_sent.where(mailer_class_name: "RefereeMailer", mailer_action_name: "reference_requested").order(created_at: :desc).first) %>
<p class="govuk-body">This email was last sent on <%= timeline_event.created_at.to_fs(:date_and_time) %></p>
<p class="govuk-body">This email was last sent on <%= timeline_event.created_at.to_fs %></p>
<% end %>

<%= govuk_button_link_to "Resend reference request email", [:resend_email, :assessor_interface, @application_form, @assessment, @reference_request] %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/referee_mailer/reference_reminder.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The applicant may not be awarded QTS if we cannot confirm the information they h

# What you need to do

You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>. This should take no longer than 5 minutes.
You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs %>. This should take no longer than 5 minutes.

Follow the link below to start.

Expand Down
2 changes: 1 addition & 1 deletion app/views/referee_mailer/reference_requested.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ They have given us your name and email address to confirm the information they

# What you need to do

You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs(:long_ordinal_uk) %>. This should take no longer than 5 minutes.
You need to answer a few questions about <%= application_form_full_name(@application_form) %> by <%= @reference_request.expires_at.to_date.to_fs %>. This should take no longer than 5 minutes.

Follow the link below to start.

Expand Down
6 changes: 3 additions & 3 deletions app/views/shared/_reference_request_summary.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
t(
"helpers.legend.teacher_interface_reference_request_dates_response_form.dates_response.current",
school_name: work_history.school_name,
start_date: work_history.start_date.strftime("%B %Y"),
start_date: work_history.start_date.to_fs(:month_and_year),
) :
t(
"helpers.legend.teacher_interface_reference_request_dates_response_form.dates_response.previous",
school_name: work_history.school_name,
start_date: work_history.start_date.strftime("%B %Y"),
end_date: work_history.end_date.strftime("%B %Y"),
start_date: work_history.start_date.to_fs(:month_and_year),
end_date: work_history.end_date.to_fs(:month_and_year),
),
value: reference_request.dates_response ? "Yes" : "No — #{reference_request.dates_comment}",
href: dates_teacher_interface_reference_request_path(reference_request.slug),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
t(
"helpers.legend.teacher_interface_reference_request_dates_response_form.dates_response.current",
school_name: @work_history.school_name,
start_date: @work_history.start_date.strftime("%B %Y"),
start_date: @work_history.start_date.to_fs(:month_and_year),
) :
t(
"helpers.legend.teacher_interface_reference_request_dates_response_form.dates_response.previous",
school_name: @work_history.school_name,
start_date: @work_history.start_date.strftime("%B %Y"),
end_date: @work_history.end_date.strftime("%B %Y"),
start_date: @work_history.start_date.to_fs(:month_and_year),
end_date: @work_history.end_date.to_fs(:month_and_year),
) %>

<% content_for :page_title, title_with_error_prefix(title, error: @form.errors.any?) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<%= govuk_inset_text do %>
<p class="govuk-body">
<%= @work_history.school_name %> from <%= @work_history.start_date.strftime("%B %Y") %> to <%= (@work_history.end_date || Time.zone.today).strftime("%B %Y") %>
<%= @work_history.school_name %> from <%= @work_history.start_date.to_fs(:month_and_year) %> to <%= (@work_history.end_date || Date.today).to_fs(:month_and_year) %>
</p>
<% end %>

Expand Down
6 changes: 3 additions & 3 deletions app/views/teacher_mailer/application_not_submitted.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Dear <%= application_form_full_name(@application_form) %>,
<% when 0 %>
We’ve noticed that you have a draft application for qualified teacher status (QTS) that has not been submitted.

We need to let you know that if you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
We need to let you know that if you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs %> we’ll delete the application.
<% when 1 %>
We contacted you a week ago about your draft application for qualified teacher status (QTS).

If you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %> we’ll delete the application.
If you do not complete and submit your application by <%= @application_form.expires_at.to_date.to_fs %> we’ll delete the application.
<% end %>

# What happens if your application is deleted?
Expand All @@ -19,7 +19,7 @@ Applications are deleted permanently, so if you still wanted to apply for QTS af

# Your next steps

If you still want to apply for QTS you must do so before <%= @application_form.expires_at.to_date.to_fs(:long_ordinal_uk) %>. You can sign in to complete and submit your application using the link below:
If you still want to apply for QTS you must do so before <%= @application_form.expires_at.to_date.to_fs %>. You can sign in to complete and submit your application using the link below:

<%= new_teacher_session_url %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/teacher_mailer/consent_reminder.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Dear <%= application_form_full_name(@application_form) %>,

We recently wrote to you asking for your consent to verify some of your qualifications as part of your QTS application.

We have not received your consent documents. If you do not send them by <%= @expires_at.to_fs(:date) %> we will not be able to proceed with your application.
We have not received your consent documents. If you do not send them by <%= @expires_at.to_date.to_fs %> we will not be able to proceed with your application.

## What you need to do

Expand Down
2 changes: 1 addition & 1 deletion app/views/teacher_mailer/consent_requested.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Download each document then:

[Sign in to access your documents](<%= new_teacher_session_url %>)

You need to sign and upload these documents by <%= @expires_at.to_fs(:date) %> so that we can proceed with your application.
You need to sign and upload these documents by <%= @expires_at.to_date.to_fs %> so that we can proceed with your application.

## Why we need your written consent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dear <%= application_form_full_name(@application_form) %>,

# What happens next

You must respond to this request by <%= @further_information_request.expires_at.to_date.to_fs(:long_ordinal_uk) %> otherwise your QTS application will be declined.
You must respond to this request by <%= @further_information_request.expires_at.to_date.to_fs %> otherwise your QTS application will be declined.

Once you respond with all of the information we’ve requested, the assessor will be able to continue reviewing your application.

Expand Down
4 changes: 2 additions & 2 deletions app/views/teacher_mailer/references_reminder.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Dear <%= application_form_full_name(@application_form) %>,
## We’re still waiting for a response from one or more of the references you provided to verify your work history.

<% if @number_of_reminders_sent == 0 %>
We contacted your references on <%= @reference_requests.first.requested_at.to_date.to_fs(:long_ordinal_uk) %> but have not received a response from:
We contacted your references on <%= @reference_requests.first.requested_at.to_date.to_fs %> but have not received a response from:
<% elsif @number_of_reminders_sent == 1 %>
The following references have just 2 weeks to respond to the reference request.
<% end %>
Expand All @@ -12,6 +12,6 @@ The following references have just 2 weeks to respond to the reference request.
- <%= reference_request.work_history.contact_name %><%= reference_request.work_history.school_name %>
<% end %>

They need to respond by <%= @reference_requests.first.expires_at.to_date.to_fs(:long_ordinal_uk) %>. If your references do not respond, and, as a result, we cannot verify your work history, we may not be able to award you QTS. You should contact your reference to remind them about the request.
They need to respond by <%= @reference_requests.first.expires_at.to_date.to_fs %>. If your references do not respond, and, as a result, we cannot verify your work history, we may not be able to award you QTS. You should contact your reference to remind them about the request.

<%= render "shared/teacher_mailer/footer" %>
2 changes: 1 addition & 1 deletion app/views/teacher_mailer/references_requested.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Dear <%= application_form_full_name(@application_form) %>,

We’ve contacted the references you provided to verify the work history information you gave as part of your QTS application.

They need to respond by <%= @reference_requests.first.expires_at.to_date.to_fs(:long_ordinal_uk) %>. If your references do not respond, and, as a result, we cannot verify your work history, we may not be able to award you QTS.
They need to respond by <%= @reference_requests.first.expires_at.to_date.to_fs %>. If your references do not respond, and, as a result, we cannot verify your work history, we may not be able to award you QTS.

Contact them to make sure they have received the request. They may need to check their junk email folder.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ We can confirm that the following person has made an application to us for quali

<%= application_form_full_name(@application_form) %>

Date of birth: <%= @application_form.date_of_birth.to_fs(:long_ordinal_uk) %>
Date of birth: <%= @application_form.date_of_birth.to_fs %>

The applicant has provided us with the following details about their teaching qualification:

Title: <%= @qualification.title %>
Institution studied at: <%= @qualification.institution_name %>
Date started: <%= @qualification.start_date.to_fs(:long_ordinal_uk) %>
Date ended: <%= @qualification.complete_date.to_fs(:long_ordinal_uk) %>
Date started: <%= @qualification.start_date.to_fs %>
Date ended: <%= @qualification.complete_date.to_fs %>

They’ve told us that they’re qualified to teach children <%= @application_form.subjects.to_sentence %> from age <%= @application_form.age_range_min %> to <%= @application_form.age_range_max %> years old.

Expand Down
5 changes: 2 additions & 3 deletions config/initializers/date_formats.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

Date::DATE_FORMATS[:long_ordinal_uk] = "%-d %B %Y"
Date::DATE_FORMATS[:default] = "%-d %B %Y"
Date::DATE_FORMATS[:month_and_year] = "%B %Y"

Time::DATE_FORMATS[:date] = "%e %B %Y"
Time::DATE_FORMATS[:date_and_time] = "%e %B %Y at %l:%M %P"
Time::DATE_FORMATS[:default] = "%-d %B %Y at %l:%M %P"
2 changes: 1 addition & 1 deletion spec/helpers/application_form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
actions: [],
},
{ key: { text: "Created on" }, value: { text: " 1 January 2020" } },
{ key: { text: "Created on" }, value: { text: "1 January 2020" } },
{
key: {
text: "Working days since submission",
Expand Down

0 comments on commit efde255

Please sign in to comment.