Skip to content

Instantly share code, notes, and snippets.

@gterrill
Last active December 17, 2015 23:59
Show Gist options
  • Save gterrill/5692966 to your computer and use it in GitHub Desktop.
Save gterrill/5692966 to your computer and use it in GitHub Desktop.
Display end dates based on default duration
<!-- inside cart.items for loop -->
{% for p in item.properties %}
{% unless p.last == blank %}
<span class="date" data-date="{{ p.last | date:'%c' }}" data-duration="{{ item.variant.metafields.bookthatapp.duration }}">{{ p.first | replace: 'booking-start', 'Date' | replace: 'booking-time', 'Time' }}:&nbsp{% if p.last contains '/uploads/' %}{{ p.last | split: '/' | last }}{% else %}{{ p.last }}{% endif %}</span><br />
{% endunless %}
{% endfor %}
<script type="text/javascript">// at the bottom of cart.liquid
pad = function(n) {
return ('0' + n).slice(-2);
}
jQuery(document).ready(function($) {
$('span.date').each(function() {
var start = new Date($(this).attr('data-date')),
days = parseInt($(this).attr('data-duration'), 10)/1440,
finish = new Date();
finish.setDate(start.getDate() + days);
var text = ' - ' + pad(finish.getMonth() + 1) + "/" + pad(finish.getDate()) + "/" + finish.getFullYear()
$(this).append($('<span>').text(text));
})
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment