/*
 * CM_FMT_DATE.pgc - cm 모듈 서비스 CM_FMT_DATE (one service = one file).
 * Split out of the former inline cm_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by cm_svr at tpsvrinit.
 */
#include "CM_FMT_DATE.h"

/* 16. CM_FMT_DATE - 날짜 포맷 변환 (순수 계산): YYYYMMDD -> YYYY-MM-DD. */
void CM_FMT_DATE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char in[16], out[16];
    int y, m, d;
    gets_(b, T_STR1, in, sizeof(in));
    if (strlen(in) == 8 && sscanf(in, "%4d%2d%2d", &y, &m, &d) == 3)
        sprintf(out, "%04d-%02d-%02d", y, m, d);
    else if (sscanf(in, "%d-%d-%d", &y, &m, &d) == 3)
        sprintf(out, "%04d%02d%02d", y, m, d);       /* 역변환 */
    else FAIL(b);
    sets_(b, T_STR3, out);
    OK(b);
}
