Convert time from 24-hr to standard in cart line items

Follow

Comments

3 comments

  • Avatar
    Zetya Support

    Hi Ryan,

    Yes, this is possible. You need to use the liquid date filter.

    For example, when outputting the value in cart.liquid:  {{ p.last | date: '%m/%d/%y %-I:%M %p' }}

    Gavin

  • Avatar
    Ryan

    Hey Gavin,

    I was wondering of a way to do it using timber's ajax-cart.js, and ajax-cart-template? I have already implemented it as illustrated here: 

    https://gist.github.com/gterrill/3b2b4a11d64dcd6cd092

    https://gist.github.com/gterrill/07222da9c9d3252b3184

    Any help would be greatly appreciated, Thanks!

    Ryan

     

  • Avatar
    Zetya Support

    Hi Ryan,

    Yeah, I'm not a huge fan of how they've done this handlebars templating thing in Timber. Why introduce another templating language when they already have Liquid?

    Anyways, I haven't done this myself yet, but here is how I'd approach it...

    1. To format the date you can use the  formatDate method of the jQuery UI Datepicker.
    2. The value of the line item property is being output on line 27 so you'll need to convert the string to a Date then use formatDate, only if it is the booking start property. This SO answer looks like a promising approach. For a more handlebar-ish way of doing it you might want to check out  http://formatjs.io/handlebars/

    Thanks, Gavin.

Please sign in to leave a comment.