function twoDigit(number) {
  return ('0' + number).slice(-2);
}

function timestamp(date) {
  date = date || new Date();
  return [ date.getFullYear(), twoDigit(date.getMonth() + 1), twoDigit(date.getDate()) ].join('-') + 
    ' ' +
    [ twoDigit(date.getHours()), twoDigit(date.getMinutes()), twoDigit(date.getSeconds()) ].join(':');
}

module.exports = {
  timestamp
};