tryParseDistance(text) {
    if (text.length < 2) {
      return null;
    }

    const shiftAmount = text.slice(0, Math.max(0, text.length - 1));
    // False positive of ESLint: Number.isNaN cannot recognize arbitrary text (e.g. "test") as NaN. So use direct isNaN.
    /* eslint-disable unicorn/prefer-number-properties */
    if (isNaN(shiftAmount) || Number.parseInt(shiftAmount, 10) <= 0) {
      return null;
    }
    /* eslint-enable unicorn/prefer-number-properties */

    const unit = text[text.length - 1];
    let shiftType = ShiftTypes.milliseconds;
    switch (unit) {
      case this.langManager.getString(TimeArgUnits.year):
        shiftType = ShiftTypes.years;
        break;
      case this.langManager.getString(TimeArgUnits.month):
        shiftType = ShiftTypes.months;
        break;
      case this.langManager.getString(TimeArgUnits.week):
        shiftType = ShiftTypes.weeks;
        break;
      case this.langManager.getString(TimeArgUnits.day):
        shiftType = ShiftTypes.days;
        break;
      case this.langManager.getString(TimeArgUnits.hour):
        shiftType = ShiftTypes.hours;
        break;
      case this.langManager.getString(TimeArgUnits.minute):
        shiftType = ShiftTypes.minutes;
        break;
      case this.langManager.getString(TimeArgUnits.second):
        shiftType = ShiftTypes.seconds;
        break;
      default:
        return null;
    }

    return [{ amount: Number.parseInt(shiftAmount, 10), shiftType }];
  }
/**
   * Tries to parse a distance time definition from text.
   * @param  {string}          text the text to parse
   * @return {(Array | null)}       array of objects containing the shift type and amount, or null if unsuccessful
   */
Tries to parse a distance time definition from text.
@param  {string}          text the text to parse
@return {(Array | null)}       array of objects containing the shift type and amount, or null if unsuccessful
Tries to parse a distance time definition from text . @param { string } text the text to parse @return { ( Array | null ) } array of objects containing the shift type and amount or null if unsuccessful
tryParseDistance(text) {
    if (text.length < 2) {
      return null;
    }
    const shiftAmount = text.slice(0, Math.max(0, text.length - 1));
    if (isNaN(shiftAmount) || Number.parseInt(shiftAmount, 10) <= 0) {
      return null;
    }
    const unit = text[text.length - 1];
    let shiftType = ShiftTypes.milliseconds;
    switch (unit) {
      case this.langManager.getString(TimeArgUnits.year):
        shiftType = ShiftTypes.years;
        break;
      case this.langManager.getString(TimeArgUnits.month):
        shiftType = ShiftTypes.months;
        break;
      case this.langManager.getString(TimeArgUnits.week):
        shiftType = ShiftTypes.weeks;
        break;
      case this.langManager.getString(TimeArgUnits.day):
        shiftType = ShiftTypes.days;
        break;
      case this.langManager.getString(TimeArgUnits.hour):
        shiftType = ShiftTypes.hours;
        break;
      case this.langManager.getString(TimeArgUnits.minute):
        shiftType = ShiftTypes.minutes;
        break;
      case this.langManager.getString(TimeArgUnits.second):
        shiftType = ShiftTypes.seconds;
        break;
      default:
        return null;
    }
    return [{ amount: Number.parseInt(shiftAmount, 10), shiftType }];
  }
tryParseDistance ( text ) { if ( text . length < 2 ) { return null ; } const shiftAmount = text . slice ( 0 , Math . max ( 0 , text . length - 1 ) ) ; if ( isNaN ( shiftAmount ) || Number . parseInt ( shiftAmount , 10 ) <= 0 ) { return null ; } const unit = text [ text . length - 1 ] ; let shiftType = ShiftTypes . milliseconds ; switch ( unit ) { case this . langManager . getString ( TimeArgUnits . year ) : shiftType = ShiftTypes . years ; break ; case this . langManager . getString ( TimeArgUnits . month ) : shiftType = ShiftTypes . months ; break ; case this . langManager . getString ( TimeArgUnits . week ) : shiftType = ShiftTypes . weeks ; break ; case this . langManager . getString ( TimeArgUnits . day ) : shiftType = ShiftTypes . days ; break ; case this . langManager . getString ( TimeArgUnits . hour ) : shiftType = ShiftTypes . hours ; break ; case this . langManager . getString ( TimeArgUnits . minute ) : shiftType = ShiftTypes . minutes ; break ; case this . langManager . getString ( TimeArgUnits . second ) : shiftType = ShiftTypes . seconds ; break ; default : return null ; } return [ { amount : Number . parseInt ( shiftAmount , 10 ) , shiftType } ] ; }
Tries to parse a distance time definition from text.
Tries to parse a distance time definition from text .
// False positive of ESLint: Number.isNaN cannot recognize arbitrary text (e.g. "test") as NaN. So use direct isNaN. /* eslint-disable unicorn/prefer-number-properties */ /* eslint-enable unicorn/prefer-number-properties */