Skip to content

The date time used as filter for transactions is not correct #9471

Open
@shendy-a8c

Description

@shendy-a8c

Describe the bug

I found this bug as I was working on #8522.

The dates used as filter that are passed to server are incorrect and this can lead to a misleading result.

Screenshot 2024-09-20 at 14 10 10

The times displayed under the Date / Time column are in the blog's timezone (can be set at wp-admin > Settings > General > Timezone).

When user chooses the date filter before and after, they expect to filter the date based on their local time (browser's time).

Currently, the filter dates will be passed to PHP in UTC (because of this). Then, WC_REST_Payments_Transactions_Controller::format_transaction_date_with_timestamp() will convert the dates before passing it to server. It will calculate the difference between store's timezone and user browser's timezone, which is incorrect. The server should receive the date in UTC.

To Reproduce

  1. Set blog timezone to be different from browser's timezone. wp-admin > Settings > General > Timezone.
  2. Set the date filter on the transaction list page, either before, after, or between.
  3. Debug the value of the filter dates that are passed to server. It should be the UTC of what is input by user, for example, if my timezone is UTC+7 and I choose 2024-09-01 and 2024-09-03, I will be expecting any data between 2024-09-01 00:00:00 and 2024-09-03 23:59:59 in UTC+7, which means 2024-08-31 17:00:00 and 2024-09-03 16:59:59 in UTC.

Actual behavior

The filter dates passed to server is UTC + (difference between browser's timezone and store's timezone).

Expected behavior

The filter dates passed to server should be in UTC.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions