<commit_before>import UtilityService from './utility';
import Alphanumeric from './alpha';
import DateRange from './entities/dateRange';
import dateformat from 'dateformat';

export default class Calendar {

  constructor(lang = 'us') {
    this.lang = lang;
    this.utility = new UtilityService(this.lang);
    this.alpha = new Alphanumeric(this.lang);
  }

  second() {
    const second = this.alpha.randomNumber(0, 59);
    return second <= 9 ? `0${second}` : second;
  }

  minute() {
    return this.second();
  }

  hour24(format24h = true) {
    return format24h ? this.alpha.randomNumber(1, 24) : this.alpha.randomNumber(1, 12);
  }

  time(format24h = true) {
    const hour = this.hour24(format24h);
    if (hour <= 9) {
      return `0${hour}:${this.minute()}`;
    }
    return `${hour}:${this.minute()}`;
  }

  ampm() {
    return this.alpha.randomNumber(0, 10) < 5 ? 'am' : 'pm';
  }

  day() {
    const randomDay = this.alpha.randomNumber(1, 31);
    return randomDay <= 9 ? `0${randomDay}` : randomDay;
  }

  dayOfWeek() {
    return this.utility.getValue('calendar.day_of_week');
  }

  month(params = { asNumber: false, short: false }) {
    if (params.asNumber) {
      const monthNumber = this.alpha.randomNumber(1, 12);
      return monthNumber <= 9 ? `0${monthNumber}` : monthNumber;
    }
    const month = this.utility.getValue('calendar.month');
    return params.short ? month.substring(0, 3) : month;
  }

  year(params = { min: 1940, max: new Date().getFullYear() }) {
    return this.alpha.randomNumber(params.min, params.max);
  }

  date(options = { format: 'dd-mm-yyyy', asString: false }) {
    let randomDate = new Date(`${this.month({ asNumber: true })}-${this.day()}-${this.year()}`);
    while (Object.prototype.toString.call(randomDate) !== '[object Date]') {
      randomDate = this.date({ format: options.format, asString: options.asString });
    }
    if (options.asString) {
      return dateformat(randomDate, options.format);
    }
    return randomDate;
  }

  century() {
    return this.utility.getValue('calendar.centuries');
  }

  dateRange() {
    return new DateRange();
  }
}<commit_msg>remove usage of dateformat library. use moment instead<commit_after>import UtilityService from './utility';
import Alphanumeric from './alpha';
import DateRange from './entities/dateRange';
import moment from 'moment';

export default class Calendar {

  constructor(lang = 'us') {
    this.lang = lang;
    this.utility = new UtilityService(this.lang);
    this.alpha = new Alphanumeric(this.lang);
  }

  second() {
    const second = this.alpha.randomNumber(0, 59);
    return second <= 9 ? `0${second}` : second;
  }

  minute() {
    return this.second();
  }

  hour24(format24h = true) {
    return format24h ? this.alpha.randomNumber(1, 24) : this.alpha.randomNumber(1, 12);
  }

  time(format24h = true) {
    const hour = this.hour24(format24h);
    if (hour <= 9) {
      return `0${hour}:${this.minute()}`;
    }
    return `${hour}:${this.minute()}`;
  }

  ampm() {
    return this.alpha.randomNumber(0, 10) < 5 ? 'am' : 'pm';
  }

  day() {
    const randomDay = this.alpha.randomNumber(1, 31);
    return randomDay <= 9 ? `0${randomDay}` : randomDay;
  }

  dayOfWeek() {
    return this.utility.getValue('calendar.day_of_week');
  }

  month(params = { asNumber: false, short: false }) {
    if (params.asNumber) {
      const monthNumber = this.alpha.randomNumber(1, 12);
      return monthNumber <= 9 ? `0${monthNumber}` : monthNumber;
    }
    const month = this.utility.getValue('calendar.month');
    return params.short ? month.substring(0, 3) : month;
  }

  year(params = { min: 1940, max: new Date().getFullYear() }) {
    return this.alpha.randomNumber(params.min, params.max);
  }

  date(options = { format: 'DD-MM-YYYY', asString: false }) {
    let randomDate = new Date(`${this.month({ asNumber: true })}-${this.day()}-${this.year()}`);
    while (Object.prototype.toString.call(randomDate) !== '[object Date]') {
      randomDate = this.date({ format: options.format, asString: options.asString });
    }
    if (options.asString) {
      return moment(randomDate).format(options.format);
    }
    return randomDate;
  }

  century() {
    return this.utility.getValue('calendar.centuries');
  }

  dateRange() {
    return new DateRange();
  }
}
{'fraction_non_alphanumeric': 0.1662043458159963, 'fraction_numerical': 0.020804438280166437, 'mean_word_length': 3.3226773226773227, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5955360', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1426, 'n_words': 310}