Skip to content

Instantly share code, notes, and snippets.

@DanWebb
Last active October 23, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanWebb/9ed3841a52b3b799c489 to your computer and use it in GitHub Desktop.
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.
{% 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 %}
@ckhatton
Copy link

👍 Noice!

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