vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.63k stars 998 forks source link

Add timezone property to Channel for datetime inputs #183

Open michaelbromley opened 4 years ago

michaelbromley commented 4 years ago

Is your feature request related to a problem? Please describe. Vendure stores all dates/times as UTC in the database. When these datetimes are displayed in the Admin UI, they will be converted to the local representation in the current user's local timezone.

This is done typically by the Angular date pipe, which takes a timezone argument which we are currently not using. The DatePipe docs state:

A timezone offset (such as '+0430'), or a standard UTC/GMT or continental US timezone abbreviation. When not supplied, uses the end-user's local system timezone.

Let's say we have a UK-based shop running on GMT. Then an administrator based in Europe logs in and sets up a Promotion which ends at 6pm next Tuesday. Since her local timezone is GMT+1, the UTC value stored in the database will be the equivalent of 7pm GMT, so the Promotion is now incorrectly set up.

One work-around is for the Europe-based admin to just remember to offset all times by an hour. This is not a reasonable expectation. Too error-prone.

Describe the solution you'd like A Channel entity could have a new field, timezone which would be a string conforming to the IANA timezone database (e.g. `Europe/Vienna').

This would be exposed via the Channel type in the Admin API. When datetimes have to be entered (e.g. in setting up a Promotion) then this timezone value is used to make the specified time conform the the Channel's timezone. So If the European admin enters 6pm, then it is saved as 6pm GMT (actually the UTC representation thereof).

For listing datetimes, it generally makes sense to keep displaying them in the local timezone. So an Order that came in at 7.30pm GMT is displayed as 8.30pm CET to the European admin, which makes sense (at 8.45pm CET the admin correctly thinks "this order came in 15 minutes ago").

martijnvdbrug commented 3 months ago

@michaelbromley Is this issue still needed? If so, should it get the label feature?

michaelbromley commented 3 months ago

Let's label it as a feature, but low prio is right.