Skip to content

Instantly share code, notes, and snippets.

@DannyFeliz
Created September 13, 2016 08:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannyFeliz/ec987793de2b97e92a6fa629695a40dd to your computer and use it in GitHub Desktop.
Save DannyFeliz/ec987793de2b97e92a6fa629695a40dd to your computer and use it in GitHub Desktop.
Add timestamp to webpack
/**
* Get current time
* @example 10:34:12 am
* @param {Date} date
* @returns {string}
*/
function getTime(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
seconds = seconds < 10 ? '0' + seconds : seconds;
return hours + ':' + minutes + ':' + seconds + " " + ampm;
}
/**
* Get current date
* @example 13-09-2016
* @returns {string}
*/
function getDate() {
var currentDate = new Date();
return getTime(currentDate) + " - " +("0" + currentDate.getDate()).slice(-2) + "-" + ("0"+(currentDate.getMonth()+1)).slice(-2) + "-" +
currentDate.getFullYear();
}
plugins: [
function () {
this.plugin('compile', function () {
console.log('Start: ' + getDate().red);
})
},
function () {
this.plugin('done', function () {
console.log('End: ' + getDate().yellow );
})
},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment