export default class PublisherUtils {


  static getDate(date) {
    if (!date) {
      date = new Date();
    }

    let dateStr = (date.getDate());
    dateStr += '/';
    dateStr += date.getMonth() + 1;
    dateStr += '/';
    dateStr += date.getFullYear().toString().substring(2, 4);

    return dateStr;
  };

  static getDateAndTime(date, includeSeconds = false) {
    if (!date) {
      date = new Date();
    }

    let dateStr = (date.getDate());
    dateStr += '/';
    dateStr += date.getMonth() + 1;
    dateStr += '/';
    dateStr += date.getFullYear().toString().substring(2, 4);
    dateStr += ' ';
    dateStr += date.getHours();
    dateStr += ':';
    dateStr += ('0' + date.getMinutes()).substr(-2);
    if (includeSeconds) {
      dateStr += ':';
      dateStr += ('0' + date.getSeconds()).substr(-2);
    }

    return dateStr;
  };

  static getDateAndTimeForFile(date) {
    if (!date) {
      date = new Date();
    }

    let dateStr = date.getFullYear().toString();
    dateStr += ('0' + (date.getMonth() + 1)).substr(-2);
    dateStr += ('0' + date.getDate()).substr(-2);
    dateStr += '_';
    dateStr += ('0' + date.getHours()).substr(-2);
    dateStr += ('0' + date.getMinutes()).substr(-2);
    dateStr += ('0' + date.getSeconds()).substr(-2);

    return dateStr;
  };

  static cleanLog(log, removeProperties) {
    let properties = Object.keys(log);
    properties.forEach(function(prop) {
      if (removeProperties.includes(prop)){
        delete log[prop];
      } else if (log[prop] && typeof log[prop] === 'object'){
        log[prop] = PublisherUtils.cleanLog(log[prop], removeProperties);
      }
    });
    return log;
  }

  static async sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

}
