static async scan(context, langManager, message, text) {
    if (text === undefined || text === null || text === '') {
      return { value: null, nextPos: 1 };
    }

    const timeArg = new TimeArg(langManager);

    // Check if the text contains a valid type marker or at least a valid time definition.
    let nextSpace = OhUtils.findFirstNonQuotedIndex(text, ' ');
    if (nextSpace === -1) {
      nextSpace = text.length;
    }

    const firstDef = text.slice(0, Math.max(0, nextSpace));
    if (!timeArg.isValidTimeType(firstDef) && !timeArg.isValidTimeDef(firstDef)) {
      return { value: null, nextPos: 1 };
    }

    // If the first part of the text marks the type of the time arg, then set the type,
    // otherwise consider the type as "distance" and start to parse time definitions.
    if (timeArg.isValidTimeType(firstDef)) {
      timeArg.setTimeType(timeArg.parseTimeType(firstDef));
    } else {
      timeArg.setTimeType(TimeArg.DISTANCE_TYPE);
      timeArg.addDefinition(firstDef);
    }

    let nextPos = firstDef.length + 1;
    let nextText = text.slice(Math.max(0, nextPos));
    nextSpace = OhUtils.findFirstNonQuotedIndex(nextText, ' ');
    if (nextSpace === -1) {
      nextSpace = nextText.length;
    }

    let nextDef = nextText.slice(0, Math.max(0, nextSpace));

    // Scan and add definitions until the next part of text does not looks like a valid definition.
    // This can happen either when the text is not a definition at all, or when the next
    // definition cannot be added to the existing definitions. E.g. when a month is defined in the same arg
    // as dayofweek, or when the same definition type is defined twice.
    while (timeArg.isValidTimeDef(nextDef)) {
      timeArg.addDefinition(nextDef);

      nextPos = nextPos + nextDef.length + 1;
      nextText = nextText.slice(Math.max(0, nextSpace + 1));

      nextSpace = OhUtils.findFirstNonQuotedIndex(nextText, ' ');
      if (nextSpace === -1) {
        nextSpace = nextText.length;
      }

      nextDef = nextText.slice(0, Math.max(0, nextSpace));
    }

    // Adds the timezone definition based of org/user settings
    await this.appendTimezone(context, message, timeArg);
    // Auto complete definitions based on the type of the argument ("any" value for recurrent types etc.).
    timeArg.autoCompleteDefinitions();

    return { value: timeArg, nextPos };
  }
/**
   * Parses the given text to make an argument object for a command.
   * @param  {Context}      context     Bot's context
   * @param  {LangManager}  langManager Lang manager of the command
   * @param  {Object}       message     Message's object (source-dependent)
   * @param  {string}       text        Text to be scanned to parse the argument
   * @return {Promise}                  Promise of the parsed object of the argument and how many chars were scanned
   */
Parses the given text to make an argument object for a command.
Parses the given text to make an argument object for a command .
static async scan(context, langManager, message, text) {
    if (text === undefined || text === null || text === '') {
      return { value: null, nextPos: 1 };
    }
    const timeArg = new TimeArg(langManager);
    let nextSpace = OhUtils.findFirstNonQuotedIndex(text, ' ');
    if (nextSpace === -1) {
      nextSpace = text.length;
    }
    const firstDef = text.slice(0, Math.max(0, nextSpace));
    if (!timeArg.isValidTimeType(firstDef) && !timeArg.isValidTimeDef(firstDef)) {
      return { value: null, nextPos: 1 };
    }
    if (timeArg.isValidTimeType(firstDef)) {
      timeArg.setTimeType(timeArg.parseTimeType(firstDef));
    } else {
      timeArg.setTimeType(TimeArg.DISTANCE_TYPE);
      timeArg.addDefinition(firstDef);
    }
    let nextPos = firstDef.length + 1;
    let nextText = text.slice(Math.max(0, nextPos));
    nextSpace = OhUtils.findFirstNonQuotedIndex(nextText, ' ');
    if (nextSpace === -1) {
      nextSpace = nextText.length;
    }
    let nextDef = nextText.slice(0, Math.max(0, nextSpace));
    while (timeArg.isValidTimeDef(nextDef)) {
      timeArg.addDefinition(nextDef);
      nextPos = nextPos + nextDef.length + 1;
      nextText = nextText.slice(Math.max(0, nextSpace + 1));
      nextSpace = OhUtils.findFirstNonQuotedIndex(nextText, ' ');
      if (nextSpace === -1) {
        nextSpace = nextText.length;
      }
      nextDef = nextText.slice(0, Math.max(0, nextSpace));
    }
    await this.appendTimezone(context, message, timeArg);
    timeArg.autoCompleteDefinitions();
    return { value: timeArg, nextPos };
  }
static async scan ( context , langManager , message , text ) { if ( text === undefined || text === null || text === '' ) { return { value : null , nextPos : 1 } ; } const timeArg = new TimeArg ( langManager ) ; let nextSpace = OhUtils . findFirstNonQuotedIndex ( text , ' ' ) ; if ( nextSpace === - 1 ) { nextSpace = text . length ; } const firstDef = text . slice ( 0 , Math . max ( 0 , nextSpace ) ) ; if ( ! timeArg . isValidTimeType ( firstDef ) && ! timeArg . isValidTimeDef ( firstDef ) ) { return { value : null , nextPos : 1 } ; } if ( timeArg . isValidTimeType ( firstDef ) ) { timeArg . setTimeType ( timeArg . parseTimeType ( firstDef ) ) ; } else { timeArg . setTimeType ( TimeArg . DISTANCE_TYPE ) ; timeArg . addDefinition ( firstDef ) ; } let nextPos = firstDef . length + 1 ; let nextText = text . slice ( Math . max ( 0 , nextPos ) ) ; nextSpace = OhUtils . findFirstNonQuotedIndex ( nextText , ' ' ) ; if ( nextSpace === - 1 ) { nextSpace = nextText . length ; } let nextDef = nextText . slice ( 0 , Math . max ( 0 , nextSpace ) ) ; while ( timeArg . isValidTimeDef ( nextDef ) ) { timeArg . addDefinition ( nextDef ) ; nextPos = nextPos + nextDef . length + 1 ; nextText = nextText . slice ( Math . max ( 0 , nextSpace + 1 ) ) ; nextSpace = OhUtils . findFirstNonQuotedIndex ( nextText , ' ' ) ; if ( nextSpace === - 1 ) { nextSpace = nextText . length ; } nextDef = nextText . slice ( 0 , Math . max ( 0 , nextSpace ) ) ; } await this . appendTimezone ( context , message , timeArg ) ; timeArg . autoCompleteDefinitions ( ) ; return { value : timeArg , nextPos } ; }
Parses the given text to make an argument object for a command.
Parses the given text to make an argument object for a command .
// Check if the text contains a valid type marker or at least a valid time definition. // If the first part of the text marks the type of the time arg, then set the type, // otherwise consider the type as "distance" and start to parse time definitions. // Scan and add definitions until the next part of text does not looks like a valid definition. // This can happen either when the text is not a definition at all, or when the next // definition cannot be added to the existing definitions. E.g. when a month is defined in the same arg // as dayofweek, or when the same definition type is defined twice. // Adds the timezone definition based of org/user settings // Auto complete definitions based on the type of the argument ("any" value for recurrent types etc.).