Created
August 28, 2014 22:08
-
-
Save rdallaire/562645b38d07c1f261eb to your computer and use it in GitHub Desktop.
daysleft
This file contains hidden or 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 %} | |
====================================================== | |
To account for the differences between client time | |
and server time (PST), set the "offset" variable. To | |
find the offset, solve for X, using the equation below: | |
(server time) + X = (client Time) | |
Sample UK Time: -8 + X = 0 (so X = 8) | |
Sample Hawaiin Time: -8 +X = -10 (so X = -2) | |
====================================================== | |
{% endcomment %} | |
{% comment %}Set offset variable to display correct time to client{% endcomment %} | |
{% assign offset = -2 %} | |
{% comment %}Set the variable for the hour based on 'now'{% endcomment %} | |
{% assign hour = 'now' | date: "%H" | plus: offset %} | |
{% comment %}Set the variable for the day based on 'now'{% endcomment %} | |
{% assign day = 'now' | date: "%d" | times: 1%} | |
{% comment %}Set the variable for the month based on 'now'{% endcomment %} | |
{% assign month = 'now' | date: "%m" | times: 1 %} | |
{% comment %}Set the variable for the year based on 'now'{% endcomment %} | |
{% assign year = 'now' | date: "%y" | times: 1 %} | |
{% comment %}If the hour is less than zero{% endcomment %} | |
{% if hour < 0 %} | |
{% comment %}Set the number of hours in a given day{% endcomment %} | |
{% assign hour = hour | plus: 24 %} | |
{% comment %}Start the 'day' variable index{% endcomment %} | |
{% if day > 1 %} | |
{% comment %}Make day index equate to zero{% endcomment %} | |
{% assign day = day | minus: 1 %} | |
{% else %} | |
{% comment %}Set variables for January{% endcomment %} | |
{% if month == 1 %} | |
{% comment %}Number of days in month{% endcomment %} | |
{% assign day = 31 %} | |
{% comment %}Number of months in a given year{% endcomment %} | |
{% assign month = 12 %} | |
{% assign month = year | minus: 1 %} | |
{% comment %}Set variables for the month of Febuary{% endcomment %} | |
{% elsif month == 3 %} | |
{% comment %}Number of days in month{% endcomment %} | |
{% assign day = 28 %} | |
{% assign month = month | minus: 1 %} | |
{% comment %}Set the variables for all months with 30 days{% endcomment %} | |
{% elsif month == 5 or month == 7 or month == 10 or month == 12 %} | |
{% comment %}Number of days in month{% endcomment %} | |
{% assign day = 30 %} | |
{% assign month = month | minus: 1 %} | |
{% comment %}Set variables for remaining months (31 days){% endcomment %} | |
{% else %} | |
{% comment %}Number of days in month{% endcomment %} | |
{% assign day = 31 %} | |
{% assign month = month | minus: 1 %} | |
{% endif %} | |
{% endif %} | |
{% comment %}If the hour is greater than 23{% endcomment %} | |
{% elsif hour > 23 %} | |
{% comment %}If day is less than 28{% endcomment %} | |
{% if day < 28 %} | |
{% assign day = day | plus: 1 %} | |
{% comment %}If month is 2 and day is 29{% endcomment %} | |
{% elsif month == 2 and day == 29 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 2 and day is 28{% endcomment %} | |
{% elsif month == 2 and day == 28 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 4 and day is 30{% endcomment %} | |
{% elsif day == 30 and month == 4 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 6 and day is 30{% endcomment %} | |
{% elsif day == 30 and month == 6 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 9 and day is 30{% endcomment %} | |
{% elsif day == 30 and month == 9 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 11 and day is 30{% endcomment %} | |
{% elsif day == 30 and month == 11 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is not 12 and day is 31{% endcomment %} | |
{% elsif day == 31 and month != 12 %} | |
{% assign day = 1 %} | |
{% assign month = month | plus: 1 %} | |
{% comment %}If month is 12 and day is 31{% endcomment %} | |
{% elsif day == 31 and month == 12 %} | |
{% assign day = 1 %} | |
{% assign month = 1 %} | |
{% assign year = year | plus: 1 %} | |
{% comment %}Otherwise, if month is N and day is N{% endcomment %} | |
{% else %} | |
{% assign day = day | plus: 1 %} | |
{% endif %} | |
{% endif %} |
This file contains hidden or 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
{% include 'daily_deal_time' %} | |
{% comment %}<h1>{{ 30 | minus: day }}</h1>{% endcomment %} | |
{% comment %}31{% endcomment %} | |
{% if month == 9 %} | |
{% if day == 15 %} | |
{% comment %}TODAY IS THE DAY!{% endcomment %} | |
{% else %} | |
{{ 15 | minus: day }} days left | |
{% endif %} | |
{% elsif month == 8 %} | |
{{ 46 | minus: day }} days left | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment