saleor-dashboard
saleor-dashboard copied to clipboard
`Sales today`, `Order today`, `Product top` values don't handle browser timezones
What I'm trying to achieve
Hello. First of all thank you for all the great work that you're doing - Saleor is awesome! :fire:
It seems that stats available on a dashboard main page (Sales today
, Order today
, Product top
) don't handle client/browser timezone correctly which results in odd values and confusion for an end user.
Steps to reproduce the problem
- Go to the dashboard main page
- Make sure that you have some orders fulfilled for a current day
- See
Sales today
andOrders today
and make sure that these are non-zero values - Change your timezone where there's next day already. Example: my timezone is GMT+1, local time: 23:52. I've changed my timezone using google chrome sensors tool (https://dev.to/aileenr/how-to-spoof-your-timezone-in-google-chrome-48ch#:~:text=Click%20the%20three%2C%20vertically%2Daligned,to%20manually%20enter%20a%20timezone) to Tokyo, GMT+9, local time: 7:52.
- Refresh the page. Value of
Sales today
stays the same as it was before and value ofOrders today
is now 0.
What I expected to happen
Value of Sales today
and Orders today
should be calculated based on a browser timezone and exact date range for both values (mismatch between 0 in Orders today
and some non-zero value in Sales today
)
What is the cause of that behavior
-
Sales today
andProduct top
(wasn't mentioned in a reproduction steps) - both useTODAY
enum as a graphql query param which is interpreted without any timezone info on a backend side as UTC time -
Order today
- counts order based on browser date (without both time and timezone) which seems incorrect, becausetoday
is a date range filter (likedatePeriod: {gte: "2021-11-09", lte: "2021-11-09"}
) which is handled as UTC date on a backend side
Screenshots
Another reproduction for GMT+1 timezone is to go to https://demo.saleor.io/dashboard/ between 00:00 and 01:00
Http request and response from inspector
query:
query Home($channel: String!, $datePeriod: DateRangeInput!) {
salesToday: ordersTotal(period: TODAY, channel: $channel) {
gross {
amount
currency
__typename
}
__typename
}
ordersToday: orders(filter: {created: $datePeriod}, channel: $channel){
totalCount
__typename
}
}
variables:
{
"channel": "default-channel",
"datePeriod": {"gte": "2021-11-09", "lte": "2021-11-09"}
}
run via https://demo.saleor.io/graphql/ few minutes after midnight GMT+1 result:
{
"data": {
"salesToday": {
"gross": {
"amount": 497.24,
"currency": "USD",
"__typename": "Money"
},
"__typename": "TaxedMoney"
},
"ordersToday": {
"totalCount": 0,
"__typename": "OrderCountableConnection"
}
}
}
System information
Saleor version:
- [x] dev (current main)
- [x] 3.0
- [ ] 2.11
- [ ] 2.10
Operating system:
- [ ] Windows
- [x] Linux
- [ ] MacOS
- [ ] Other
Browser:
- [ ] Safari
- [X] Chrome
- [ ] Edge
- [ ] Other
Thx for a catch @fijolekProjects ! I am reporting it, we will try to fix it ASAP.