EXPORT RM_ENTRY(rmc_encode_date) { struct tm *tim = (struct tm *)arg_vector[0].a_address; tim->tm_sec = CvtCobolToInt((ISC_UCHAR *)&tim->tm_sec, sizeof(tim->tm_sec), 11); tim->tm_min = CvtCobolToInt((ISC_UCHAR *)&tim->tm_min, sizeof(tim->tm_min), 11); tim->tm_hour = CvtCobolToInt((ISC_UCHAR *)&tim->tm_hour, sizeof(tim->tm_hour), 11); tim->tm_mday = CvtCobolToInt((ISC_UCHAR *)&tim->tm_mday, sizeof(tim->tm_mday), 11); tim->tm_mon = CvtCobolToInt((ISC_UCHAR *)&tim->tm_mon, sizeof(tim->tm_mon), 11); tim->tm_year = CvtCobolToInt((ISC_UCHAR *)&tim->tm_year, sizeof(tim->tm_year), 11); tim->tm_wday = CvtCobolToInt((ISC_UCHAR *)&tim->tm_wday, sizeof(tim->tm_wday), 11); tim->tm_yday = CvtCobolToInt((ISC_UCHAR *)&tim->tm_yday, sizeof(tim->tm_yday), 11); tim->tm_isdst = CvtCobolToInt((ISC_UCHAR *)&tim->tm_isdst, sizeof(tim->tm_isdst), 11); isc_encode_date(tim, (ISC_QUAD *)arg_vector[1].a_address); return (0); }
// Convert a Cobol date field to ISC_QUAD format. Used to convert date fields // before calling other isc_ routines. EXPORT RM_ENTRY(rmc_dtoc) { char stemp[10]; struct tm tim; date_fmt fmt; ClearParamPool(); const int dtlen = arg_vector[1].a_length; const ISC_UCHAR* dt = arg_vector[1].a_address; const ISC_UCHAR* fmtString = CobolToString(&arg_vector[2]); ParseDateFormat(fmtString, &fmt); memset(&tim, 0, sizeof(tim)); if ((fmt.yr_start != -1) && (fmt.yr_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.yr_start, fmt.yr_len); tim.tm_year = atoi(stemp); // If the year is supplied as 4 digits, no problem just decerement by 1900 // to keep isc_encode_date happy. If 2 digits, assume date > 2000 and // add 100 to keep isc_encode_date happy. if (fmt.yr_len > 2) tim.tm_year -= 1900; else tim.tm_year += 100; } if ((fmt.mon_start != -1) && (fmt.mon_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.mon_start, 2); tim.tm_mon = atoi(stemp) - 1; } if ((fmt.day_start != -1) && (fmt.day_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.day_start, 2); tim.tm_mday = atoi(stemp); } if ((fmt.hr_start != -1) && (fmt.hr_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.hr_start, 2); tim.tm_hour = atoi(stemp); } if ((fmt.min_start != -1) && (fmt.min_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.min_start, 2); tim.tm_min = atoi(stemp); } if ((fmt.sec_start != -1) && (fmt.sec_start < dtlen)) { memset(stemp, 0, sizeof(stemp)); memmove(stemp, dt + fmt.sec_start, 2); tim.tm_sec = atoi(stemp); } isc_encode_date(&tim, (ISC_QUAD *)arg_vector[0].a_address); return (0); }
void API_ROUTINE gds__encode_date(const void* time_structure, GDS_QUAD* date) { isc_encode_date(time_structure, date); }