Ejemplo n.º 1
0
int msParseTime(const char *string, struct tm *tm)
{
  int i, indice = 0;
  int num_patterns = 0;
  
  if(msTimeSetup() != MS_SUCCESS) {
    return MS_FALSE;
  }

  /* if limited patterns are set, use then. Else use all the */
  /* patterns defined */
  if (ms_num_limited_pattern > 0)
    num_patterns = ms_num_limited_pattern;
  else
    num_patterns = MS_NUMTIMEFORMATS;

  for(i=0; i<num_patterns; i++) {
    int match;
    if (ms_num_limited_pattern > 0)
      indice = ms_limited_pattern[i];
    else
      indice = i;

    match = ms_regexec(ms_timeFormats[indice].regex, string, 0,NULL, 0);
    /* test the expression against the string */
    if(match == 0) {
      /* match    */
      msStrptime(string, ms_timeFormats[indice].format, tm);
      return(MS_TRUE);
    }
  }

  msSetError(MS_REGEXERR, "Unrecognized date or time format (%s).", "msParseTime()", string);
  return(MS_FALSE);
}
Ejemplo n.º 2
0
/**
   return MS_TRUE if the time string matchs the timeformat.
   else return MS_FALSE.
 */
int msTimeMatchPattern(const char *timestring, const char *timeformat)
{
  int i =-1;
  if(msTimeSetup() != MS_SUCCESS) {
    return MS_FALSE;
  }

  /* match the pattern format first and then check if the time string  */
  /* matchs the pattern. If it is the case retrurn the MS_TRUE */
  for (i=0; i<MS_NUMTIMEFORMATS; i++) {
    if (strcasecmp(ms_timeFormats[i].userformat, timeformat) == 0)
      break;
  }

  if (i >= 0 && i < MS_NUMTIMEFORMATS) {
    int match = ms_regexec(ms_timeFormats[i].regex, timestring, 0, NULL, 0);
    if(match == 0)
      return MS_TRUE;
  }
  return MS_FALSE;
}
Ejemplo n.º 3
0
void msSetLimitedPatternsToUse(const char *patternstring)
{
  int *limitedpatternindice = NULL;
  int numpatterns=0, i=0, j=0, ntmp=0;
  char **patterns = NULL;
  msTimeSetup();

  limitedpatternindice = (int *)msSmallMalloc(sizeof(int)*MS_NUMTIMEFORMATS);

  /* free previous setting */
  msUnsetLimitedPatternToUse();

  if (patternstring) {
    patterns = msStringSplit(patternstring, ',', &ntmp);
    if (patterns && ntmp >= 1) {

      for (i=0; i<ntmp; i++) {
        for (j=0; j<MS_NUMTIMEFORMATS; j++) {
          if (strcasecmp( ms_timeFormats[j].userformat, patterns[i]) ==0) {
            limitedpatternindice[numpatterns] = j;
            numpatterns++;
            break;
          }
        }
      }
    }
    msFreeCharArray(patterns, ntmp);
  }

  if (numpatterns > 0) {
    for (i=0; i<numpatterns; i++)
      ms_limited_pattern[i] = limitedpatternindice[i];

    ms_num_limited_pattern = numpatterns;
  }
  free (limitedpatternindice);
}
Ejemplo n.º 4
0
void msUnsetLimitedPatternToUse()
{
  msTimeSetup();
  ms_num_limited_pattern = 0;
}