335
int _msValidateTime(char *timestring, const char *timeextent)
337
int numelements, numextents, i, numranges;
338
struct tm tmtimestart, tmtimeend, tmstart, tmend;
339
char **atimerange = NULL, **atimeelements= NULL, **atimeextents=NULL;
341
if (!timestring || !timeextent)
344
if (strlen(timestring) <= 0 ||
345
strlen(timeextent) <= 0)
349
/* we first need to parse the timesting that is passed
350
so that we can determine if it is a descrete time
354
atimeelements = split (timestring, '/', &numelements);
355
msTimeInit(&tmtimestart);
356
msTimeInit(&tmtimeend);
358
if (numelements == 1) /*descrete time*/
360
/*start end end times are the same*/
361
if (msParseTime(timestring, &tmtimestart) != MS_TRUE)
363
msFreeCharArray(atimeelements, numelements);
366
if (msParseTime(timestring, &tmtimeend) != MS_TRUE)
368
msFreeCharArray(atimeelements, numelements);
372
else if (numelements >=2)/*range */
374
if (msParseTime(atimeelements[0], &tmtimestart) != MS_TRUE)
376
msFreeCharArray(atimeelements, numelements);
379
if (msParseTime(atimeelements[1], &tmtimeend) != MS_TRUE)
381
msFreeCharArray(atimeelements, numelements);
386
msFreeCharArray(atimeelements, numelements);
389
/* Now parse the time extent. Extents can be
390
- one range (2004-09-21/2004-09-25/resolution)
391
- multiple rages 2004-09-21/2004-09-25/res1,2004-09-21/2004-09-25/res2
392
- one value 2004-09-21
393
- mutiple values 2004-09-21,2004-09-22,2004-09-23
397
atimeextents = split (timeextent, ',', &numextents);
398
if (atimeextents == NULL || numextents <= 0)
401
/*the time timestring should at be valid in one of the extents
404
for (i=0; i<numextents; i++)
406
/* build time structure for the extents */
407
msTimeInit(&tmstart);
411
atimerange = split (atimeextents[i], '/', &numranges);
412
/* - one value 2004-09-21 */
415
/*time tested can either be descrete or a range */
417
if (msParseTime(atimerange[0], &tmstart) == MS_TRUE &&
418
msParseTime(atimerange[0], &tmend) == MS_TRUE &&
419
msTimeCompare(&tmstart, &tmtimestart) <= 0 &&
420
msTimeCompare(&tmend, &tmtimeend) >= 0)
422
msFreeCharArray(atimerange, numranges);
426
/*2004-09-21/2004-09-25/res1*/
427
else if (numranges >= 2)
429
if (msParseTime(atimerange[0], &tmstart) == MS_TRUE &&
430
msParseTime(atimerange[1], &tmend) == MS_TRUE &&
431
msTimeCompare(&tmstart, &tmtimestart) <= 0 &&
432
msTimeCompare(&tmend, &tmtimeend) >= 0)
434
msFreeCharArray(atimerange, numranges);
438
msFreeCharArray(atimerange, numranges);
442
msFreeCharArray(atimeextents, numextents);
449
int msValidateTimeValue(char *timestring, const char *timeextent)
451
char **atimes, **tokens = NULL;
452
int i, numtimes, ntmp = 0;
454
/* we need to validate the time passsed in the request */
455
/* against the time extent defined */
457
if (!timestring || !timeextent)
461
/* parse the time string. We support descrete times (eg 2004-09-21), */
462
/* multiple times (2004-09-21, 2004-09-22, ...) */
463
/* and range(s) (2004-09-21/2004-09-25, 2004-09-27/2004-09-29) */
464
if (strstr(timestring, ",") == NULL &&
465
strstr(timestring, "/") == NULL) /* discrete time */
467
return _msValidateTime(timestring, timeextent);
472
atimes = split (timestring, ',', &numtimes);
473
if (numtimes >=1) /* multiple times */
475
tokens = split(atimes[0], '/', &ntmp);
476
if (ntmp == 1) /* multiple descrete times */
478
/*msFreeCharArray(tokens, ntmp);*/
479
for (i=0; i<numtimes; i++)
481
if (_msValidateTime(atimes[i], timeextent) == MS_FALSE)
483
msFreeCharArray(atimes, numtimes);
487
msFreeCharArray(atimes, numtimes);
490
else if (ntmp >= 2)/* multiple ranges */
492
for (i=0; i<numtimes; i++)
494
/*msFreeCharArray(tokens, ntmp);*/
495
if (_msValidateTime(atimes[i], timeextent) == MS_FALSE)
497
msFreeCharArray(atimes, numtimes);
502
msFreeCharArray(atimes, numtimes);