Quoting myself from #2881791: Computed field value for DateTime field causes start time validation error:

Also, note that there's another problem here: because the date field stores no timezone, the promotion start/end dates are always specific to the customer's timezone. If you specified June 1st - June 10th assuming the EST timezone, and I'm in the GMT timezone, then the promotion will start earlier for me than for someone who's in EST. We could solve this by having a $store->timezone that's used for these things.

There's the same problem with taxes. If your tax changes from 18% to 19% on June 1st, do you switch when it's June 1st to the store, or June 1st to the customer? Cause if it's a US store, the EU customer will reach June 1st first, for example.
Logic says "June 1st to the store, since the store reports taxes", though I wonder if there will be potential confusion for the customer who'll see their invoice date be May 31st.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

shabana.navas’s picture

Status: Active » Needs review
FileSize
6.72 KB

Patch that adds a base default timezone field to the store entity.

Nils Loewen’s picture

Status: Needs review » Needs work
FileSize
7.2 KB

Great work Shabana.

I changed all defaults of 'UTC' to DateTimeItemInterface::STORAGE_TIMEZONE, which happens to be 'UTC', but use of the constant will be better in the long run.

Before writing tests for this, a new feature should be added which is a toggle on promotionListBuilder to show dates in store timezone or current user timezone, or for that matter, in storage timezone or site default timezone.

We should probably wait till #2977618: Add time to promotion start and end date is committed before adding that feature.

bojanz’s picture

Assigned: Unassigned » bojanz

Time to finish this. We'll need it before proceeding with #2977618: Add time to promotion start and end date.

Committed #3093784: Add the concept of an order "calculation date" which should help.

bojanz’s picture

Status: Needs work » Needs review
FileSize
16.29 KB

Here's part 1.

Adds the $store->timezone field and converts commerce_tax to use it. The promotion part is yet to come.

I started from the patch in #3 and renamed "default_timezone" to "timezone", cause I felt that the "default_" prefix was unnecessary.
I also made the field default to the site timezone, and not UTC, since that's more user friendly

bojanz’s picture

Here's part 2.

Promotions are now also converted.
Introduced StoreDateTimeWidget and StoreDateTimeFormatter, which respect the store timezone logic (and can be used by both commerce_promotion and commerce_pricelist). Currently still missing test coverage for them.

We're also missing the normalizer/denormalizer, but I'll leave that for a followup.

bojanz’s picture

This should be the final patch.

Adds test coverage for the new widget and formatter, and fixes a few warnings in them along the way.

bojanz’s picture

Title: Create a $store->timezone base field » Create a $store->timezone field and use it for promotions and taxes

Better title.

  • bojanz committed 5ea6ace on 8.x-2.x
    Issue #2883789 by bojanz, shabana.navas, nlz: Create a $store->timezone...
bojanz’s picture

Status: Needs review » Fixed

Committed.

  • bojanz committed 8740f20 on 8.x-2.x
    Issue #2883789 followup: Simplify StoreDateTimeWidget, never show the...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.