Skip to content

Instantly share code, notes, and snippets.

@siamak
Created July 5, 2020 13:45
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 siamak/ae86a02bd5f187f9cecc91b7f7308b9d to your computer and use it in GitHub Desktop.
Save siamak/ae86a02bd5f187f9cecc91b7f7308b9d to your computer and use it in GitHub Desktop.
function expiration() {
// const due_date = new Date('2019-02-12'); // this date will be current date in most case
const due_date = new Date(); // this date will be current date in most case
const days_deadline = 7; // this is no. of days remaining for expiry date. In this case it will 2019-02-16
/* stop changing here */
const current_date = new Date();
const utc1 = Date.UTC(due_date.getFullYear(), due_date.getMonth(), due_date.getDate());
const utc2 = Date.UTC(current_date.getFullYear(), current_date.getMonth(), current_date.getDate());
const days = Math.floor((utc2 - utc1) / (1000 * 60 * 60 * 24));
if(days > 0) {
const days_late = days_deadline-days;
let opacity = (days_late*100/days_deadline)/100;
opacity = (opacity < 0) ? 0 : opacity;
opacity = (opacity > 1) ? 1 : opacity;
if(opacity >= 0 && opacity <= 1) {
document.getElementsByTagName("BODY")[0].style.opacity = opacity;
}
}
}
document.addEventListener('DOMContentLoaded', expiration);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment