putyourlightson / craft-campaign

Send and manage email campaigns, contacts and mailing lists in Craft CMS.
https://putyourlightson.com/plugins/campaign
Other
63 stars 25 forks source link

DateTime/Timezone issue when using Live Preview to view a Campaign template #360

Closed angrybrad closed 1 year ago

angrybrad commented 1 year ago

Using a fresh install of Craft Pro 3.7.63.1 and Campaign 1.24.0.

{% set newsletter = craft.campaign.getCampaignById(123) %}
<p>{{ newsletter.title }}</p>
<p>{{ newsletter.myDate|date('d')}} / {{ newsletter.myDate|date('F')}} / {{ newsletter.myDate|date('Y')}}</p>

This doesn’t happen with native Date fields outside the context of the Campaign plugin, like on entries.

Haven’t checked to see if this is an issue on Craft 4 / Campaign 2.

bencroker commented 1 year ago

12/21/2023 sounds a lot to my European brain like the 12th day of the 21st month of the 2023rd year. 21 months gives you a remainder of 9 (21 % 12 = 9) plus a carried year, resulting in the the 12th day of the 9th month of 2024th year, i.e. 12 / September / 2024.

Do you see where I'm going with this @angrybrad, or should I continue spelling it out?

angrybrad commented 1 year ago

That explains the math of the results but not the underlying cause of the issue.

The underlying issue is that Campaign 1.x uses the old-school Live Preview request method that Categories use in Craft 3.x.

We were able to reproduce this on Craft 3.x Category Live Preview requests and pushed up a fix here: https://github.com/craftcms/cms/commit/c92d7114c27f77a194203b5925cdc585aadc67f1

And made a PR with the same fix for Campaign here: https://github.com/putyourlightson/craft-campaign/issues/360

You needed to be logged in with a user that had a number/date formatting locale that was different than what the front-end site language/formatting locale was set to to be able to reproduce.

I have yet to check Campaign 2.x, but Craft 4 moved Categories to the newer Live Preview logic, where it’s not an issue, so I’m guessing it’s not an issue in Campaign 2.x, too.

bencroker commented 1 year ago

Aha, I missed the important detail that this was only an issue in Live Preview. Thanks for the PR, merged. This shouldn't be an issue in Campaign 2, as it uses the newer Preview logic.

bencroker commented 1 year ago

Released in version 1.24.1, thanks for the bug report!