/* ----------------------------------------------------------------------- * 関数名 : CSystemFunction::GETTIME * 引数  : epochからの秒数,GMTかどうか(1でGMT) 省略可 * 返値  : year,month,day,week(0-6),hour,minute,secondの汎用配列 * ----------------------------------------------------------------------- */ CValue CSystemFunction::GETTIME(vector &arg, wstring &d, int &l) { time_t ltime; time(<ime); //とりあえず標準で設定しておく if (arg.size() >= 1) { //epochからの秒数 if (arg[0].GetType() == F_TAG_INT || arg[0].GetType() == F_TAG_DOUBLE) { ltime = arg[0].GetValueInt(); } else { logger.Error(E_W, 9, L"GETTIME", d, l); SetError(9); } } tm *today = localtime(<ime);; if (arg.size() >= 2) { //GMTかどうか if (arg[1].GetType() == F_TAG_INT || arg[1].GetType() == F_TAG_DOUBLE) { if (arg[1].GetValueInt() == 1) { today = gmtime(<ime); } } else { logger.Error(E_W, 9, L"GETTIME", d, l); SetError(9); } } CValue result(F_TAG_ARRAY, 0/*dmy*/); result.array.push_back(CValueSub(today->tm_year + 1900)); result.array.push_back(CValueSub(today->tm_mon + 1)); result.array.push_back(CValueSub(today->tm_mday)); result.array.push_back(CValueSub(today->tm_wday)); result.array.push_back(CValueSub(today->tm_hour)); result.array.push_back(CValueSub(today->tm_min)); result.array.push_back(CValueSub(today->tm_sec)); return result; } /* ----------------------------------------------------------------------- * 関数名 : CSystemFunction::TIME * * 返値  : epochからの経過時間 * ----------------------------------------------------------------------- */ CValue CSystemFunction::TIME(void) { time_t ltime; time(<ime); return CValue((int)ltime); } /* ----------------------------------------------------------------------- * 関数名 : CSystemFunction::MAKETIME * 引数  : year,month,day,hour,minute,second * 返値  : epochからの秒数 * ----------------------------------------------------------------------- */ CValue CSystemFunction::MAKETIME(vector &arg, wstring &d, int &l) { if (!arg.size()) { logger.Error(E_W, 8, L"MAKETIME", d, l); SetError(8); return CValue(F_TAG_NOP, 0/*dmy*/); } //あらかじめ初期化しておく tm stime; ::memset(&stime,0,sizeof(stime)); stime.tm_mday = 1; stime.tm_isdst = -1; //Cライブラリに夏時間判断をまかせる for (unsigned int i = 0 ; i < 6 ; ++i) { if (i >= arg.size()) { break; } if (arg[i].GetType() != F_TAG_INT && arg[i].GetType() != F_TAG_DOUBLE) { logger.Error(E_W, 9, L"MAKETIME", d, l); SetError(9); continue; //一応無視して次を見る } switch(i) { case 0: //年 stime.tm_year = arg[i].GetValueInt() - 1900; break; case 1: //月 stime.tm_mon = arg[i].GetValueInt() - 1; break; case 2: //日 stime.tm_mday = arg[i].GetValueInt(); break; case 3: //時 stime.tm_hour = arg[i].GetValueInt(); break; case 4: //分 stime.tm_min = arg[i].GetValueInt(); break; case 5: //秒 stime.tm_sec = arg[i].GetValueInt(); break; } } return CValue((int)mktime(&stime)); }