void parse_ref_response(Message message, double** data){ Element ReferenceDataResponse = message.asElement(); ReferenceDataResponse.print(std::cout); if (ReferenceDataResponse.hasElement("responseError")){ OutputDebugString(L"ERROR"); return; } Element securityDataArray = message.getElement("securityData"); int numItems = securityDataArray.numValues(); double array[11]; int sequenceNum; for (int i = 0; i < numItems; i++){ Element securityData = securityDataArray.getValueAsElement(i); sequenceNum = securityData.getElementAsInt32("sequenceNumber"); Element fieldData = securityData.getElement("fieldData"); Datetime maturity = fieldData.getElementAsDatetime("MATURITY"); array[0] = (maturity.year()); //0 array[1] = (maturity.month()); //1 array[2] = (maturity.day()); //2 Datetime issue_dt = fieldData.getElementAsDatetime("ISSUE_DT"); array[3] = (maturity.year() - issue_dt.year()); //3 //newRow.push_back(issue_dt.month()); //newRow.push_back(issue_dt.day()); array[4] = (fieldData.getElementAsFloat64("DUR_ADJ_MID")); //4 array[5] = (fieldData.getElementAsFloat64("LAST_PRICE")); //5 array[6] = (fieldData.getElementAsFloat64("PX_LAST_EOD")); //6 array[7] = (fieldData.getElementAsFloat64("YLD_YTM_MID")); //7 array[8] = (fieldData.getElementAsFloat64("ASSET_SWAP_SPD_MID")); //8 array[9] = (fieldData.getElementAsFloat64("BB_Z_SPREAD_TO_OIS_DISC_MID")); //9 array[10] = (fieldData.getElementAsFloat64("BB_Z_SPREAD_TO_OIS_DISC_MID")); //10 } for (int j = 0; j < 11; j++){ data[sequenceNum][j] = array[j]; } }
// CLASS METHODS DatetimeTz CurrentTime::asDatetimeTz() { Datetime now = utc(); bsls::TimeInterval offset = LocalTimeOffset::localTimeOffset(now); now.addSeconds(offset.totalSeconds()); BSLS_ASSERT((-1440 < offset.totalMinutes()) && (offset.totalMinutes() < 1440)); return DatetimeTz(now, static_cast<int>(offset.totalMinutes())); }
DatetimeList HKU_API getDateRange(const Datetime& start, const Datetime& end) { DatetimeList result; bd::date start_day = start.date(); bd::date end_day = end.date(); bd::date_period dp(start_day, end_day); bd::day_iterator iter = dp.begin(); for (; iter != dp.end(); ++iter) { result.push_back(*iter); } return result; }
vector<int> retrieve(string s, string e, string gra) { Datetime start = parse(s); Datetime end = parse(e); start.setdefault(gra, true); end.setdefault(gra, false); auto iter = m.lower_bound(start); auto jter = m.upper_bound(end); vector<int> res; for(auto i = iter; i != jter; ++i) res.push_back(i->second); return res; }
void CheckOuterInstance(const Outer_Class& x) { UT_ASSERT(x.booleanScalar_value()); // == true UT_ASSERT(x.uint8Scalar_value() == 8); UT_ASSERT(x.sint8Scalar_value() == -8); UT_ASSERT(x.uint16Scalar_value() == 16); UT_ASSERT(x.sint16Scalar_value() == -16); UT_ASSERT(x.uint32Scalar_value() == 32); UT_ASSERT(x.sint32Scalar_value() == -32); UT_ASSERT(x.uint64Scalar_value() == 64); UT_ASSERT(x.sint64Scalar_value() == -64); UT_ASSERT(Close(x.real32Scalar_value(), 32.32)); UT_ASSERT(Close(x.real64Scalar_value(), 64.64)); UT_ASSERT(x.char16Scalar_value() == 16); { Datetime datetimeScalar; datetimeScalar.Set(MI_T("20091231120030.123456+360")); UT_ASSERT(x.datetimeScalar_value() == datetimeScalar); } UT_ASSERT(x.stringScalar_value() == ZT("string")); CheckInnerInstance(x.instanceScalar_value()); UT_ASSERT(CheckArray<Boolean>::func(x.booleanArray_value(), true, false)); UT_ASSERT(CheckArray<Uint8>::func(x.uint8Array_value(), 8, 8)); UT_ASSERT(CheckArray<Sint8>::func(x.sint8Array_value(), -8, -8)); UT_ASSERT(CheckArray<Uint16>::func(x.uint16Array_value(), 16, 16)); UT_ASSERT(CheckArray<Sint16>::func(x.sint16Array_value(), -16, -16)); UT_ASSERT(CheckArray<Uint32>::func(x.uint32Array_value(), 32, 32)); UT_ASSERT(CheckArray<Sint32>::func(x.sint32Array_value(), -32, -32)); UT_ASSERT(CheckArray<Uint64>::func(x.uint64Array_value(), 64, 64)); UT_ASSERT(CheckArray<Sint64>::func(x.sint64Array_value(), -64, -64)); UT_ASSERT(CheckArray<Real32>::func(x.real32Array_value(), 32.32f, 32.32f)); UT_ASSERT(CheckArray<Real64>::func(x.real64Array_value(), 64.64, 64.64)); UT_ASSERT(CheckArray<Char16>::func(x.char16Array_value(), 16, 16)); UT_ASSERT(CheckArray<String>::func(x.stringArray_value(), String(ZT("string")), String(ZT("string")))); { Datetime dt; dt.Set(ZT("20091231120030.123456+360")); UT_ASSERT(CheckArray<Datetime>::func(x.datetimeArray_value(), dt, dt)); } { UT_ASSERT(x.instanceArray_value().GetSize() == 2); CheckInnerInstance(x.instanceArray_value()[0]); CheckInnerInstance(x.instanceArray_value()[1]); } }
// [[Rcpp::export]] List Datetime_get_functions(Datetime x) { Datetime dt = Datetime(x); return List::create(Named("year") = dt.getYear(), Named("month") = dt.getMonth(), Named("day") = dt.getDay(), Named("wday") = dt.getWeekday(), Named("hour") = dt.getHours(), Named("minute") = dt.getMinutes(), Named("second") = dt.getSeconds(), Named("microsec") = dt.getMicroSeconds()); }
void processMessage(Message &msg) { Element data = msg.getElement(BAR_DATA).getElement(BAR_TICK_DATA); int numBars = data.numValues(); std::cout <<"Response contains " << numBars << " bars" << std::endl; std::cout <<"Datetime\t\tOpen\t\tHigh\t\tLow\t\tClose" << "\t\tNumEvents\tVolume" << std::endl; for (int i = 0; i < numBars; ++i) { Element bar = data.getValueAsElement(i); Datetime time = bar.getElementAsDatetime(TIME); assert(time.hasParts(DatetimeParts::DATE | DatetimeParts::HOURS | DatetimeParts::MINUTES)); double open = bar.getElementAsFloat64(OPEN); double high = bar.getElementAsFloat64(HIGH); double low = bar.getElementAsFloat64(LOW); double close = bar.getElementAsFloat64(CLOSE); int numEvents = bar.getElementAsInt32(NUM_EVENTS); long long volume = bar.getElementAsInt64(VOLUME); std::cout.setf(std::ios::fixed, std::ios::floatfield); std::cout << time.month() << '/' << time.day() << '/' << time.year() << " " << time.hours() << ":" << time.minutes() << "\t\t" << std::showpoint << std::setprecision(3) << open << "\t\t" << high << "\t\t" << low << "\t\t" << close << "\t\t" << numEvents << "\t\t" << std::noshowpoint << volume << std::endl; } }
KRecord Stock:: getKRecordByDate(const Datetime& datetime, KQuery::KType ktype) const { size_t startix = 0, endix = 0; KQuery query = KQueryByDate(datetime, Datetime(datetime.number() + 1), ktype); if (getIndexRange(query, startix, endix)) { return getKRecord(startix, ktype); } return Null<KRecord>(); }
const double bbgDatetimeToPOSIX(const Datetime& dt) { boost::gregorian::date bbg_boost_date(dt.year(),dt.month(),dt.day()); boost::posix_time::time_duration td = boost::posix_time::hours(dt.hours()) + boost::posix_time::minutes(dt.minutes()) + boost::posix_time::seconds(dt.seconds()) + boost::posix_time::milliseconds(dt.milliseconds()); boost::posix_time::ptime bbg_ptime(bbg_boost_date,td); struct tm tm_time(to_tm(bbg_ptime)); return static_cast<double>(mktime(&tm_time)); }
void setDatetime(MYSQL_BIND& bind, const Datetime& data) { reserve(bind, sizeof(MYSQL_TIME)); memset(bind.buffer, 0, sizeof(MYSQL_TIME)); MYSQL_TIME* ts = static_cast<MYSQL_TIME*>(bind.buffer); ts->year = data.getYear(); ts->month = data.getMonth(); ts->day = data.getDay(); ts->hour = data.getHour(); ts->minute = data.getMinute(); ts->second = data.getSecond(); bind.buffer_type = MYSQL_TYPE_DATE; bind.is_null = 0; }
Datetime Datetime::today() { Datetime x = Datetime::now(); return Datetime(x.year(), x.month(), x.day()); }
PriceList HistoryFinanceReader ::getHistoryFinanceInfo(Datetime date, const string& market, const string& code) { string funcname(" [HistoryFinanceReader::getHistoryFinanceInfo]"); PriceList result; string filename(m_dir + "/gpcw" + boost::lexical_cast<string>(date.number() / 10000) + ".dat"); FILE *fp = fopen(filename.c_str(), "rb"); if (NULL == fp) { HKU_INFO("Can't found " << filename << funcname); return result; } unsigned int report_date = 0; unsigned short max_count = 0; unsigned long report_size = 0; char header_buf[20]; if (!fread(header_buf, 1, 20, fp)) { HKU_ERROR("read data failed! " << filename << funcname); fclose(fp); return result; } memcpy(&report_date, header_buf + 2, 4); memcpy(&max_count, header_buf + 6, 2); memcpy(&report_size, header_buf + 12, 4); char stock_code[7]; hku_uint32 address = 0; for (int i = 0; i < max_count; i++) { if (!fread(stock_code, 1, 7, fp)) { HKU_ERROR("read stock_code failed! " << filename << funcname); fclose(fp); return result; } if (!fread(&address, 4, 1, fp)) { HKU_ERROR("read stock_item address failed! " << filename << funcname); fclose(fp); return result; } stock_code[6] = '\0'; if (strcmp(stock_code, code.c_str()) == 0) { break; } } if (address != 0) { const int MAX_COL_NUM = 350; float result_buffer[MAX_COL_NUM]; int report_fields_count = int(report_size / 4); if (report_fields_count >= MAX_COL_NUM) { HKU_WARN("Over MAX_COL_NUM! " << filename << funcname); report_fields_count = MAX_COL_NUM; } fseek(fp, address, SEEK_SET); if (!fread(result_buffer, 4, report_fields_count, fp)) { HKU_ERROR("read col data failed! " << filename << funcname); fclose(fp); return result; } result.reserve(report_fields_count); price_t null_price = Null<price_t>(); for (int i = 0; i < report_fields_count; i++) { if (result_buffer[i] == 0xf8f8f8f8) { result.push_back(null_price); } else { result.push_back(result_buffer[i]); } } } else { HKU_ERROR("Invalid address(0)! " << filename << funcname); } fclose(fp); return result; }
//根据调度判断是否允许发送 bool CAlertMain::IsScheduleMatch(string strSchedule) { if(strSchedule == "") return true; bool bReturn = false; Datetime tm; int nDay; int nHour; int nMin; nDay = tm.getDayOfWeek(); nHour = tm.getHour(); nMin = tm.getMinute(); printf("%d:%d:%d ",nDay,nHour,nMin); //"Type" "绝对任务计划" "相对任务计划" 不存在"绝对任务计划"的情况, 应该在emailset.exe里屏蔽掉 OBJECT hTask = GetTask(strSchedule); //if(GetTaskValue("Type", hTask) == "相对任务计划") { //相对调度条件参数 char buf[256]; string temp1 = "Allow"; itoa(nDay, buf, 10); temp1 += buf; string temp = GetTaskValue(temp1, hTask); if(strcmp(temp.c_str(), "1") == 0) { //允许 int nTaskStartHour = 0, nTaskEndHour = 0, nTaskStartMin = 0, nTaskEndMin = 0; int nTaskStart = 0, nTaskEnd = 0, nInput = 0; //开始 temp1 = "start"; temp1 += buf; std::list<string> pTmpList; temp = GetTaskValue(temp1, hTask); CAlertMain::ParserToken(pTmpList, temp.c_str(), ":"); sscanf(pTmpList.front().c_str(), "%d", &nTaskStartHour); sscanf(pTmpList.back().c_str(), "%d", &nTaskStartMin); //结束 pTmpList.clear(); temp1 = "end"; temp1 += buf; temp = GetTaskValue(temp1, hTask); CAlertMain::ParserToken(pTmpList, temp.c_str(), ":"); sscanf(pTmpList.front().c_str(), "%d", &nTaskEndHour); sscanf(pTmpList.back().c_str(), "%d", &nTaskEndMin); //比较 nTaskStart = nTaskStartHour * 60 + nTaskStartMin; nTaskEnd = nTaskEndHour * 60 + nTaskEndMin; nInput = nHour * 60 + nMin; if(nInput >= nTaskStart && nInput <= nTaskEnd) bReturn = true; } else { //禁止返回 false; } } return bReturn; }
TEST(Datetime, defaultCtor) { Datetime time; ASSERT_EQ(time_t_to_str(std::time(0)), time.toString()); }
const double bbgDateToPOSIX(const Datetime& bbg_date) { boost::gregorian::date bbg_boost_date(bbg_date.year(),bbg_date.month(),bbg_date.day()); struct tm tm_time(to_tm(bbg_boost_date)); return static_cast<double>(mktime(&tm_time)); }
const int bbgDateToJulianDate(const Datetime& bbg_date) { const boost::gregorian::date r_epoch(1970,1,1); boost::gregorian::date bbg_boost_date(bbg_date.year(),bbg_date.month(),bbg_date.day()); boost::gregorian::date_period dp(r_epoch,bbg_boost_date); return static_cast<int>(dp.length().days()); }