diff --git a/app/views/admin/reports/_date_range_form.html.haml b/app/views/admin/reports/_date_range_form.html.haml index cebe2ce8f2a7..d98c9fd6c59c 100644 --- a/app/views/admin/reports/_date_range_form.html.haml +++ b/app/views/admin/reports/_date_range_form.html.haml @@ -8,3 +8,7 @@ %span.range-divider %i.icon-arrow-right = f.text_field "#{field}_lt", :class => 'datetimepicker datepicker-to', :placeholder => t(:stop), data: { controller: "flatpickr", "flatpickr-enable-time-value": true, "flatpickr-default-date-value": "endOfDay" } += hidden_field_tag "time_zone" +:javascript + document.querySelector("input[name='time_zone']").value = Intl.DateTimeFormat().resolvedOptions().timeZone + diff --git a/lib/reporting/reports/customers/base.rb b/lib/reporting/reports/customers/base.rb index a1c2382e557b..aad79fcbab31 100644 --- a/lib/reporting/reports/customers/base.rb +++ b/lib/reporting/reports/customers/base.rb @@ -55,6 +55,10 @@ def filter_to_completed_at(orders) return orders if min.blank? || max.blank? + if client_time_zone.present? + min = convert_to_client_time_zone(min) + max = convert_to_client_time_zone(max) + end orders.where(completed_at: [min..max]) end @@ -81,6 +85,18 @@ def last_completed_order(orders) def last_completed_order_date(orders) last_completed_order(orders).completed_at&.to_date end + + def convert_to_client_time_zone(datetime) + DateTime.parse(datetime).change(offset: utc_offset) + end + + def client_time_zone + ActiveSupport::TimeZone[params["time_zone"] || ""] + end + + def utc_offset + ActiveSupport::TimeZone[client_time_zone].formatted_offset + end end end end