本文整理汇总了C++中DateTime类的典型用法代码示例。如果您正苦于以下问题:C++ DateTime类的具体用法?C++ DateTime怎么用?C++ DateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
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);
}
示例2: writer
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;
}
示例3: assert
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);
}
示例4:
Time::Time()
{
DateTime dt;
assign(dt.hour(), dt.minute(), dt.second());
}
示例5: executeAtomSolver
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 );
}
//.........这里部分代码省略.........
示例6: DayTimeDuration
DayTimeDuration operator- (const DateTime& first, const DateTime& second)
{
return DayTimeDuration(first.NormalizedValue() - second.NormalizedValue());
}
示例7:
bool operator!= (const DateTime& first, const DateTime& second)
{
if (first.HasTimezone() == second.HasTimezone())
return first.NormalizedValue() != second.NormalizedValue();
return true;
}
示例8:
/// time duration
Time DateTime::operator- (const DateTime& dateTime) const
{
Time t1 = (m_date - dateTime.date());
Time t2 = (m_time - dateTime.time());
return t1 + t2;
}
示例9: return
/// equality operator
bool DateTime::operator== (const DateTime& other) const
{
return ((m_date==other.date()) && (m_time==other.time()));
}
示例10:
Revision::Revision(const DateTime dateTime)
{
m_revision.kind = svn_opt_revision_date;
m_revision.value.date = dateTime.GetAPRTimeT();
}
示例11: fnLog
// ===============
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;
}
}
示例12: GetNowDateTime
DateTime DateTime::GetNowDate()
{
DateTime tNow = GetNowDateTime();
tNow.StripTime();
return tNow;
}
示例13: warnf
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;
}
示例14: loop
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);
}
示例15: TimeSpan
TimeSpan DateTime::operator-(const DateTime& right) {
return TimeSpan(unixtime()-right.unixtime());
}