The invextend() function

The invextend() function copies an interval value under a different qualifier.

Extending is the operation of adding or dropping fields of an INTERVAL value to make it match a given qualifier. For INTERVAL values, both qualifiers must belong to the same interval class: either the year to month class or the day to fraction(5) class.

Syntax

mint invextend(in_inv, out_inv)
   intrvl_t *in_inv, *out_inv;
in_inv
A pointer to the interval variable to extend.
out_inv
A pointer to the interval variable with a valid qualifier to use for the extension.

Usage

The invextend() function copies the qualifier-field digits of in_inv interval variable to the out_inv interval variable. The qualifier of the out_inv variable controls the copy.

The function discards any fields in in_inv that are to the right of the least-significant field in out_inv. The function completes any fields in out_inv that are not present in in_inv as follows:
  • It fills the fields to the right of the least-significant field in in_inv with zeros.
  • It sets the fields to the left of the most-significant field in in_inv to valid interval values.

Return codes

0
The conversion was successful.
<0
The conversion failed.
-1266
An interval value is incompatible with the operation.
-1268
A parameter contains an invalid interval qualifier.

Example

The demo directory contains this sample program in the file invextend.ec. The example illustrates interval extension. In the second result, the output contains zeros in the seconds field, and the days field has been set to 3.
/*
   * invextend.ec *

   The following program illustrates INTERVAL extension. It extends an INTERVAL 
   value to another INTERVAL value with a different qualifier. Note that in the
   second example, the output contains zeros in the seconds field and the 
   days field has been set to 3. 
*/

#include <stdio.h>
EXEC SQL include datetime;

main()
{
    mint x;
    char out_str[16];
;
    EXEC SQL BEGIN DECLARE SECTION;
      interval hour to minute hrtomin;
      interval hour to hour hrtohr;
      interval day to second daytosec;
    EXEC SQL END DECLARE SECTION;

    printf("INVEXTEND Sample ESQL Program running.\n\n");

    printf("Interval (hour to minute) value =      75.27\n");
    incvasc("75:27", &hrtomin);

    /* Extend to hour-to-hour and convert the internal format to
     * ascii for displaying 
     */
    invextend(&hrtomin, &hrtohr);
    intoasc(&hrtohr, out_str);
    printf("Extended (hour to hour) value =    %s\n", out_str);  

    /* Extend to day-to-second and convert the internal format to
     * ascii for displaying

     */
   invextend(&hrtomin, &daytosec);
   intoasc(&daytosec, out_str);
   printf("Extended (day to second) value =: %s\n", out_str); 

    printf("\nINVEXTEND Sample Program over.\n\n");
}

Output

INVEXTEND Sample ESQL Program running.

Interval (hour to minute) value =    75:27
Extended (hour to hour) value   =    75
Extended (day to second) value  =  3 03:27:00

INVEXTEND Sample Program over.