Footer: {{moment}} helper displays full date
sacr3dc0w opened this issue · 3 comments
Expected behavior
The copyright in the footer should display: Copyright © 2022
Actual behavior
The copyright in the footer is currently displaying: Copyright © July 13, 2022
Links
Taken from here if this helps. Apologies for the vague issue description: bigcommerce/paper-handlebars#182
There's the behavior that changed in the footer of the Cornerstone theme. The copyright displays the full date. It appears to be impacting at least one other merchant.
{{moment format="YYYY"}}
should display 2022, it is displaying July 13, 2022.
As for our use case, we compared the output of the format in a conditional statement. A simple example is what used to work for the home page banner on our websites:
{{#if (moment format='MM') '===' '07'}}{{/if}}
A more complex example was devised to determine if it was Thanksgiving, Black Friday, or Cyber Monday. This is stored as a component in components/custom/common/thanksgiving-bf-cm-logic.html, which you'll see reference below this example.
{{! Conditional check for the Happy Thanksgiving and Black Friday / Cyber Monday banner }}
{{#if (moment format='MM') '===' '11'}}
{{#if source '===' 'home'}}
{{! Thanksgiving always falls on the fourth Thursday, so let's calculate to make sure it's nth day of week of the month }}
{{#if (ceil (divide (moment format='DD') 7)) '===' 4}}
{{! Let's display the Thanksgiving banner on Wednesday as well }}
{{#any
(if (moment format='dddd') '===' 'Wednesday')
(if (moment format='dddd') '===' 'Thursday')
}}
{{assignVar "homeBanner--happyThanksgiving" 1}}
{{/any}}
{{/if}}
{{/if}}
{{! Either the 4th day of the week of the month or the 5th. }}
{{#or
(if (ceil (divide (moment format='DD') 7)) '===' 4)
(if (ceil (divide (moment format='DD') 7)) '===' 5)
}}
{{#if (moment format='dddd') '===' 'Sunday'}}
{{! Check that the previous Thursday was the fourth Thursday of the month}}
{{#if (ceil (divide (subtract (moment format='DD') 3) 7)) '===' 4}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/if}}
{{else if (moment format='dddd') '===' 'Monday'}}
{{! Check that the previous Thursday was the fourth Thursday of the month}}
{{#if (ceil (divide (subtract (moment format='DD') 4) 7)) '===' 4}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/if}}
{{else if (moment format='dddd') '===' 'Friday'}}
{{! Check that the previous Thursday was the fourth Thursday of the month}}
{{#if (ceil (divide (subtract (moment format='DD') 1) 7)) '===' 4}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/if}}
{{else if (moment format='dddd') '===' 'Saturday'}}
{{! Check that the previous Thursday was the fourth Thursday of the month}}
{{#if (ceil (divide (subtract (moment format='DD') 2) 7)) '===' 4}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/if}}
{{/if}}
{{/or}}
{{else if (moment format='MM') '===' '12'}}
{{! The conditionals below are only met in 2024/2025 and 2030/2031, etc. }}
{{#if (ceil (divide (moment format='DD') 7)) '===' 1}}
{{#and
(if (moment format='D') '===' '1')
(if (moment format='dddd') '===' 'Sunday')
}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/and}}
{{#if (moment format='dddd') '===' 'Monday'}}
{{#or
(if (moment format='D') '===' '1')
(if (moment format='D') '===' '2')
}}
{{assignVar "homeBanner--blackFridayCyberMonday" 1}}
{{/or}}
{{/if}}
{{/if}}
{{/if}}
{{! Conditional check for the Happy Halloween banner }}
{{#and
(if (moment format='MM-DD') '>=' '10-24')
(if (moment format='MM-DD') '<=' '10-31')
}}
{{assignVar "homeBanner--happyHalloween" 1}}
{{/and}}
{{> components/custom/common/thanksgiving-bf-cm-logic source='home'}}
{{#if (getVar "homeBanner--blackFridayCyberMonday") '===' 1}}
{{> components/custom/common/hero-banners hero = 'black-friday-cyber-monday'}}
{{else if (getVar "homeBanner--happyHalloween") '===' 1}}
{{> components/custom/common/hero-banners hero = 'halloween'}}
{{else if (getVar "homeBanner--happyThanksgiving") '===' 1}}
{{> components/custom/common/hero-banners hero = 'thanksgiving'}}
{{else if (moment format='MM') '===' '09'}}
{{> components/custom/common/hero-banners hero = 'lt-giveaway'}}
{{else if (moment format='MM-DD') '===' '11-11'}}
{{> components/custom/common/hero-banners hero = 'veterans-day'}}
{{else if (moment format='MM-YYYY') '===' '02-2022'}}
{{> components/custom/common/hero-banners hero = 'pipe-marking-season'}}
{{else if (moment format='MM-DD') '<=' '04-30'}}
{{> components/custom/common/hero-banners hero = 'labeltac-bundles'}}
{{else if (moment format='MM') '===' '07'}}
{{> components/custom/common/hero-banners hero = 'lt-sale-july-2022'}}
{{else}}
{{> components/custom/common/hero-banners hero = 'labeltac-default'}}
{{/if}}
Can confirm I noticed this as well the other day on a few stores and had to manually fix.
A helpful explanation for those who stumble upon this thread.
"Our engineering teams have been making some recent efforts to modernize some third-party helper libraries that BigCommerce leverages, such as moment. These changes had to be reverted/patched multiple times due to unexpected issues such as the one described by this case, from late June through last week.
These changes are now fully implemented, and looking over the examples provided on the case, the moment helper appears to be working as expected in all cases. The only issue we are currently aware of with moment is related to a datejs issue for dates that are on the 30th of the month (format returned is incorrect), which can be worked around by adding the argument datejs=false to any moment helper that may be causing this issue. If there are still general issues with the format that are occurring with the helper that do not match this behavior, please let us know. Thank you for choosing BigCommerce."