int clip_LASTDAYOM(ClipMachine * ClipMachineMemory) { int dd, mm, yy, ww, mm1; struct tm *sysTime; long d; int numpar = _clip_parinfo(ClipMachineMemory, 0); _clip_pardc(ClipMachineMemory, 1, &yy, &mm, &dd, &ww); mm1 = _clip_parni(ClipMachineMemory, 1); if (numpar == 0 || mm1 != 0) { sysTime = _clip_sysdate(); yy = sysTime->tm_year + 1900; mm = sysTime->tm_mon + 1; dd = sysTime->tm_mday; free(sysTime); } if (mm1 != 0) mm = mm1; d = _clip_jdate(1, mm + 1, yy); _clip_cdate(d, &dd, &mm1, &yy, &ww); while (mm != mm1) { d--; _clip_cdate(d, &dd, &mm1, &yy, &ww); } _clip_retndp(ClipMachineMemory, dd, 2, 0); return 0; }
CLIP_DLLEXPORT void _clip_datetostr(long date, char *buf) { int dd, mm, yy, ww; char *sss = "0123456789"; buf[8] = 0; if (date == 0) { memset(buf, ' ', 8); return; } _clip_cdate(date, &dd, &mm, &yy, &ww); buf[7] = sss[dd % 10]; buf[6] = sss[dd / 10]; buf[5] = sss[mm % 10]; buf[4] = sss[mm / 10]; buf[3] = sss[yy % 10]; yy /= 10; buf[2] = sss[yy % 10]; yy /= 10; buf[1] = sss[yy % 10]; yy /= 10; buf[0] = sss[yy]; }
int clip_PG_OUT_DATETIME(ClipMachine* mp){ PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item( mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL); long time; long date = _clip_pardtj(mp,2,&time); int totext = _clip_parl(mp,3); if(!rowset){ _clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset); return 1; } if((!totext)&&rowset->binary){ long l = date - _clip_jdate(1,1,2000); double d = l*(24*60*60) + time/1000; _clip_retcn(mp,(char*)&d,8); } else { char str[26]; int y,m,d,w,h,mm,s,t,q; _clip_cdate(date,&d,&m,&y,&w); h = time/(60*60*1000); q = time%(60*60*1000); mm = q/(60*1000); q %= 60*1000; s = q/(1000); t = q%1000; snprintf(str,sizeof(str),"%04d-%02d-%02d %02d:%02d:%02d.%02d+00",y,m,d,h,mm,s,t); _clip_retc(mp,str); } return 0; }
int clip_ODBC_OUT_DATE(ClipMachine* mp){ long julian = _clip_pardj(mp,1); short int s[3] = {0,0,0}; int yy,mm,dd,ww; if((_clip_parinfo(mp,1) == DATE_t) && julian){ _clip_cdate(julian,&dd,&mm,&yy,&ww); s[0] = yy; s[1] = mm; s[2] = dd; } _clip_retcn(mp,(char*)s,6); return 0; }
int _clip_dt_normalize(ClipDateTime * dt) { int ii, jj, ww; long d; ii = dt->msec % 1000; jj = dt->msec / 1000; if (ii < 0) { jj--; ii = 1000 + ii; } dt->msec = ii; dt->sec += jj; ii = dt->sec % 60; jj = dt->sec / 60; if (ii < 0) { jj--; ii = 60 + ii; } dt->sec = ii; dt->min += jj; ii = dt->min % 60; jj = dt->min / 60; if (ii < 0) { jj--; ii = 60 + ii; } dt->min = ii; dt->hour += jj; ii = dt->hour % 24; jj = dt->hour / 24; if (ii < 0) { jj--; ii = 24 + ii; } dt->hour = ii; dt->day += jj; d = _clip_jdate(dt->day, dt->month, dt->year); _clip_cdate(d, &(dt->day), &(dt->month), &(dt->year), &ww); return 0; }
int clip_ODBC_OUT_TIMESTAMP(ClipMachine* mp){ long time; long julian = _clip_pardtj(mp,1,&time); short int s[6] = {0,0,0,0,0,0}; int yy,mm,dd,ww; long t; if(_clip_parinfo(mp,1) == DATE_t){ if(julian){ _clip_cdate(julian,&dd,&mm,&yy,&ww); s[0] = yy; s[1] = mm; s[2] = dd; } s[3] = time / (60*60*1000); t = time % (60*60*1000); s[4] = t / (60*1000); s[5] = (t % (60*1000)) / 1000; } _clip_retcn(mp,(char*)s,12); return 0; }
int clip_PG_OUT_DATE(ClipMachine* mp){ PG_ROWSET* rowset = (PG_ROWSET*)_clip_fetch_c_item( mp,_clip_parni(mp,1),_C_ITEM_TYPE_SQL); long date = _clip_pardj(mp,2); int totext = _clip_parl(mp,3); if(!rowset){ _clip_trap_err(mp,0,0,0,subsys,ER_NOROWSET,er_norowset); return 1; } if((!totext)&&rowset->binary){ long d = date-2451545; _clip_retcn(mp,(char*)&d,4); } else { char str[11]; int y,m,d,w; _clip_cdate(date,&d,&m,&y,&w); snprintf(str,sizeof(str),"%04d-%02d-%02d",y,m,d); _clip_retc(mp,str); } return 0; }
CLIP_DLLEXPORT char * _clip_date_to_str(long date, char *format) { int i, fl; int dl = 1, ml = 1, yl = 1; int dd, mm, yy, ww; char ch, ch2; char ds[DD_BUF_LEN + 1], ms[DD_BUF_LEN + 1], ys[DD_BUF_LEN + 1]; char *ret; if (format == NULL) format = CLIP_DATEFORMAT_DEFAULT; fl = strlen(format); ret = malloc(fl + 1); memset(ret, 32, fl - 1); ret[fl] = 0; memset(ds, 32, DD_BUF_LEN); ds[DD_BUF_LEN] = 0; memset(ms, 32, DD_BUF_LEN); ms[DD_BUF_LEN] = 0; memset(ys, 32, DD_BUF_LEN); ys[DD_BUF_LEN] = 0; _clip_cdate(date, &dd, &mm, &yy, &ww); if (date != 0) { snprintf(ds, DD_BUF_LEN + 1, "%07d", dd); snprintf(ms, DD_BUF_LEN + 1, "%07d", mm); snprintf(ys, DD_BUF_LEN + 1, "%07d", yy); } for (i = fl; i >= 0; i--) { ch = format[i]; switch (ch) { case 'd': case 'D': ch2 = ds[DD_BUF_LEN - dl]; dl++; break; case 'm': case 'M': ch2 = ms[DD_BUF_LEN - ml]; ml++; break; case 'y': case 'Y': ch2 = ys[DD_BUF_LEN - yl]; yl++; break; default: ch2 = ch; break; } ret[i] = ch2; /*printf("%c%c%d%d%d.",ch,ch2,dl,ml,yl); */ } return ret; }