void Statement::bindParam(Param *parameter) { Param::ParamType paramType=parameter->getParamType(); DateTime *paramDT; switch(paramType){ case Param::Integer: OCI_BindInt(ociStmt, parameter->getParamName().toStdWString().c_str(), (int*)parameter->data); break; case Param::String: OCI_BindString(ociStmt, parameter->getParamName().toStdWString().c_str(), (dtext*)parameter->data, parameter->getMaxStringLength()); break; case Param::Double: OCI_BindDouble(ociStmt, parameter->getParamName().toStdWString().c_str(), (double*)parameter->data); break; case Param::Datetime: paramDT=parameter->getDateTimeValue(); paramDT->setConnection(this->connection); paramDT->copyToOci(); OCI_BindDate(ociStmt, parameter->getParamName().toStdWString().c_str(), paramDT->ociDate()); break; case Param::Stmt: { Statement *paramStmt=parameter->getStmtValue(); paramStmt->setConnection(this->connection); /*if(useScrollableResultsets){ int res=OCI_SetFetchMode(paramStmt->ociStatement(), OCI_SFM_SCROLLABLE); qDebug() << "OCI_SetFetchMode for param returned" << res; }*/ OCI_BindStatement(ociStmt, parameter->getParamName().toStdWString().c_str(), paramStmt->ociStatement()); } break; case Param::ReturningInto: OCI_RegisterString(ociStmt, parameter->getParamName().toStdWString().c_str(), 250); break; case Param::StringList: this->bindArrayOfStrings(parameter->getParamName(), (dtext*)parameter->data, parameter->getMaxStringLength(), parameter->getArraySize()); break; default: Q_ASSERT(false); break; } DbUtil::checkForOciError(this); setParamDirection(parameter); if(parameter->isNull()){ OCI_BindSetNull(OCI_GetBind2(ociStmt, parameter->getParamName().toStdWString().c_str())); } DbUtil::checkForOciError(this); }
bool File::Test( ) { bool ok = true; cout << "Testing File" << endl; try { const string testDataFileName = "FileTest.dat"; char testData[ 266 ] = { 0, '\r', '\n', '\r', '\n', '\n', '\r', '\r', 0, '\n' }; for ( int i = 0; i < 256; ++i ) testData[ i + 10 ] = static_cast< char >( i ); DataBuffer buff; buff.Add( testData, 266 ); { cout << "FileWriter( string ) constructor" << endl; FileWriter writer( testDataFileName ); cout << "writer.Save( DataBuffer )" << endl; writer.Save( buff ); } TESTCHECK( FileExists( testDataFileName ), true, &ok ); TESTCHECK( FileSize( testDataFileName ), (int) (ARRAY_LENGTH( testData )), &ok ); DateTime now( true ); DateTime then = now; then.Increment( 0, 0, 0, 0, -1 ); //1 minute ago TESTCHECK( (now < FileModDate( testDataFileName )), false, &ok ); TESTCHECK( (then < FileModDate( testDataFileName )), true, &ok ); buff.Clear( ); { cout << "FileReader( string ) constructor" << endl; FileReader reader( testDataFileName ); cout << "writer.Load( DataBuffer * )" << endl; reader.Load( &buff ); } const vector< char > & testData1 = buff.Buffer(); TESTCHECK( testData1.size(), ARRAY_LENGTH( testData ), &ok ); TESTCHECK( memcmp( &testData1[0], testData, ARRAY_LENGTH( testData ) ), 0, &ok ); cout << "DeleteFile( string )" << endl; DeleteFile( testDataFileName ); TESTCHECK( FileExists( testDataFileName ), false, &ok ); const string testTextFileName = "FileTest.txt"; const string testText = "Four score and seven years ago\n" "our fathers set forth upon this continent\n\r" "a new nation,\r\n" "conceived in liberty\r" "and dedicated to the proposition\x0" "that all men are created equal."; { cout << "FileWriter( string, File::Text ) constructor" << endl; FileWriter writer( testTextFileName, File::Text ); cout << "writer.Save( string )" << endl; writer.Save( testText ); } TESTCHECK( FileExists( testTextFileName ), true, &ok ); string testText1; { cout << "FileReader( string, File::Text ) constructor" << endl; FileReader reader( testTextFileName, File::Text ); cout << "reader.Load( string * )" << endl; reader.Load( &testText1 ); } TESTCHECK( (testText1 == testText), true, &ok ); cout << "DeleteFile( string )" << endl; DeleteFile( testTextFileName ); TESTCHECK( FileExists( testTextFileName ), false, &ok ); } catch ( FileException & except ) { cout << except.Description() << endl; ok = false; } if ( ok ) cout << "File PASSED." << endl << endl; else cout << "File FAILED." << endl << endl; return ok; }
void DateTimeParserTest::testRFC1123() { int tzd; DateTime dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sat, 8 Jan 2005 12:30:00 GMT", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 0); dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sat, 8 Jan 2005 12:30:00 +0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 3600); dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sat, 8 Jan 2005 12:30:00 -0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == -3600); dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sun, 20 Jul 1969 16:17:30 EDT", tzd); assert (dt.year() == 1969); assert (dt.month() == 7); assert (dt.day() == 20); assert (dt.hour() == 16); assert (dt.minute() == 17); assert (dt.second() == 30); assert (tzd == -14400); dt = DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, "Sun, 20 Jul 1969 16:17:30 GMT+01:00", tzd); assert (dt.year() == 1969); assert (dt.month() == 7); assert (dt.day() == 20); assert (dt.hour() == 16); assert (dt.minute() == 17); assert (dt.second() == 30); assert (tzd == 3600); }
Time::Time() { DateTime dt; assign(dt.hour(), dt.minute(), dt.second()); }
const std::pair< Vector3, Vector3 > executeAtomSolver( const Vector3& departurePosition, const DateTime& departureEpoch, const Vector3& arrivalPosition, const Real timeOfFlight, const Vector3& departureVelocityGuess, std::string& solverStatusSummary, int& numberOfIterations, const Tle& referenceTle, const Real earthGravitationalParameter, const Real earthMeanRadius, const Real absoluteTolerance, const Real relativeTolerance, const int maximumIterations ) { // Set up parameters for residual function. AtomParameters< Real, Vector3 > parameters( departurePosition, departureEpoch, arrivalPosition, timeOfFlight, earthGravitationalParameter, earthMeanRadius, referenceTle, absoluteTolerance, relativeTolerance, maximumIterations ); // Set up residual function. gsl_multiroot_function atomFunction = { &computeAtomResiduals< Real, Vector3 >, 3, ¶meters }; // Set initial guess. gsl_vector* initialGuess = gsl_vector_alloc( 3 ); for ( int i = 0; i < 3; i++ ) { gsl_vector_set( initialGuess, i, departureVelocityGuess[ i ] ); } // Set up solver type (derivative free). const gsl_multiroot_fsolver_type* solverType = gsl_multiroot_fsolver_hybrids; // Allocate memory for solver. gsl_multiroot_fsolver* solver = gsl_multiroot_fsolver_alloc( solverType, 3 ); // Set solver to use residual function with initial guess. gsl_multiroot_fsolver_set( solver, &atomFunction, initialGuess ); // Declare current solver status and iteration counter. int solverStatus = false; int counter = 0; // Set up buffer to store solver status summary table. std::ostringstream summary; // Print header for summary table to buffer. summary << printAtomSolverStateTableHeader( ); do { // Print current state of solver for summary table. summary << printAtomSolverState( counter, solver ); // Increment iteration counter. ++counter; // Execute solver iteration. solverStatus = gsl_multiroot_fsolver_iterate( solver ); // Check if solver is stuck; if it is stuck, break from loop. if ( solverStatus ) { std::cerr << "GSL solver status: " << solverStatus << std::endl; std::cerr << summary.str( ) << std::endl; std::cerr << std::endl; throw std::runtime_error( "ERROR: Non-linear solver is stuck!" ); } // Check if root has been found (within tolerance). solverStatus = gsl_multiroot_test_delta( solver->dx, solver->x, absoluteTolerance, relativeTolerance ); } while ( solverStatus == GSL_CONTINUE && counter < maximumIterations ); // Save number of iterations. numberOfIterations = counter - 1; // Print final status of solver to buffer. summary << std::endl; summary << "Status of non-linear solver: " << gsl_strerror( solverStatus ) << std::endl; summary << std::endl; // Write buffer contents to solver status summary string. solverStatusSummary = summary.str( ); // Store final departure velocity. Vector3 departureVelocity = departureVelocityGuess; for ( int i = 0; i < 3; i++ ) { departureVelocity[ i ] = gsl_vector_get( solver->x, i ); } // Set departure state [km/s]. std::vector< Real > departureState( 6 ); for ( int i = 0; i < 3; i++ ) { departureState[ i ] = departurePosition[ i ]; } for ( int i = 0; i < 3; i++ ) { departureState[ i + 3 ] = departureVelocity[ i ]; } // Convert departure state to TLE. std::string dummyString = ""; int dummyint = 0; const Tle departureTle = convertCartesianStateToTwoLineElements< Real >( departureState, departureEpoch, dummyString, dummyint, referenceTle, earthGravitationalParameter, earthMeanRadius, absoluteTolerance, relativeTolerance, maximumIterations ); // Propagate departure TLE by time-of-flight using SGP4 propagator. SGP4 sgp4( departureTle ); DateTime arrivalEpoch = departureEpoch.AddSeconds( timeOfFlight ); Eci arrivalState = sgp4.FindPosition( arrivalEpoch ); Vector3 arrivalVelocity = departureVelocity; arrivalVelocity[ 0 ] = arrivalState.Velocity( ).x; arrivalVelocity[ 1 ] = arrivalState.Velocity( ).y; arrivalVelocity[ 2 ] = arrivalState.Velocity( ).z; // Free up memory. gsl_multiroot_fsolver_free( solver ); gsl_vector_free( initialGuess ); // Return departure and arrival velocities. return std::make_pair< Vector3, Vector3 >( departureVelocity, arrivalVelocity ); }
DayTimeDuration operator- (const DateTime& first, const DateTime& second) { return DayTimeDuration(first.NormalizedValue() - second.NormalizedValue()); }
bool operator!= (const DateTime& first, const DateTime& second) { if (first.HasTimezone() == second.HasTimezone()) return first.NormalizedValue() != second.NormalizedValue(); return true; }
/// time duration Time DateTime::operator- (const DateTime& dateTime) const { Time t1 = (m_date - dateTime.date()); Time t2 = (m_time - dateTime.time()); return t1 + t2; }
/// equality operator bool DateTime::operator== (const DateTime& other) const { return ((m_date==other.date()) && (m_time==other.time())); }
Revision::Revision(const DateTime dateTime) { m_revision.kind = svn_opt_revision_date; m_revision.value.date = dateTime.GetAPRTimeT(); }
// =============== void Log::Initialise // =============== ( EngineSetting* pSetting // pointer to Setting object ) { // Set the log name to the name of the cluster; place the '@' character // after it. m_strLogName = pSetting->Get( "CLUSTER", "FileName" ) + "@"; // Make a string out of the current date and time (separated by an // underscore), and add this to the back of the file name. DateTime dt; m_strLogName += dt.Get( "YYYYMMDD_hhmmss" ); // Replace all characters that are not allowed in a file name by underscores. string::size_type nChar; while ( (nChar = m_strLogName.find_first_of( NOT_ALLOWED_IN_FILE )) != string::npos ) { m_strLogName.replace( nChar, 1, "_" ); } // Create a FileName object of the log name; set its extension; // set its location as specified in the settings. FileName fnLog( m_strLogName ); fnLog.ChangeExtension( LOG_EXTENSION ); fnLog.ChangeLocation( pSetting->Get( "LOG", "Path" ) ); // Determine if the file name is unique. int nCounter = 0; bool bUnique = false; while ( !bUnique ) { // If the name was already once found to be not unique, add // another '#' character to the back of the name. if ( nCounter > 0 ) { fnLog.ChangeName( fnLog.GetName() + "#" ); } // Get the new log file. m_strLogName = fnLog.GetFile(); // Determine if a file with this name/location already exists. if( FileExists( m_strLogName ) ) { // File name already exists; update counter. nCounter++; } else { bUnique = true; } } // Open the output medium for writing, and check if this succeeds. if ( Open( m_strLogName, WRITE ) ) { m_bGood = true; } }
DateTime DateTime::GetNowDate() { DateTime tNow = GetNowDateTime(); tNow.StripTime(); return tNow; }
bool CDeviceController::closeDoor(JSON::Object::Ptr& param, std::string& detail) { if(m_fd == 0) { warnf("%s, %d: Maybe should call openDevice first.", __FILE__, __LINE__); detail = "420"; return false; } if(!m_door_open) { infof("%s, %d: Door already closed.", __FILE__, __LINE__); return true; } std::string token; if(!param.isNull()) { token = param->getValue<std::string>(REG_TOKEN_STR); param->remove(REG_TOKEN_STR); if(m_user_mode == 1 && m_user_manager->userAuthority(token) != CUserManager::USER_AUTHORITY_ADMIN) { warnf("%s, %d: Device in admin mode, only admin can close door.", __FILE__, __LINE__); detail = "421"; return false; } } #ifdef __SC_ARM__ #ifdef __SC_ON_NORMAL_CLOSE__ ioctl(m_fd, SC_RELAY_OFF, 0); #else ioctl(m_fd, SC_RELAY_ON, 0); #endif #else tracef("%s, %d: X86 does not implement closeDoor.", __FILE__, __LINE__); #endif m_door_open = false; OperationRecordNode op = {0, 0, "", 0}; DateTime now; now.makeLocal(Timezone::tzd()); op.timestamp = now.timestamp().epochMicroseconds(); op.operation = 0; op.username = ""; op.schema = -1; if(param.isNull()) //scheduled { op.schema = 1; infof("%s, %d: Door closed by schedule.", __FILE__, __LINE__); } else //manual { op.schema = 0; std::string username; if(m_user_manager->getUserNameFromToken(token, username)) { op.username = username; } infof("%s, %d: Door closed by manual[User:%s].", __FILE__, __LINE__, op.username.c_str()); } m_op_manager->addRecord(op); return true; }
void loop () { DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); Serial.print(" since midnight 1/1/1970 = "); Serial.print(now.unixtime()); Serial.print("s = "); Serial.print(now.unixtime() / 86400L); Serial.println("d"); // calculate a date which is 7 days and 30 seconds into the future DateTime future (now.unixtime() + 7 * 86400L + 30); Serial.print(" now + 7d + 30s: "); Serial.print(future.year(), DEC); Serial.print('/'); Serial.print(future.month(), DEC); Serial.print('/'); Serial.print(future.day(), DEC); Serial.print(' '); Serial.print(future.hour(), DEC); Serial.print(':'); Serial.print(future.minute(), DEC); Serial.print(':'); Serial.print(future.second(), DEC); Serial.println(); Serial.println(); delay(3000); }
TimeSpan DateTime::operator-(const DateTime& right) { return TimeSpan(unixtime()-right.unixtime()); }
/// non-equality operator bool DateTime::operator!= (const DateTime& other) const { return ((m_date!=other.date()) || (m_time!=other.time())); }
void RTC_Millis::adjust(const DateTime& dt) { offset = dt.unixtime() - millis() / 1000; }
/// copy constructor DateTime::DateTime(const DateTime& other) : m_date(other.date()), m_time(other.time()) { // should not need to normalize }
DateTime operator- (const DateTime& first, const DayTimeDuration& second) { return DateTime(first.Value() - second.Value(), first.Timezone()); }
boolean Cron::matchCron(String cronString, DateTime time){ boolean secMatch,minMatch,hourMatch,dayMatch,monMatch,yearMatch; String tempTimeString; String commandString; int cronTime[6]; cronString.trim(); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[0] = -1; } else { cronTime[0] = tempTimeString.toInt(); } cronString.trim(); cronString = cronString.substring(cronString.indexOf('.') + 1); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[1] = -1; } else { cronTime[1] = tempTimeString.toInt(); } cronString = cronString.substring(cronString.indexOf('.') + 1); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[2] = -1; } else { cronTime[2] = tempTimeString.toInt(); } cronString = cronString.substring(cronString.indexOf('.') + 1); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[3] = -1; } else { cronTime[3] = tempTimeString.toInt(); } cronString = cronString.substring(cronString.indexOf('.') + 1); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[4] = -1; } else { cronTime[4] = tempTimeString.toInt(); } cronString = cronString.substring(cronString.indexOf('.') + 1); tempTimeString = cronString.substring(0,cronString.indexOf('.')); if (tempTimeString.equals("*")) { cronTime[5] = -1; } else { cronTime[5] = tempTimeString.toInt(); } cronString = cronString.substring(cronString.indexOf('.') + 1); commandString = cronString.substring(0,cronString.indexOf('.')); cronString = ""; if (cronTime[5] == -1){ yearMatch = true; } else if (time.year() == cronTime[5]){ yearMatch = true; } else{ yearMatch = false; } if (cronTime[4] == -1){ monMatch = true; } else if (time.month() == cronTime[4]){ monMatch = true; } else{ monMatch = false; } if (cronTime[3] == -1){ dayMatch = true; } else if (time.day() == cronTime[3]){ dayMatch = true; } else{ dayMatch = false; } if (cronTime[2] == -1){ hourMatch = true; } else if (time.hour() == cronTime[2]){ hourMatch = true; } else{ hourMatch = false; } if (cronTime[1] == -1){ minMatch = true; } else if (time.minute() == cronTime[1]){ minMatch = true; } else{ minMatch = false; } if (cronTime[0] == -1){ secMatch = true; } else if (time.second() == cronTime[0]){ secMatch = true; } else{ secMatch = false; } if (secMatch && minMatch && hourMatch && dayMatch && monMatch && yearMatch){ return true; } else { return false; } }
AlarmListViewItem::AlarmListViewItem(AlarmListView *parent, const KAEvent &event, const QDateTime &now) : EventListViewItemBase(parent, event), mMessageTruncated(false), mTimeToAlarmShown(false) { setLastColumnText(); // set the message column text DateTime dateTime = event.expired() ? event.startDateTime() : event.displayDateTime(); if(parent->column(AlarmListView::TIME_COLUMN) >= 0) setText(parent->column(AlarmListView::TIME_COLUMN), alarmTimeText(dateTime)); if(parent->column(AlarmListView::TIME_TO_COLUMN) >= 0) { QString tta = timeToAlarmText(now); setText(parent->column(AlarmListView::TIME_TO_COLUMN), tta); mTimeToAlarmShown = !tta.isNull(); } QTime t = dateTime.time(); mDateTimeOrder.sprintf("%04d%03d%02d%02d", dateTime.date().year(), dateTime.date().dayOfYear(), t.hour(), t.minute()); int repeatOrder = 0; int repeatInterval = 0; QString repeatText = event.recurrenceText(true); // text displayed in Repeat column if(repeatText.isEmpty()) repeatText = event.repetitionText(true); if(event.repeatAtLogin()) repeatOrder = 1; else { repeatInterval = event.recurInterval(); switch(event.recurType()) { case KARecurrence::MINUTELY: repeatOrder = 2; break; case KARecurrence::DAILY: repeatOrder = 3; break; case KARecurrence::WEEKLY: repeatOrder = 4; break; case KARecurrence::MONTHLY_DAY: case KARecurrence::MONTHLY_POS: repeatOrder = 5; break; case KARecurrence::ANNUAL_DATE: case KARecurrence::ANNUAL_POS: repeatOrder = 6; break; case KARecurrence::NO_RECUR: default: break; } } setText(parent->column(AlarmListView::REPEAT_COLUMN), repeatText); mRepeatOrder.sprintf("%c%08d", '0' + repeatOrder, repeatInterval); bool showColour = (event.action() == KAEvent::MESSAGE || event.action() == KAEvent::FILE); mColourOrder.sprintf("%06u", (showColour ? event.bgColour().rgb() : 0)); mTypeOrder.sprintf("%02d", event.action()); }
void PatternFormatter::format(const Message& msg, std::string& text) { Timestamp timestamp = msg.getTime(); bool localTime = _localTime; if (localTime) { timestamp += Timezone::utcOffset()*Timestamp::resolution(); timestamp += Timezone::dst()*Timestamp::resolution(); } DateTime dateTime = timestamp; for (std::vector<PatternAction>::iterator ip = _patternActions.begin(); ip != _patternActions.end(); ++ip) { text.append(ip->prepend); switch (ip->key) { case 's': text.append(msg.getSource()); break; case 't': text.append(msg.getText()); break; case 'l': NumberFormatter::append(text, (int) msg.getPriority()); break; case 'p': text.append(getPriorityName((int) msg.getPriority())); break; case 'q': text += getPriorityName((int) msg.getPriority()).at(0); break; case 'P': NumberFormatter::append(text, msg.getPid()); break; case 'T': text.append(msg.getThread()); break; case 'I': NumberFormatter::append(text, msg.getTid()); break; case 'O': NumberFormatter::append(text, msg.getOsTid()); break; case 'N': text.append(Environment::nodeName()); break; case 'U': text.append(msg.getSourceFile() ? msg.getSourceFile() : ""); break; case 'u': NumberFormatter::append(text, msg.getSourceLine()); break; case 'w': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3); break; case 'W': text.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]); break; case 'b': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3); break; case 'B': text.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]); break; case 'd': NumberFormatter::append0(text, dateTime.day(), 2); break; case 'e': NumberFormatter::append(text, dateTime.day()); break; case 'f': NumberFormatter::append(text, dateTime.day(), 2); break; case 'm': NumberFormatter::append0(text, dateTime.month(), 2); break; case 'n': NumberFormatter::append(text, dateTime.month()); break; case 'o': NumberFormatter::append(text, dateTime.month(), 2); break; case 'y': NumberFormatter::append0(text, dateTime.year() % 100, 2); break; case 'Y': NumberFormatter::append0(text, dateTime.year(), 4); break; case 'H': NumberFormatter::append0(text, dateTime.hour(), 2); break; case 'h': NumberFormatter::append0(text, dateTime.hourAMPM(), 2); break; case 'a': text.append(dateTime.isAM() ? "am" : "pm"); break; case 'A': text.append(dateTime.isAM() ? "AM" : "PM"); break; case 'M': NumberFormatter::append0(text, dateTime.minute(), 2); break; case 'S': NumberFormatter::append0(text, dateTime.second(), 2); break; case 'i': NumberFormatter::append0(text, dateTime.millisecond(), 3); break; case 'c': NumberFormatter::append(text, dateTime.millisecond()/100); break; case 'F': NumberFormatter::append0(text, dateTime.millisecond()*1000 + dateTime.microsecond(), 6); break; case 'z': text.append(DateTimeFormatter::tzdISO(localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break; case 'Z': text.append(DateTimeFormatter::tzdRFC(localTime ? Timezone::tzd() : DateTimeFormatter::UTC)); break; case 'E': NumberFormatter::append(text, msg.getTime().epochTime()); break; case 'v': if (ip->length > msg.getSource().length()) //append spaces text.append(msg.getSource()).append(ip->length - msg.getSource().length(), ' '); else if (ip->length && ip->length < msg.getSource().length()) // crop text.append(msg.getSource(), msg.getSource().length()-ip->length, ip->length); else text.append(msg.getSource()); break; case 'x': try { text.append(msg[ip->property]); } catch (...) { } break; case 'L': if (!localTime) { localTime = true; timestamp += Timezone::utcOffset()*Timestamp::resolution(); timestamp += Timezone::dst()*Timestamp::resolution(); dateTime = timestamp; } break; } } }
Time::Time(const DateTime& dt) { assign(dt.hour(), dt.minute(), dt.second()); }
DateTime & getTime() { static DateTime dt; dt.mark(); return dt; }
int computeAtomResiduals( const gsl_vector* independentVariables, void* parameters, gsl_vector* residuals ) { // Store parameters locally. const Vector3 departurePosition = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->departurePosition; const DateTime departureEpoch = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->departureEpoch; const Vector3 targetPosition = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->targetPosition; const Real timeOfFlight = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->timeOfFlight; const Real earthGravitationalParameter = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->earthGravitationalParameter; const Real earthMeanRadius = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->earthMeanRadius; const Tle referenceTle = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->referenceTle; const Real absoluteTolerance = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->absoluteTolerance; const Real relativeTolerance = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->relativeTolerance; const int maximumIterations = static_cast< AtomParameters< Real, Vector3 >* >( parameters )->maximumIterations; // Set Departure state [km; km/s]. std::vector< Real > departureVelocity( 3 ); for ( int i = 0; i < 3; i++ ) { departureVelocity[ i ] = gsl_vector_get( independentVariables, i ); } std::vector< Real > departureState( 6 ); for ( int i = 0; i < 3; i++ ) { departureState[ i ] = departurePosition[ i ]; } for ( int i = 0; i < 3; i++ ) { departureState[ i + 3 ] = departureVelocity[ i ]; } // Convert departure state to TLE. std::string dummyString = ""; int dummyint = 0; const Tle departureTle = convertCartesianStateToTwoLineElements( departureState, departureEpoch, dummyString, dummyint, referenceTle, earthGravitationalParameter, earthMeanRadius, absoluteTolerance, relativeTolerance, maximumIterations ); // Propagate departure TLE by time-of-flight using SGP4 propagator. SGP4 sgp4( departureTle ); DateTime arrivalEpoch = departureEpoch.AddSeconds( timeOfFlight ); Eci arrivalState = sgp4.FindPosition( arrivalEpoch ); // Evaluate system of non-linear equations and store residuals. gsl_vector_set( residuals, 0, ( arrivalState.Position( ).x - targetPosition[ 0 ] ) / earthMeanRadius ); gsl_vector_set( residuals, 1, ( arrivalState.Position( ).y - targetPosition[ 1 ] ) / earthMeanRadius ); gsl_vector_set( residuals, 2, ( arrivalState.Position( ).z - targetPosition[ 2 ] ) / earthMeanRadius ); return GSL_SUCCESS; }
static void checkTime() { DateTime time = rtc.now(); if (time.hour() >= 20); }
void DateTimeParserTest::testRFC822() { int tzd; DateTime dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Sat, 8 Jan 05 12:30:00 GMT", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 0); dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Sat, 8 Jan 05 12:30:00 +0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 3600); dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Sat, 8 Jan 05 12:30:00 -0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == -3600); dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Tue, 18 Jan 05 12:30:00 CET", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 18); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 3600); dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "Wed, 12 Sep 73 02:01:12 CEST", tzd); assert (dt.year() == 1973); assert (dt.month() == 9); assert (dt.day() == 12); assert (dt.hour() == 2); assert (dt.minute() == 1); assert (dt.second() == 12); assert (tzd == 7200); dt = DateTimeParser::parse(DateTimeFormat::RFC822_FORMAT, "12 Sep 73 02:01:12 CEST", tzd); assert (dt.year() == 1973); assert (dt.month() == 9); assert (dt.day() == 12); assert (dt.hour() == 2); assert (dt.minute() == 1); assert (dt.second() == 12); assert (tzd == 7200); }
ExitCodes main_(int, const char **) { //------------------------------------------------------------- // parameter handling //------------------------------------------------------------- //input/output files String in(getStringOption_("in")); String out(getStringOption_("out")); //------------------------------------------------------------- // loading input //------------------------------------------------------------- PeakMap exp; MzMLFile f; f.setLogType(log_type_); PeakFileOptions options; options.clearMSLevels(); options.addMSLevel(2); f.getOptions() = options; f.load(in, exp); writeDebug_("Data set contains " + String(exp.size()) + " spectra", 1); //------------------------------------------------------------- // calculations //------------------------------------------------------------- vector<PeptideIdentification> pep_ids; CompNovoIdentification comp_novo_id; // set the options Param algorithm_param = getParam_().copy("algorithm:", true); comp_novo_id.setParameters(algorithm_param); comp_novo_id.getIdentifications(pep_ids, exp); algorithm_param = comp_novo_id.getParameters(); //------------------------------------------------------------- // writing output //------------------------------------------------------------- DateTime now = DateTime::now(); String date_string = now.get(); String identifier("CompNovo_" + date_string); for (vector<PeptideIdentification>::iterator it = pep_ids.begin(); it != pep_ids.end(); ++it) { it->assignRanks(); it->setIdentifier(identifier); } vector<ProteinIdentification> prot_ids; ProteinIdentification prot_id; prot_id.setIdentifier(identifier); prot_id.setDateTime(now); StringList ms_runs; exp.getPrimaryMSRunPath(ms_runs); prot_id.setPrimaryMSRunPath(ms_runs); ProteinIdentification::SearchParameters search_parameters; search_parameters.charges = "+2-+3"; if (algorithm_param.getValue("tryptic_only").toBool()) { search_parameters.digestion_enzyme = *EnzymesDB::getInstance()->getEnzyme("Trypsin"); } else { search_parameters.digestion_enzyme = *EnzymesDB::getInstance()->getEnzyme("no cleavage"); } search_parameters.mass_type = ProteinIdentification::MONOISOTOPIC; search_parameters.fixed_modifications = algorithm_param.getValue("fixed_modifications"); search_parameters.variable_modifications = algorithm_param.getValue("variable_modifications"); search_parameters.missed_cleavages = (UInt)algorithm_param.getValue("missed_cleavages"); search_parameters.fragment_mass_tolerance = (double)algorithm_param.getValue("fragment_mass_tolerance"); search_parameters.precursor_mass_tolerance = (double)algorithm_param.getValue("precursor_mass_tolerance"); prot_id.setSearchParameters(search_parameters); prot_id.setSearchEngineVersion("0.9beta"); prot_id.setSearchEngine("CompNovo"); prot_ids.push_back(prot_id); IdXMLFile().store(out, prot_ids, pep_ids); return EXECUTION_OK; }
void DateTimeParserTest::testHTTP() { int tzd; DateTime dt = DateTimeParser::parse(DateTimeFormat::HTTP_FORMAT, "Sat, 08 Jan 2005 12:30:00 GMT", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 0); dt = DateTimeParser::parse(DateTimeFormat::HTTP_FORMAT, "Sat, 08 Jan 2005 12:30:00 +0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == 3600); dt = DateTimeParser::parse(DateTimeFormat::HTTP_FORMAT, "Sat, 08 Jan 2005 12:30:00 -0100", tzd); assert (dt.year() == 2005); assert (dt.month() == 1); assert (dt.day() == 8); assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); assert (tzd == -3600); }
bool mayPayTax() { DateTime currentDate = Scenario::instance().getCity()->getDate(); return lastPayDate.getMonthToDate( currentDate ) > 0; }