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    
ui-component-library / src / forms / deps / isValidDates.ts
Size: Mime:
import React from 'react'
import { observer } from 'xmobx/mobx-react'
import { observable } from 'xmobx/mobx'
import { size } from 'chain-able-boost'
import { toNumber } from 'exotic'
import {
  isValidDate,
  currentYear,
  currentYearTwoDigit,
} from './isValidExpiryDate'

type MonthYearType = string | number
// 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}$/

/**
 * @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 = observable({
  month: '',
  year: '',
})
/**
 * @see https://date-fns.org/
 *
 * @todo - use date_fns
 * @todo - use in the dateParse util
 * @todo - use in time atom
 */

// function isValidDate() {
//   //
// }
// @observer
// extends React.Component
class ExpiryDateValidation {
  isValidMonth = (month: MonthYearType): boolean => {
    if (month && month > 0 && month <= 12) {
      return true
    } else {
      return false
    }
  }
  isValidYear = (year: MonthYearType): boolean => {
    if (year >= toNumber(currentYear)) {
      return true
    } else {
      const expiryYearLength = year.length
      let validYear = false
      if (expiryYearLength >= 4) {
        validYear = false
      } else if (
        year >= toNumber(currentYearTwoDigit) &&
        expiryYearLength === 2
      ) {
        validYear = true
      }
      return validYear
    }
  }
  isValidTimeOrDay() {
    //
  }
}

const expiryDate = new ExpiryDateValidation()
const isValidMonth = expiryDate.isValidMonth
const isValidYear = expiryDate.isValidYear

export { isValidMonth, isValidYear, expiryDate }