Fix date format for form response in reports [SCI-11811]

This commit is contained in:
Andrej 2025-04-14 10:50:39 +02:00
parent 16c9d8fa71
commit fde255b132
3 changed files with 14 additions and 2 deletions

View file

@ -137,6 +137,8 @@ module ReportsHelper
tags: %w(img),
team: current_team
)
elsif form_field_value.is_a?(FormDatetimeFieldValue)
form_field_value&.formatted_localize
else
form_field_value&.formatted
end
@ -144,7 +146,7 @@ module ReportsHelper
{
name: form_field.name,
value: value,
submitted_at: form_field_value&.submitted_at&.utc.to_s,
submitted_at: form_field_value&.submitted_at ? I18n.l(form_field_value&.submitted_at) : '',
submitted_by: form_field_value&.submitted_by&.full_name.to_s
}
end

View file

@ -25,4 +25,12 @@ class FormDatetimeFieldValue < FormFieldValue
range? ? [datetime&.to_date, datetime_to&.to_date].join(' - ') : datetime&.to_date.to_s
end
end
def formatted_localize
format = form_field.data['time'] ? :full : :full_date
from = datetime ? I18n.l(datetime, format: format) : ''
to = datetime_to ? I18n.l(datetime_to, format: format) : ''
range? ? [from, to].join(' - ') : from
end
end

View file

@ -26,13 +26,15 @@ module Reports
I18n.t('forms.export.values.not_applicable')
elsif form_field_value.is_a?(FormTextFieldValue)
SmartAnnotations::TagToText.new(user, team, form_field_value&.formatted).text
elsif form_field_value.is_a?(FormDatetimeFieldValue)
form_field_value&.formatted_localize
else
form_field_value&.formatted
end
table << [
form_field.name,
value,
form_field_value&.submitted_at&.utc.to_s,
form_field_value&.submitted_at ? I18n.l(form_field_value&.submitted_at) : '',
form_field_value&.submitted_by&.full_name.to_s
]
end