Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding two helpers to make it easier to compare dates #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

elephantengine
Copy link
Contributor

FUNCTIONS

  • phpDateToTimestamp(dateString)
  • getTime()

DESCRIPTION (WHAT)
The Stencil framework returns date strings using a PHP format of "M jS Y" in the
page context. This function converts the string to milliseconds since Jan 1, 1970in order to make it easier to perform date comparisons and operations.

USE CASE (WHY)
Some examples of how this would be used include the following story: As a merchant,
I want to display a carousel on my category pages that displays cards for products
that were added to the catalog within the last month. In order to do that, I need
to be able to convert the "date added" field that appears in the product cards under
the category.products object. Likewise, the same behavior would apply to brand pages
with products.

USAGE

{{#if (phpDateToTimestamp 'category.products[0].date_added.') >
((getTime) - theme_settings.new_product_lag)) }}
/* product is newer than the given time interval */
{{/if}}

and similarly with brands: 'brands.products[0].date_added.')

@mcampa

@davidchin
Copy link
Contributor

Thanks for your contribution. However, I'm not 100% sure how this would work. As far as I know, the formatted dates M jS Y don't contain timezone information (you can't assume it is always GMT). So you don't have enough information to transform them into timestamps. Hence, you can't compare with the current time reliably.

Instead of doing the conversion in the template layer, maybe we should provide unformatted timestamps in Stencil resources? @mcampa what are your thoughts?

@elephantengine
Copy link
Contributor Author

In the developer documentation for the BigCommerce API, it mentions that all dates are returned in GMT - wouldn't that also be the case in terms of Stencil?

@mcampa
Copy link
Contributor

mcampa commented Feb 20, 2017

I agree with @davidchin, we should provide the timestamp. The getTime helper can stay though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants