QString QListViewItemExt::key(int column,bool ascending) const { ascending = ascending; //s QDateTime epoch(QDate(1900,1,1)); QString qs; int i; bool ok; qs = mParent->item(mRow, column)->text(); switch(column) { //sort by name case 0: case 1: qs = mParent->item(mRow, 2)->text(); break; //sort by byte size case 2: i = mParent->item(mRow, 2)->text().toInt(&ok); if(!ok) i = 0; qs.sprintf("%010i",i); break; case 3: i = epoch.secsTo(mDateTime); qs.sprintf("%010i",i); break; default:; } return qs; }
time_t RegestryHistory::to_time_t(boost::posix_time::ptime t) { boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); boost::posix_time::time_duration::sec_type x = (t - epoch).total_seconds(); return time_t(x); }
int main(int argc, char* argv[]) { if (argc < 4) { std::cout << "please provide run, epoch and iterations" << std::endl; return EXIT_FAILURE; } std::string run(argv[1]); std::string epoch(argv[2]); std::string root(ROOT); long ITERATIONS = std::atol(argv[3]); double* weights = new double[GENOME_SIZE]; if (system(("mkdir " + root + "\\www\\darwin\\data\\behaviours\\" + run).c_str())) { // prevent compiler warning, ah-ah! } std::ifstream weights_file(root + "/www/darwin/data/weights/" + run + "/" + epoch + ".dat"); std::ofstream log_file(root + "/www/darwin/data/behaviours/" + run + "/" + epoch + ".dat"); for (int i = 0; i < GENOME_SIZE; ++i) { weights_file >> weights[i]; } double food[] = {24 / sqrt(2), 24 / sqrt(2)}; Individual subject(weights); for (int i = 0; i < ITERATIONS; ++i) { log_file << i << " " << subject.position[0] << " " << subject.position[1] << " " << subject.rotation << std::endl; subject.tick(food); } return EXIT_SUCCESS; }
void CheckSystem::check_uptime(const Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response) { typedef check_uptime_filter::filter filter_type; modern_filter::data_container data; modern_filter::cli_helper<filter_type> filter_helper(request, response, data); std::vector<std::string> times; filter_type filter; filter_helper.add_options("uptime < 2d", "uptime < 1d", "", filter.get_filter_syntax(), "ignored"); filter_helper.add_syntax("${status}: ${list}", filter.get_format_syntax(), "uptime: ${uptime}h, boot: ${boot} (UTC)", "uptime", "", ""); if (!filter_helper.parse_options()) return; if (!filter_helper.build_filter(filter)) return; double uptime_secs = 0, idle_secs = 0; get_uptime(uptime_secs, idle_secs); unsigned long long value = uptime_secs; boost::posix_time::ptime now = boost::posix_time::second_clock::universal_time(); boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); boost::posix_time::ptime boot = now - boost::posix_time::time_duration(0, 0, value); long long now_delta = (now-epoch).total_seconds(); long long uptime = static_cast<long long>(value); boost::shared_ptr<check_uptime_filter::filter_obj> record(new check_uptime_filter::filter_obj(uptime, now_delta, boot)); filter.match(record); filter_helper.post_process(filter); }
std::time_t vishnu::string_lc_to_utc_time_t(const std::string& ts,const std::string& utcOffset) { // two aliases for convenience namespace bps= boost::posix_time; namespace bg=boost::gregorian; namespace blt=boost::local_time; std::cout << " convert " << ts << " " << utcOffset << " in utc time\n"; boost::local_time::time_zone_ptr tz(new boost::local_time::posix_time_zone(utcOffset)); bps::ptime t; if (std::string::npos==ts.find(":")){ t=bps::ptime(bg::from_string(ts)); } else{ t= bps::ptime (bps::time_from_string(ts)); } bps::ptime epoch(bg::date(1970,1,1)); blt::local_date_time ldt(t.date(), t.time_of_day(),tz,blt::local_date_time::NOT_DATE_TIME_ON_ERROR); bps::time_duration::sec_type x = (ldt.utc_time() - epoch).total_seconds(); return std::time_t(x); }
/** * Get Current time stamp * @return current time stamp * nabto_stamp_t nabtoGetStamp(); */ nabto_stamp_t nabtoGetStamp() { boost::posix_time::ptime epoch(boost::gregorian::date(1970,boost::gregorian::Jan,1)); boost::posix_time::ptime now = boost::get_system_time(); return (now-epoch).total_microseconds(); }
int parse_anza_SP ( uchar_t *packet, ushort_t pkttype ) { double ptime, ytime, sec; ulong ysec; int year, day, hour, min; PktPar pack; /* Get parameters for current datatype */ if( !get_packet( pkttype, &pack) ) return -1; Par.staid = packet[6]*256 + packet[7]; Par.packet = pack; Par.chan = -1; Par.hdrtype = ( int )decode( pack.hdrtype ); ytime = now(); e2h( ytime, &year, &day, &hour, &min, &sec); ptime = epoch( year * 1000 ); memcpy( (char *) &ysec, (char *) &packet[10], 4); Par.time = ptime + ysec; return (int) pkttype; }
// Step a GRect animation static void prv_animation_step_grect(AnimationNode *node) { // set from grect on first call, allowing another animation to change the target value // while this animation is delayed if (!node->from) { node->from = MALLOC(sizeof(GRect)); (*(GRect*)node->from) = (*(GRect*)node->target); } // step value GRect from = (*(GRect*)node->from); GRect to = (*(GRect*)node->to); uint32_t percent_max = node->duration; uint32_t percent = epoch() - (node->start_time + node->delay); (*(GRect*)node->target).origin.x = interpolation_integer(from.origin.x, to.origin.x, percent, percent_max, node->interpolation); (*(GRect*)node->target).origin.y = interpolation_integer(from.origin.y, to.origin.y, percent, percent_max, node->interpolation); (*(GRect*)node->target).size.w = interpolation_integer(from.size.w, to.size.w, percent, percent_max, node->interpolation); (*(GRect*)node->target).size.h = interpolation_integer(from.size.h, to.size.h, percent, percent_max, node->interpolation); // continue animation if (percent >= percent_max) { animation_stop(node->target); } }
/** * Construct a planet_tle from two strings containing the two line elements * \param[in] line1 first line * \param[in] line2 second line */ tle::tle(const std::string& line1, const std::string& line2) try : base(), m_line1(line1), m_line2(line2), m_tle(Tle("TLE satellite", line1, line2)), m_sgp4_propagator(SGP4(m_tle)) { // We read the osculating elements of the satellite array6D keplerian_elements; double mu_central_body = kMU*1E09; // (m^3/s^2) double mean_motion = m_tle.MeanMotion() * 2 * kPI / kSECONDS_PER_DAY; // [rad/s] keplerian_elements[0] = std::pow(mu_central_body / (mean_motion*mean_motion),1./3); // a [m] keplerian_elements[1] = m_tle.Eccentricity(); // e keplerian_elements[2] = m_tle.Inclination(false); // i [rad] keplerian_elements[3] = m_tle.RightAscendingNode(false); // Om [rad] keplerian_elements[4] = m_tle.ArgumentPerigee(false); // om [rad] keplerian_elements[5] = m_tle.MeanAnomaly(false); // M [rad] std::string year_str = m_tle.IntDesignator().substr(0,2); int year_int = std::stoi(year_str); std::string rest = m_tle.IntDesignator().substr(2); int prefix = (year_int > 50)?(19):(20); std::string object_name(std::to_string(prefix)+year_str+std::string("-")+rest); set_mu_central_body(mu_central_body); set_name(object_name); m_ref_mjd2000 = epoch(m_tle.Epoch().ToJulian(),epoch::JD).mjd2000(); } catch (TleException& e) { std::cout << "TleException cought in planet_tle constructor" << std::endl; throw_value_error(e.what()); } catch (SatelliteException& e) { std::cout << "SatelliteException cought in planet_tle constructor" << std::endl; throw_value_error(e.what()); }
/** * \brief Simple function to convert time * from string format (YYYY-MM-DD H:M:S) to * long integer format in seconds * \param ts: the time in string format * \return the time in long integer format in seconds */ std::time_t vishnu::string_to_time_t(const std::string& ts){ // two aliases for convenience namespace bps= boost::posix_time; namespace bg=boost::gregorian; bps::ptime t; if (std::string::npos==ts.find(":")){ t=bps::ptime(bg::from_string(ts)); } else{ t= bps::ptime (bps::time_from_string(ts)); } bps::ptime epoch(bg::date(1970,1,1)); bps::time_duration::sec_type x = (t - epoch).total_seconds(); return std::time_t(x); }
std::time_t DateTime::toEpoch() const { // credit: http://stackoverflow.com/questions/4461586/how-do-i-convert-boostposix-timeptime-to-time-t boost::posix_time::ptime pt(m_date.impl(), m_time.impl()); boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); boost::posix_time::time_duration::sec_type x = (pt - epoch).total_seconds(); return std::time_t(x); }
ull64 Time::getCurrentTime() { boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration diff = now - epoch; return diff.total_milliseconds(); }
void Notifier::onCopyTimestamp() { QModelIndex selectedInd = _observer->selectedIndex(); if (!selectedInd.isValid()) return; BsonTreeItem *documentItem = QtUtils::item<BsonTreeItem*>(selectedInd); if (!documentItem) return; if (!detail::isObjectIdType(documentItem)) return; QClipboard *clipboard = QApplication::clipboard(); // new Date(parseInt(this.valueOf().slice(0,8), 16)*1000); QString hexTimestamp = documentItem->value().mid(10, 8); bool ok; long long milliTimestamp = (long long)hexTimestamp.toLongLong(&ok, 16)*1000; bool isSupportedDate = (miutil::minDate < milliTimestamp) && (milliTimestamp < miutil::maxDate); boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); boost::posix_time::time_duration diff = boost::posix_time::millisec(milliTimestamp); boost::posix_time::ptime time = epoch + diff; if (isSupportedDate) { std::string date = miutil::isotimeString(time, false, false); clipboard->setText("ISODate(\""+QString::fromStdString(date)+"\")"); } else { clipboard->setText("Error extracting ISODate()"); } }
/** * Streams out the planet object in a human readable format * * \param[in] s stream to which the planet will be sent * \param[in] body planet to be sent to stream * * \return reference to s * */ std::ostream &kep_toolbox::operator<<(std::ostream &s, const kep_toolbox::planet &body) { s << "Planet Name: " << body.m_name << std::endl; s << "Own gravity parameter: " << boost::lexical_cast<std::string>(body.mu_self) << std::endl; s << "Central body gravity parameter: " << boost::lexical_cast<std::string>(body.mu_central_body) << std::endl; s << "Planet radius: " << boost::lexical_cast<std::string>(body.radius) << std::endl; s << "Planet safe radius: " << boost::lexical_cast<std::string>(body.safe_radius) << std::endl; s << "Planet keplerian elements: "<<std::endl; array6D elem = body.get_elements(epoch(body.ref_mjd2000)); s << "Semi major axis (AU): " << boost::lexical_cast<std::string>(elem[0] / ASTRO_AU) << std::endl; s << "Eccentricity: " << boost::lexical_cast<std::string>(elem[1]) << std::endl; s << "Inclination (deg.): " << boost::lexical_cast<std::string>(elem[2] * ASTRO_RAD2DEG) << std::endl; s << "Big Omega (deg.): " << boost::lexical_cast<std::string>(elem[3] * ASTRO_RAD2DEG) << std::endl; s << "Small omega (deg.): " << boost::lexical_cast<std::string>(elem[4] * ASTRO_RAD2DEG) << std::endl; s << "Mean anomaly (deg.): " << boost::lexical_cast<std::string>(elem[5] * ASTRO_RAD2DEG) << std::endl; s << "Elements reference epoch: " << epoch(body.ref_mjd2000) << std::endl; return s; }
int setFdUsed(SOCKET fd, StreamType ct) { int i; /* Find a free entry in socketFd(i) */ for (i = 0; i <= socketIdxMax; i++) { if (stream[i].fd == -1 || stream[i].fd == fd) { break; } } if (i == FD_SETSIZE) { logError("Already %d active streams, ignoring new one\n", FD_SETSIZE); close(fd); return -1; } stream[i].fd = fd; stream[i].timeout = epoch() + UPDATE_INTERVAL; stream[i].type = ct; stream[i].readHandler = readHandlers[ct]; FD_SET(fd, &activeSet); if (stream[i].readHandler) { logDebug("Enabling fd=%d in the readSet\n", fd); FD_SET(fd, &readSet); } else { logDebug("Disabling fd=%d in the readSet\n", fd); FD_CLR(fd, &readSet); } switch (stream[i].type) { case CLIENT_JSON: case CLIENT_JSON_STREAM: case CLIENT_NMEA0183_STREAM: case DATA_OUTPUT_STREAM: case DATA_OUTPUT_COPY: logDebug("Enabling fd=%d in the writeSet\n", fd); FD_SET(fd, &writeSet); break; default: logDebug("Clear fd=%d in the writeSet\n", fd); FD_CLR(fd, &writeSet); } socketIdxMax = CB_MAX(socketIdxMax, i); socketFdMax = CB_MAX(socketFdMax, fd); logDebug("New client %u type %d %u..%u fd=%d fdMax=%d\n", i, stream[i].type, socketIdxMin, socketIdxMax, fd, socketFdMax); return i; }
double FitsReader::ParseFitsDateToMJD(const char* valueStr) { casacore::MVTime time; casacore::MEpoch::Types systypes; bool parseSuccess = casacore::FITSDateUtil::fromFITS(time, systypes, valueStr, "UTC"); if(!parseSuccess) throw std::runtime_error(std::string("Could not parse FITS date: ") + valueStr); casacore::MEpoch epoch(time.get(), systypes); return epoch.getValue().get(); }
epoch planet_mpcorb::packed_date2epoch(std::string in) { if (in.size()!=5) { throw_value_error("mpcorb data format requires 5 characters."); } boost::algorithm::to_lower(in); boost::gregorian::greg_year anno = packed_date2number(in[0]) * 100 + boost::lexical_cast<int>(std::string(&in[1],&in[3])); boost::gregorian::greg_month mese = packed_date2number(in[3]); boost::gregorian::greg_day giorno = packed_date2number(in[4]); return epoch(anno,mese,giorno); }
int64_t milliNow() { boost::posix_time::ptime time_now; time_now = boost::posix_time::microsec_clock::universal_time(); boost::posix_time::ptime epoch(boost::gregorian::date(1970, boost::gregorian::Jan, 1)); boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse; time_elapse = time_now - epoch; return time_elapse.total_milliseconds(); }
QDateTime datetimeFromNumber(double num, bool is1904) { if (!is1904 && num > 60) num = num - 1; qint64 msecs = static_cast<qint64>(num * 1000*60*60*24.0 + 0.5); QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0)); return epoch.addMSecs(msecs); }
void RecordingRule::AssignProgramInfo() { if (!m_progInfo) return; m_title = m_progInfo->GetTitle(); m_subtitle = m_progInfo->GetSubtitle(); m_description = m_progInfo->GetDescription(); m_season = m_progInfo->GetSeason(); m_episode = m_progInfo->GetEpisode(); m_channelid = m_progInfo->GetChanID(); m_station = m_progInfo->GetChannelSchedulingID(); m_startdate = m_progInfo->GetScheduledStartTime().date(); m_starttime = m_progInfo->GetScheduledStartTime().time(); m_enddate = m_progInfo->GetScheduledEndTime().date(); m_endtime = m_progInfo->GetScheduledEndTime().time(); m_seriesid = m_progInfo->GetSeriesID(); m_programid = m_progInfo->GetProgramID(); if (m_findday < 0) { m_findday = (m_progInfo->GetScheduledStartTime().date().dayOfWeek() + 1) % 7; m_findtime = m_progInfo->GetScheduledStartTime().time(); QDate epoch(1970, 1, 1); m_findid = epoch.daysTo( m_progInfo->GetScheduledStartTime().date()) + 719528; } else { if (m_findid > 0) m_findid = m_progInfo->GetFindID(); else { QDate epoch(1970, 1, 1); m_findid = epoch.daysTo( m_progInfo->GetScheduledStartTime().date()) + 719528; } } m_category = m_progInfo->GetCategory(); m_inetref = m_progInfo->GetInetRef(); }
inline boost::uint64_t high_res_clock() { boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); boost::posix_time::ptime epoch( boost::gregorian::date(1970, 1, 1), boost::posix_time::seconds(0)); return (now - epoch).total_microseconds(); }
double datetimeToNumber(const QDateTime &dt, bool is1904) { //Note, for number 0, Excel2007 shown as 1900-1-0, which should be 1899-12-31 QDateTime epoch(is1904 ? QDate(1904, 1, 1): QDate(1899, 12, 31), QTime(0,0)); double excel_time = epoch.msecsTo(dt) / (1000*60*60*24.0); if (!is1904 && excel_time > 59) {//31+28 //Account for Excel erroneously treating 1900 as a leap year. excel_time += 1; } return excel_time; }
/** @return time passed in milliseconds since epoch */ inline util::int64 getCurrentTime() { // epoch boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); // get the time now boost::posix_time::ptime now = boost::posix_time::microsec_clock::local_time(); // get the difference in time since epoch boost::posix_time::time_duration diff = now - epoch; // return the time in milliseconds return diff.total_milliseconds(); }
/** * \brief Function to convert a given date into correspondant long value * \fn long long convertToTimeType(std::string date) * \param date The date to convert * \return The converted value */ long long vishnu::convertToTimeType(std::string date) { if(date.size()==0 || // For mysql, the empty date is 0000-00-00, not empty, need this test to avoid problem in ptime date.find("0000-00-00")!=std::string::npos) { return 0; } boost::posix_time::ptime pt(time_from_string(date)); boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); time_duration::sec_type time = (pt - epoch).total_seconds(); return (long long) time_t(time); }
// Terminate the program static void prv_terminate(void) { // unsubscribe from timer service tick_timer_service_unsubscribe(); // schedule wakeup if (!timer_is_chrono() && !timer_is_paused()) { time_t wakeup_time = (epoch() + timer_get_value_ms()) / MSEC_IN_SEC; wakeup_schedule(wakeup_time, 0, true); } // destroy timer_persist_store(); drawing_terminate(); layer_destroy(main_data.layer); window_destroy(main_data.window); }
int main(int argc, char* argv[]) { double t1 = epoch(); if (argc == 1) { printf("%.4f\n", t1); return 0; } double t0 = strtod(argv[1],(char **) NULL); printf("%.4f\n", t1 - t0); return 0; }
Status onShardVersionMismatch(OperationContext* opCtx, const NamespaceString& nss, ChunkVersion shardVersionReceived, bool forceRefreshFromThisThread) noexcept { invariant(!opCtx->lockState()->isLocked()); invariant(!opCtx->getClient()->isInDirectClient()); auto const shardingState = ShardingState::get(opCtx); invariant(shardingState->canAcceptShardedCommands()); LOG(2) << "Metadata refresh requested for " << nss.ns() << " at shard version " << shardVersionReceived; ShardingStatistics::get(opCtx).countStaleConfigErrors.addAndFetch(1); // Ensure any ongoing migrations have completed before trying to do the refresh. This wait is // just an optimization so that MongoS does not exhaust its maximum number of StaleConfig retry // attempts while the migration is being committed. try { auto& oss = OperationShardingState::get(opCtx); oss.waitForMigrationCriticalSectionSignal(opCtx); } catch (const DBException& ex) { return ex.toStatus(); } const auto currentShardVersion = [&] { AutoGetCollection autoColl(opCtx, nss, MODE_IS); const auto currentMetadata = CollectionShardingState::get(opCtx, nss)->getMetadata(opCtx); if (currentMetadata) { return currentMetadata->getShardVersion(); } return ChunkVersion::UNSHARDED(); }(); if (currentShardVersion.epoch() == shardVersionReceived.epoch() && currentShardVersion.majorVersion() >= shardVersionReceived.majorVersion()) { // Don't need to remotely reload if we're in the same epoch and the requested version is // smaller than the one we know about. This means that the remote side is behind. return Status::OK(); } try { forceShardFilteringMetadataRefresh(opCtx, nss, forceRefreshFromThisThread); return Status::OK(); } catch (const DBException& ex) { log() << "Failed to refresh metadata for collection" << nss << causedBy(redact(ex)); return ex.toStatus(); } }
uint32 SymbianFileHandler::getModificationDate() const { // The day the unix time starts. Used to get the time down // to a reasonable value. TDateTime epoch( 1970, EJanuary, 01, 0 , 0 , 0 , 0); TTime aTime( epoch ); TInt res = m_fileServer.Modified( *m_fileName16, aTime ); if ( res != KErrNone ) { return MAX_UINT32; } TTimeIntervalMicroSeconds interval = aTime.MicroSecondsFrom( epoch ); return LOW( interval.Int64() / 1000000 ); }
/// Extra informations streamed in humar readable format std::string keplerian::human_readable_extra() const { std::ostringstream s; s << "Keplerian planet elements: "<<std::endl; s << "Semi major axis (AU): " << boost::lexical_cast<std::string>(m_keplerian_elements[0] / ASTRO_AU) << std::endl; s << "Eccentricity: " << boost::lexical_cast<std::string>(m_keplerian_elements[1]) << std::endl; s << "Inclination (deg.): " << boost::lexical_cast<std::string>(m_keplerian_elements[2] * ASTRO_RAD2DEG) << std::endl; s << "Big Omega (deg.): " << boost::lexical_cast<std::string>(m_keplerian_elements[3] * ASTRO_RAD2DEG) << std::endl; s << "Small omega (deg.): " << boost::lexical_cast<std::string>(m_keplerian_elements[4] * ASTRO_RAD2DEG) << std::endl; s << "Mean anomaly (deg.): " << boost::lexical_cast<std::string>(m_keplerian_elements[5] * ASTRO_RAD2DEG) << std::endl; s << "Elements reference epoch: " << epoch(m_ref_mjd2000) << std::endl; s << "Ephemerides type: Keplerian" << std::endl; s << "m_r" << m_r << std::endl; s << "m_v" << m_v << std::endl; return s.str(); }
void FlagComponent::saveToFile() { /* TODO: This is a really bad way of storing things. Adding one flag shouldn't involve writing a new file/table every time. Needs fixing. */ KStarsData::Instance()->userdb()->EraseAllFlags(); for ( int i=0; i < size(); ++i ) { KStarsData::Instance()->userdb()->AddFlag(QString::number( pointList().at( i )->ra0().Degrees() ), QString::number( pointList().at( i )->dec0().Degrees() ), epoch ( i ), imageName( i ).replace( ' ', '_' ), label( i ), labelColor( i ).name()); } }