Logo Search packages:      
Sourcecode: dballe version File versions

dba_err dba_record_parse_date_extremes ( dba_record  rec,
int *  minvalues,
int *  maxvalues 
)

Parse the date extremes set in the dba_record.

This function will examine the values yearmin, monthmin, daymin, hourmin, minumin, secmin, yearmax, monthmax, daymax, hourmax, minumax, secmax, year, month, day, hour, min and sec, and will compute the two datetime extremes that bound the interval they represent.

Parameters:
rec The record that holds the datetime specifications
Return values:
minvalues An array of 6 integers that will be filled with the minimum year, month, day, hour, minute and seconds.
maxvalues An array of 6 integers that will be filled with the maximum year, month, day, hour, minute and seconds.
Returns:
The error indicator for the function.
See also:
dba_err

Definition at line 956 of file dba_record.c.

References dba_error_consistency, and _dba_varinfo::desc.

{
      dba_keyword names[] = { DBA_KEY_YEAR, DBA_KEY_MONTH, DBA_KEY_DAY, DBA_KEY_HOUR, DBA_KEY_MIN, DBA_KEY_SEC };
      dba_keyword min_names[] = { DBA_KEY_YEARMIN, DBA_KEY_MONTHMIN, DBA_KEY_DAYMIN, DBA_KEY_HOURMIN, DBA_KEY_MINUMIN, DBA_KEY_SECMIN };
      dba_keyword max_names[] = { DBA_KEY_YEARMAX, DBA_KEY_MONTHMAX, DBA_KEY_DAYMAX, DBA_KEY_HOURMAX, DBA_KEY_MINUMAX, DBA_KEY_SECMAX };
      int i;

      /* Get the year */

      for (i = 0; i < 6; i++)
      {
            int val = peek_int(rec, names[i]);
            int min = peek_int(rec, min_names[i]);
            int max = peek_int(rec, max_names[i]);

            minvalues[i] = max_with_undef(val, min);
            maxvalues[i] = min_with_undef(val, max);

            if (i > 0 &&
                        ((minvalues[i-1] == -1 && minvalues[i] != -1) ||
                         (maxvalues[i-1] == -1 && maxvalues[i] != -1)))
            {
                  dba_varinfo key1 = dba_record_keyword_byindex(names[i - 1]);
                  dba_varinfo key2 = dba_record_keyword_byindex(names[i]);

                  return dba_error_consistency("%s extremes are unset but %s extremes are set",
                              key1->desc, key2->desc);
            }
      }

      /* Now values is either 6 times -1, 6 values, or X values followed by 6-X times -1 */

      /* If one of the extremes has been selected, fill in the blanks */

      if (minvalues[0] != -1)
      {
            minvalues[1] = minvalues[1] != -1 ? minvalues[1] : 1;
            minvalues[2] = minvalues[2] != -1 ? minvalues[2] : 1;
            minvalues[3] = minvalues[3] != -1 ? minvalues[3] : 0;
            minvalues[4] = minvalues[4] != -1 ? minvalues[4] : 0;
            minvalues[5] = minvalues[5] != -1 ? minvalues[5] : 0;
      }

      if (maxvalues[0] != -1)
      {
            maxvalues[1] = maxvalues[1] != -1 ? maxvalues[1] : 12;
            maxvalues[2] = maxvalues[2] != -1 ? maxvalues[2] : max_days(maxvalues[0], maxvalues[1]);
            maxvalues[3] = maxvalues[3] != -1 ? maxvalues[3] : 23;
            maxvalues[4] = maxvalues[4] != -1 ? maxvalues[4] : 59;
            maxvalues[5] = maxvalues[5] != -1 ? maxvalues[5] : 59;
      }

      return dba_error_ok();
}


Generated by  Doxygen 1.6.0   Back to index