Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui / dist / forms / deps / isValidDates.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const mobx_1 = require("xmobx/mobx");

const exotic_1 = require("exotic");

const isValidExpiryDate_1 = require("./isValidExpiryDate"); // time match hours, minutes, and seconds, 24-hour clock


const matchTimeString = /^(2[0-3]|[01]?[0-9]):([0-5]?[0-9]):([0-5]?[0-9])$/; // dateString match m/d/yy and mm/dd/yyyy, allowing any combination of one or two digits for the day and month, and two or four digits for the year

const matchFullDate = /^(1[0-2]|0?[1-9])([\/-])(3[01]|[12][0-9]|0?[1-9])(?:\2)(?:[0-9]{2})?[0-9]{2}$/;
const matchMonthSpecicalChar = /^\d{0,2}(?:\.\d)?$/;
const matchMonth = /^[0-9]*$/gm;
/**
 * @param {String | Date} value
 * @return {Boolean}
 */
// function isValidMonth(value) {
//   // .value == new Date().getFullYear()
//   const isBeforeOneMonthAhead = value < new Date().getMonth() + 1
//   // The credit card has expired. Choose a different expiration date.
//   if (isBeforeOneMonthAhead) {
//     return false
//   }
//   return true
// }

const dateContainer = mobx_1.observable({
  month: '',
  year: ''
});
/**
 * @see https://date-fns.org/
 *
 * @todo - use date_fns
 * @todo - use in the dateParse util
 * @todo - use in time atom
 */

const monthValidateToZero = item => {
  const zero = 0;
  const value = item.length >= 2 ? item : zero + item;
  return value;
};

const matchLimit = month => {
  // const removeSpecialCharacters = month.replace(matchMonthSpecicalChar, '')
  // const validateToZero = monthValidateToZero(month)
  return month > 0 && month <= 12;
};

exports.monthValidationForYear = (month, year) => {
  const currentDate = new Date();
  const currentMonth = currentDate.getMonth() + 1;

  if (year === exotic_1.toNumber(isValidExpiryDate_1.currentYear) || year === exotic_1.toNumber(isValidExpiryDate_1.currentYearTwoDigit)) {
    return currentMonth <= month;
  } else {
    return matchLimit(month);
  }
};

class ExpiryDateValidation {
  constructor() {
    this.isValidMonth = (year, month) => {
      if (month && exports.monthValidationForYear(month, year) && matchMonthSpecicalChar.test(month)) {
        return true;
      } else {
        return false;
      }
    };

    this.isValidYear = (year, month) => {
      const expiryYearLength = year.toString().length;
      const validYear = false;

      if (expiryYearLength === 4 && year >= exotic_1.toNumber(isValidExpiryDate_1.currentYear) || expiryYearLength === 2 && year >= exotic_1.toNumber(isValidExpiryDate_1.currentYearTwoDigit)) {
        const result = isValidMonth(year, month);
        return result;
      }

      return validYear;
    };
  }

  isValidTimeOrDay() {//
  }

}

const expiryDate = new ExpiryDateValidation();
exports.expiryDate = expiryDate;
const isValidMonth = expiryDate.isValidMonth;
exports.isValidMonth = isValidMonth;
const isValidYear = expiryDate.isValidYear;
exports.isValidYear = isValidYear; //# sourceMappingURL=isValidDates.js.map