"use strict";

exports.__esModule = true;
exports.addDays = addDays;
exports.getDayNumber = getDayNumber;
exports.getMonthEndDay = getMonthEndDay;
exports.getTrueValue = getTrueValue;
exports.times = times;

var _number = require("../utils/validate/number");

/* eslint-disable no-plusplus */
function times(n, iteratee) {
  var index = -1;
  var result = Array(n);

  while (++index < n) {
    result[index] = iteratee(index);
  }

  return result;
}

function getTrueValue(value) {
  if (!value) {
    return 0;
  }

  while ((0, _number.isNaN)(parseInt(value, 10))) {
    if (value.length > 1) {
      value = value.slice(1);
    } else {
      return 0;
    }
  }

  return parseInt(value, 10);
}

function getMonthEndDay(year, month) {
  return 32 - new Date(year, month - 1, 32).getDate();
}

function addDays(date, days) {
  date = new Date(date.valueOf());
  date.setDate(date.getDate() + days);
  return date;
}

function getDayNumber(date) {
  var newDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
  return newDate.getTime() - newDate.getTime() % (24 * 60 * 60 * 1000);
}