// Convert an ISC_QUAD to Cobol date format. Used to convert date fields after // calling other isc _ routines EXPORT RM_ENTRY(rmc_ctod) { struct tm tim; date_fmt fmt; char stemp[10]; ClearParamPool(); const ISC_UCHAR* fmtString = CobolToString(&arg_vector[2]); ISC_UCHAR* dt = AllocStringPool((int)strlen((char *)fmtString) + 1); memset(dt, 0, strlen((char *)fmtString) + 1); isc_decode_date((ISC_QUAD *)arg_vector[1].a_address, &tim); ParseDateFormat(fmtString, &fmt); if (fmt.yr_start != -1) { sprintf(stemp, "%*.*d", fmt.yr_len, fmt.yr_len, tim.tm_year + 1900); memmove(dt + fmt.yr_start, stemp, fmt.yr_len); } if (fmt.mon_start != -1) { sprintf(stemp, "%2.2d", tim.tm_mon + 1); memmove(dt + fmt.mon_start, stemp, 2); } if (fmt.day_start != -1) { sprintf(stemp, "%2.2d", tim.tm_mday); memmove(dt + fmt.day_start, stemp, 2); } if (fmt.hr_start != -1) { sprintf(stemp, "%2.2d", tim.tm_hour); memmove(dt + fmt.hr_start, stemp, 2); } if (fmt.min_start != -1) { sprintf(stemp, "%2.2d", tim.tm_min); memmove(dt + fmt.min_start, stemp, 2); } if (fmt.sec_start != -1) { sprintf(stemp, "%2.2d", tim.tm_sec); memmove(dt + fmt.sec_start, stemp, 2); } StringToCobol(&arg_vector[0], dt); return (0); }
EXPORT RM_ENTRY(rmc_decode_date) { struct tm *tim = (struct tm *)arg_vector[1].a_address; isc_decode_date((ISC_QUAD *)arg_vector[0].a_address, tim); CvtIntToCobol((ISC_UCHAR *)&tim->tm_sec, tim->tm_sec, sizeof(tim->tm_sec)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_min, tim->tm_min, sizeof(tim->tm_min)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_hour, tim->tm_hour, sizeof(tim->tm_hour)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_mday, tim->tm_mday, sizeof(tim->tm_mday)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_mon, tim->tm_mon, sizeof(tim->tm_mon)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_year, tim->tm_year, sizeof(tim->tm_year)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_wday, tim->tm_wday, sizeof(tim->tm_wday)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_yday, tim->tm_yday, sizeof(tim->tm_yday)); CvtIntToCobol((ISC_UCHAR *)&tim->tm_isdst, tim->tm_isdst, sizeof(tim->tm_isdst)); return (0); }
static void edit_date( const dsc* desc, pics* picture, TEXT** output) { /************************************** * * e d i t _ d a t e * ************************************** * * Functional description * Edit data from a descriptor through an edit string to a running * output pointer. * **************************************/ SLONG date[2]; DSC temp_desc; TEXT d, temp[256]; temp_desc.dsc_dtype = dtype_timestamp; temp_desc.dsc_scale = 0; temp_desc.dsc_sub_type = 0; temp_desc.dsc_length = sizeof(date); temp_desc.dsc_address = (UCHAR*) date; QLI_validate_desc(temp_desc); MOVQ_move(desc, &temp_desc); tm times; isc_decode_date((ISC_QUAD*) date, ×); TEXT* p = temp; const TEXT* nmonth = p; p = cvt_to_ascii((SLONG) times.tm_mon + 1, p, picture->pic_nmonths); const TEXT* day = p; p = cvt_to_ascii((SLONG) times.tm_mday, p, picture->pic_days); const TEXT* year = p; p = cvt_to_ascii((SLONG) times.tm_year + 1900, p, picture->pic_years); const TEXT* julians = p; p = cvt_to_ascii((SLONG) times.tm_yday + 1, p, picture->pic_julians); const TEXT* meridian = ""; if (picture->pic_meridian) { if (times.tm_hour >= 12) { meridian = "PM"; if (times.tm_hour > 12) times.tm_hour -= 12; } else meridian = "AM"; } const SLONG seconds = date[1] % (60 * PRECISION); TEXT* hours = p; p = cvt_to_ascii((SLONG) times.tm_hour, p, picture->pic_hours); p = cvt_to_ascii((SLONG) times.tm_min, --p, picture->pic_minutes); p = cvt_to_ascii((SLONG) seconds, --p, 6); if (*hours == '0') *hours = ' '; SLONG rel_day = (date[0] + 3) % 7; if (rel_day < 0) rel_day += 7; const TEXT* weekday = alpha_weekdays[rel_day]; const TEXT* month = alpha_months[times.tm_mon]; picture->pic_pointer = picture->pic_string; picture->pic_count = 0; TEXT* out = *output; bool sig_day = false; bool blank = true; for (;;) { TEXT c = generate(picture); if (!c || c == '?') break; c = UPPER(c); switch (c) { case 'Y': *out++ = *year++; break; case 'M': if (*month) *out++ = *month++; break; case 'N': *out++ = *nmonth++; break; case 'D': d = *day++; if (!sig_day && d == '0' && blank) *out++ = ' '; else { sig_day = true; *out++ = d; } break; case 'J': if (*julians) *out++ = *julians++; break; case 'W': if (*weekday) *out++ = *weekday++; break; case 'B': *out++ = ' '; break; case 'P': if (*meridian) *out++ = *meridian++; break; case 'T': if (*hours) *out++ = *hours++; break; case '"': case '\'': case '\\': literal(picture, c, &out); break; default: *out++ = c; break; } if (c != 'B') blank = false; } *output = out; }
void API_ROUTINE gds__decode_date(const GDS_QUAD* date, void* time_structure) { isc_decode_date(date, time_structure); }