Parse given datetime for reports properly

This commit is contained in:
Maikel Linke
2024-10-17 14:15:23 +11:00
parent b9a72381fc
commit 2b8487cc6d
2 changed files with 7 additions and 2 deletions

View File

@@ -58,4 +58,9 @@ module ReportsHelper
.where(order_id: orders.map(&:id))
.pluck(:originator_id)
end
def datepicker_time(datetime)
datetime = Time.zone.parse(datetime) if datetime.is_a? String
datetime.strftime('%Y-%m-%d %H:%M')
end
end

View File

@@ -4,8 +4,8 @@
- start_field = "#{field}_gt"
- end_field = "#{field}_lt"
- query = params[:q].to_h
- start_date ||= query[start_field].presence || 3.months.ago.beginning_of_day.strftime('%Y-%m-%d %H:%M')
- end_date ||= query[end_field].presence || Time.zone.tomorrow.beginning_of_day.strftime('%Y-%m-%d %H:%M')
- start_date = datepicker_time(query[start_field].presence || 3.months.ago.beginning_of_day)
- end_date = datepicker_time(query[end_field].presence || Time.zone.tomorrow.beginning_of_day)
.row.date-range-filter
.alpha.two.columns= label_tag nil, t(:date_range)