Last active
October 23, 2015 07:50
-
-
Save DanWebb/9ed3841a52b3b799c489 to your computer and use it in GitHub Desktop.
Display whether a product or is new or not. Could also apply to other objects that have the created_at property.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% comment %} | |
Get the unix time between today and the date the product was created. | |
If there's less than 30 days (2592008) between the two times display it as new. | |
Note: "times: 1" is used to make sure the timestamp is an int not a string | |
Example usage: | |
{% include 'new_item' with product %} | |
{% endcomment %} | |
{% assign created = new_item.created_at | date: '%s' | times: 1 %} | |
{% assign today = 'now' | date: '%s' | times: 1 %} | |
{% assign time_diff = today | minus: created %} | |
{% if time_diff <= 2592008 %} | |
<h1>This item is less than a 30 days old</h1> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Noice!