Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Created April 30, 2021 15:03
Show Gist options
  • Save cgi-caesar/86c99535e13466c2dc19ee07ea98c7da to your computer and use it in GitHub Desktop.
Save cgi-caesar/86c99535e13466c2dc19ee07ea98c7da to your computer and use it in GitHub Desktop.
aMember (site.js): change absolute dates to relative in Active Subscription widget
jQuery(function(){
jQuery('.am-list-subscriptions-date_expires_date, .am-list-subscriptions-date_rebill_date, .am-list-subscriptions-date_future_date').each(function(){
if (jQuery(this).data('date') == '2037-12-31') return;
const today = new Date().toISOString().slice(0, 10)
const diffInDays = 1 + (new Date(jQuery(this).data('date')) - new Date(today)) / (1000 * 60 * 60 * 24);
jQuery(this).attr('title', jQuery(this).html());
jQuery(this).html(`in ${diffInDays} ${diffInDays == 1 ? 'day' : 'days'}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment