Determine if the supplied chain iterator is at the begining of a legal date and/or time. If it is then the supplied hzXDate reference is populated. The lenth of the date/time sequence is returned so that the calling process can choose to advance the iterator by this length. The iterator is not advanced by this function Expects dates of the form "day_name, dd month_name yyyy hh:mm:ss Time-Zone"
| Return Type | Function name | Arguments |
|---|---|---|
| uint32_t | IsFormalDate | (hzXDate&,hzChain::Iter&,) |
Declared in file: hzTextproc.h
Defined in file : hzDate.cpp
Function Logic:
Function body:
uint32_t IsFormalDate (hzXDate& date)hzChain::Iter& ci,
{
// Category: Text Processing
//
// Determine if the supplied chain iterator is at the begining of a legal date and/or time. If it is then the supplied hzXDate reference is populated. The
// lenth of the date/time sequence is returned so that the calling process can choose to advance the iterator by this length. The iterator is not advanced
// by this function
//
// Expects dates of the form "day_name, dd month_name yyyy hh:mm:ss Time-Zone"
//
// Arguments: 1) date The full date
// 2) ci Chain iterator to be tested
//
// Returns: Number being length of the date string if found
chIter zi ; // Internal chain iterator
hzTimezone tz ; // Timezone
uint32_t n ; // Counter
uint32_t dow = NULL_DOW ; // Day of week
uint32_t len = 0; // Length of examined text
uint32_t Y = 0; // Year
uint32_t M = 0; // Month
uint32_t D = 0; // Day
uint32_t h = 0; // Hour
uint32_t m = 0; // Minute
uint32_t s = 0; // Second
uint32_t hOset = 0; // Hours in timezone offset to GMT
uint32_t mOset = 0; // Minutes in timezone offset to GMT
char numBuf[4]; // For reading numbers
zi = ci ;
tz.clear() ;
for (; !zi.eof() ;)
{
if (*zi < CHAR_SPACE)
break ;
if (*zi == CHAR_SPACE || *zi == CHAR_COMMA || *zi == CHAR_PAROPEN || *zi == CHAR_PARCLOSE)
{ len++ ; zi++ ; continue ; }
if (IsDigit(*zi))
{
// We are looking for a day of the month, a year or the start of a time sequence
n = IsTime(h, m, s, zi) ;
if (n)
zi += n ;
else
{
for (n = 0; IsDigit(*zi) ; zi++)
{ n *= 10;n += (*zi - ''0'');}
if (n < 32&&D == 0) D = n ;
else if (n < 10000&&Y==0)Y= n ;
else
return 0;
}
}
if (IsAlpha(*zi))
{
// We are looking for a day name, a month name or a timezone code
if (dow == NULL_DOW)
{
for (n = 0; n < 7; n++)
if (zi == hz_daynames_full[n])
{ dow = n ; break ; }
if (dow == NULL_DOW)
{
for (n = 0; n < 7; n++)
if (zi == hz_daynames_abrv[n])
{ dow = n ; break ; }
}
if (dow != 8)
{ for (; IsAlpha(*zi) ; zi++) ; continue ; }
}
if (M == 0)
{
for (n = 0; n < 12;n++)
if (zi == hz_monthnames_full[n])
{ M = n + 1; break ; }
if (M == 0)
{
for (n = 0; n < 12;n++)
if (zi == hz_monthnames_abrv[n])
{ M = n + 1; break ; }
}
if (M >&eq; 0)
{ for (; IsAlpha(*zi) ; zi++) ; continue ; }
}
if (!tz.code)
{
for (n = 0;; n++)
{
if (zi == _hzGlobal_Timezones[n].code)
{ tz = _hzGlobal_Timezones[n] ; break ; }
}
if (tz.code)
{ for (; IsAlpha(*zi) ; zi++) ; continue ; }
}
return 0;
}
if (*zi == CHAR_PLUS || *zi == CHAR_MINUS)
{
// We are looking for a timezone offset to GMT (of the form +/-dddd)
zi++ ; numBuf[0]= *zi ;
zi++ ; numBuf[1]= *zi ;
zi++ ; numBuf[2]= *zi ;
zi++ ; numBuf[3]= *zi ;
if (IsDigit(numBuf[0])&& IsDigit(numBuf[1])&& IsDigit(numBuf[2])&& IsDigit(numBuf[3]))
{
hOset = ((numBuf[0]- ''0'')*10)+(numBuf[1]- ''0'');
mOset = ((numBuf[2]- ''0'')*10)+(numBuf[3]- ''0'');
if (hOset > 23||mOset > 59)
return 0;
zi++ ;
continue ;
}
return 0;
}
}
if (date.SetDate(Y, M, D) != E_OK) return 0;
if (date.SetTime(h, m, s) != E_OK) return 0;
ci = zi ;
return len ;
}