本文整理汇总了C++中Poco::DateTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Poco::DateTime方法的具体用法?C++ Poco::DateTime怎么用?C++ Poco::DateTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Poco
的用法示例。
在下文中一共展示了Poco::DateTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRotateAtTimeMinLocal
void FileChannelTest::testRotateAtTimeMinLocal()
{
std::string name = filename();
try
{
AutoPtr<FileChannel> pChannel = new FileChannel(name);
pChannel->setProperty(FileChannel::PROP_TIMES, "local");
pChannel->setProperty(FileChannel::PROP_ROTATION, rotation<LocalDateTime>(MIN));
pChannel->open();
Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
int min = DateTime().minute();
while (DateTime().minute() == min)
{
pChannel->log(msg);
Thread::sleep(1000);
}
pChannel->log(msg);
File f(name + ".0");
assert (f.exists());
}
catch (...)
{
remove(name);
throw;
}
remove(name);
}
示例2: testArithmetics
void DateTimeTest::testArithmetics()
{
DateTime dt1(2005, 1, 1, 0, 15, 30);
DateTime dt2(2005, 1, 2, 0, 15, 30);
Timespan s = dt2 - dt1;
assert (s.days() == 1);
DateTime dt3 = dt1 + s;
assert (dt3 == dt2);
dt3 -= s;
assert (dt3 == dt1);
dt1 += s;
assert (dt1 == dt2);
static const struct
{
int lineNum; // source line number
int year1; // operand/result date1 year
int month1; // operand/result date1 month
unsigned int day1; // operand/result date1 day
int numDays; // operand/result 'int' number of days
int year2; // operand/result date2 year
int month2; // operand/result date2 month
unsigned int day2; // operand/result date2 day
} data[] =
{
// - - - -first- - - - - - - second - - -
//line no. year month day numDays year month day
//------- ----- ----- ----- ------- ----- ----- -----
{ __LINE__, 1, 1, 1, 1, 1, 1, 2 },
{ __LINE__, 10, 2, 28, 1, 10, 3, 1 },
{ __LINE__, 100, 3, 31, 2, 100, 4, 2 },
{ __LINE__, 1000, 4, 30, 4, 1000, 5, 4 },
{ __LINE__, 1000, 6, 1, -31, 1000, 5, 1 },
{ __LINE__, 1001, 1, 1, -365, 1000, 1, 1 },
{ __LINE__, 1100, 5, 31, 30, 1100, 6, 30 },
{ __LINE__, 1200, 6, 30, 32, 1200, 8, 1 },
{ __LINE__, 1996, 2, 28, 367, 1997, 3, 1 },
{ __LINE__, 1997, 2, 28, 366, 1998, 3, 1 },
{ __LINE__, 1998, 2, 28, 365, 1999, 2, 28 },
{ __LINE__, 1999, 2, 28, 364, 2000, 2, 27 },
{ __LINE__, 1999, 2, 28, 1096, 2002, 2, 28 },
{ __LINE__, 2002, 2, 28, -1096, 1999, 2, 28 },
};
const int num_data = sizeof data / sizeof *data;
for (int di = 0; di < num_data; ++di)
{
const int line = data[di].lineNum;
const int num_days = data[di].numDays;
DateTime x = DateTime(data[di].year1, data[di].month1, data[di].day1);
const DateTime& X = x;
x += Timespan(num_days, 0, 0, 0, 0);
loop_1_assert(line, data[di].year2 == X.year());
loop_1_assert(line, data[di].month2 == X.month());
loop_1_assert(line, data[di].day2 == X.day());
}
}
示例3: testDayOfWeek
void DateTimeTest::testDayOfWeek()
{
typedef DateTime::DaysOfWeek DOW;
static const struct
{
int d_lineNum; // source line number
int d_year; // year under test
int d_month; // month under test
int d_day; // day under test
DOW d_expDay; // number of days to be added
} data[] =
{
//Line no. year month day expDay
//------- ----- ----- ----- -------
{ __LINE__, 1600, 1, 1, DateTime::SATURDAY },
{ __LINE__, 1600, 1, 2, DateTime::SUNDAY },
{ __LINE__, 1600, 1, 3, DateTime::MONDAY },
{ __LINE__, 1600, 1, 4, DateTime::TUESDAY },
{ __LINE__, 1600, 1, 5, DateTime::WEDNESDAY },
{ __LINE__, 1600, 1, 6, DateTime::THURSDAY },
{ __LINE__, 1600, 1, 7, DateTime::FRIDAY },
{ __LINE__, 1600, 1, 8, DateTime::SATURDAY },
{ __LINE__, 1752, 8, 27, DateTime::SUNDAY },
{ __LINE__, 1752, 8, 28, DateTime::MONDAY },
{ __LINE__, 1752, 8, 29, DateTime::TUESDAY },
{ __LINE__, 1752, 8, 30, DateTime::WEDNESDAY },
{ __LINE__, 1752, 8, 31, DateTime::THURSDAY },
{ __LINE__, 1752, 9, 1, DateTime::FRIDAY },
{ __LINE__, 1752, 9, 2, DateTime::SATURDAY },
{ __LINE__, 1752, 9, 14, DateTime::THURSDAY },
{ __LINE__, 1752, 9, 15, DateTime::FRIDAY },
{ __LINE__, 1752, 9, 16, DateTime::SATURDAY },
{ __LINE__, 1752, 9, 17, DateTime::SUNDAY },
{ __LINE__, 1752, 9, 18, DateTime::MONDAY },
{ __LINE__, 1752, 9, 19, DateTime::TUESDAY },
{ __LINE__, 1999, 12, 28, DateTime::TUESDAY },
{ __LINE__, 1999, 12, 29, DateTime::WEDNESDAY },
{ __LINE__, 1999, 12, 30, DateTime::THURSDAY },
{ __LINE__, 1999, 12, 31, DateTime::FRIDAY },
{ __LINE__, 2000, 1, 1, DateTime::SATURDAY },
{ __LINE__, 2000, 1, 2, DateTime::SUNDAY },
{ __LINE__, 2000, 1, 3, DateTime::MONDAY },
{ __LINE__, 2000, 1, 4, DateTime::TUESDAY },
};
const int num_data = sizeof data / sizeof *data;
for (int di = 0; di < num_data ; ++di)
{
const int line = data[di].d_lineNum;
DateTime x = DateTime(data[di].d_year, data[di].d_month, data[di].d_day);
const DateTime& X = x;
loop_1_assert(line, data[di].d_expDay == X.dayOfWeek());
}
}
示例4: testJulian
void DateTimeTest::testJulian()
{
DateTime dt(2440587.5); // unix epoch as Julian day
assert (dt.year() == 1970);
assert (dt.month() == 1);
assert (dt.day() == 1);
assert (dt.hour() == 0);
assert (dt.minute() == 0);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.dayOfWeek() == 4);
assert (dt.julianDay() == 2440587.5);
assert (dt.timestamp() == 0);
dt = 2299160.5; // 1582-10-15 00:00:00 (first day of Gregorian reform, UTC base)
assert (dt.year() == 1582);
assert (dt.month() == 10);
assert (dt.day() == 15);
assert (dt.hour() == 0);
assert (dt.minute() == 0);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.dayOfWeek() == 5);
assert (dt.julianDay() == 2299160.5);
dt = 0.0; // -4713-11-24 12:00:00 (Gregorian date of Julian day reference)
assert (dt.year() == -4713);
assert (dt.month() == 11);
assert (dt.day() == 24);
assert (dt.hour() == 12);
assert (dt.minute() == 0);
assert (dt.second() == 0);
assert (dt.millisecond() == 0);
assert (dt.dayOfWeek() == 1);
assert (dt.julianDay() == 0);
// Test that we can represent down to the microsecond.
dt = DateTime(2010, 1, 31, 17, 30, 15, 800, 3);
assert (dt.year() == 2010);
assert (dt.month() == 1);
assert (dt.day() == 31);
assert (dt.hour() == 17);
assert (dt.minute() == 30);
assert (dt.second() == 15);
assert (dt.millisecond() == 800);
assert (dt.microsecond() == 3);
}
示例5: testPatternFormatter
void PatternFormatterTest::testPatternFormatter()
{
Message msg;
PatternFormatter fmt;
msg.setSource("TestSource");
msg.setText("Test message text");
msg.setPid(1234);
msg.setTid(1);
msg.setThread("TestThread");
msg.setPriority(Message::PRIO_ERROR);
msg.setTime(DateTime(2005, 1, 1, 14, 30, 15, 500).timestamp());
msg["testParam"] = "Test Parameter";
std::string result;
fmt.setProperty("pattern", "%Y-%m-%dT%H:%M:%S [%s] %p: %t");
fmt.format(msg, result);
assert (result == "2005-01-01T14:30:15 [TestSource] Error: Test message text");
result.clear();
fmt.setProperty("pattern", "%w, %e %b %y %H:%M:%S.%i [%s:%I:%T] %q: %t");
fmt.format(msg, result);
assert (result == "Sat, 1 Jan 05 14:30:15.500 [TestSource:1:TestThread] E: Test message text");
result.clear();
fmt.setProperty("pattern", "%Y-%m-%d %H:%M:%S [%N:%P:%s]%l-%t");
fmt.format(msg, result);
assert (result.find("2005-01-01 14:30:15 [") == 0);
assert (result.find(":TestSource]3-Test message text") != std::string::npos);
result.clear();
assert (fmt.getProperty("times") == "UTC");
fmt.setProperty("times", "local");
fmt.format(msg, result);
assert (result.find("2005-01-01 ") == 0);
assert (result.find(":TestSource]3-Test message text") != std::string::npos);
result.clear();
fmt.setProperty("pattern", "%[testParam]");
fmt.format(msg, result);
assert (result == "Test Parameter");
result.clear();
fmt.setProperty("pattern", "%[testParam] %p");
fmt.format(msg, result);
assert (result == "Test Parameter Error");
}
示例6: testIncrementDecrement
void DateTimeTest::testIncrementDecrement()
{
static const struct
{
int lineNum; // source line number
int year1; // (first) date year
int month1; // (first) date month
unsigned int day1; // (first) date day
int year2; // (second) date year
int month2; // (second) date month
unsigned int day2; // (second) date day
} data[] =
{
// - - - -first- - - - - - - second - - -
//line no. year month day year month day
//------- ----- ----- ----- ----- ----- -----
{ __LINE__, 1, 1, 1, 1, 1, 2 },
{ __LINE__, 10, 2, 28, 10, 3, 1 },
{ __LINE__, 100, 3, 31, 100, 4, 1 },
{ __LINE__, 1000, 4, 30, 1000, 5, 1 },
{ __LINE__, 1100, 5, 31, 1100, 6, 1 },
{ __LINE__, 1200, 6, 30, 1200, 7, 1 },
{ __LINE__, 1300, 7, 31, 1300, 8, 1 },
{ __LINE__, 1400, 8, 31, 1400, 9, 1 },
{ __LINE__, 1500, 9, 30, 1500, 10, 1 },
{ __LINE__, 1600, 10, 31, 1600, 11, 1 },
{ __LINE__, 1700, 11, 30, 1700, 12, 1 },
{ __LINE__, 1800, 12, 31, 1801, 1, 1 },
{ __LINE__, 1996, 2, 28, 1996, 2, 29 },
{ __LINE__, 1997, 2, 28, 1997, 3, 1 },
{ __LINE__, 1998, 2, 28, 1998, 3, 1 },
{ __LINE__, 1999, 2, 28, 1999, 3, 1 },
{ __LINE__, 2000, 2, 28, 2000, 2, 29 },
{ __LINE__, 2001, 2, 28, 2001, 3, 1 },
{ __LINE__, 2004, 2, 28, 2004, 2, 29 },
{ __LINE__, 2100, 2, 28, 2100, 3, 1 },
{ __LINE__, 2400, 2, 28, 2400, 2, 29 },
};
const int num_data = sizeof data / sizeof *data;
int di;
for (di = 0; di < num_data; ++di)
{
const int line = data[di].lineNum;
DateTime x = DateTime(data[di].year1, data[di].month1,
data[di].day1);
// Would do pre-increment of x here.
const DateTime& X = x;
x = x + Timespan(1,0,0,0,0);
DateTime y = x; const DateTime& Y = y;
loop_1_assert(line, data[di].year2 == X.year());
loop_1_assert(line, data[di].month2 == X.month());
loop_1_assert(line, data[di].day2 == X.day());
loop_1_assert(line, data[di].year2 == Y.year());
loop_1_assert(line, data[di].month2 == Y.month());
loop_1_assert(line, data[di].day2 == Y.day());
}
for (di = 0; di < num_data; ++di)
{
const int line = data[di].lineNum;
DateTime x = DateTime(data[di].year1, data[di].month1, data[di].day1);
DateTime x1 = DateTime(data[di].year1, data[di].month1, data[di].day1);
DateTime x2 = DateTime(data[di].year2, data[di].month2, data[di].day2);
DateTime y = x; const DateTime& Y = y;
// Would do post increment of x here.
const DateTime& X = x;
x = x + Timespan(1,0,0,0,0);
loop_1_assert(line, data[di].year2 == X.year());
loop_1_assert(line, data[di].month2 == X.month());
loop_1_assert(line, data[di].day2 == X.day());
loop_1_assert(line, data[di].year1 == Y.year());
loop_1_assert(line, data[di].month1 == Y.month());
loop_1_assert(line, data[di].day1 == Y.day());
}
for (di = 0; di < num_data; ++di)
{
const int line = data[di].lineNum;
DateTime x = DateTime(data[di].year2, data[di].month2, data[di].day2);
const DateTime& X = x;
x = x - Timespan(1,0,0,0,0);
DateTime y = x; DateTime Y = y;
loop_1_assert(line, data[di].year1 == X.year());
loop_1_assert(line, data[di].month1 == X.month());
loop_1_assert(line, data[di].day1 == X.day());
loop_1_assert(line, data[di].year1 == Y.year());
loop_1_assert(line, data[di].month1 == Y.month());
loop_1_assert(line, data[di].day1 == Y.day());
}
for (di = 0; di < num_data; ++di)
{
//.........这里部分代码省略.........
示例7: main
int main(int argc, char** argv)
{
// create a session
Session session("SQLite", "sample.db");
// drop sample table, if it exists
session << "DROP TABLE IF EXISTS Person", now;
// (re)create table
session << "CREATE TABLE Person (Name VARCHAR(30), Address VARCHAR, Age INTEGER(3), Birthday DATE)", now;
// insert some rows
Person person =
{
"Bart Simpson",
"Springfield",
10,
DateTime(1980, 4, 1)
};
Statement insert(session);
insert << "INSERT INTO Person VALUES(?, ?, ?, ?)",
use(person);
insert.execute();
person.name = "Lisa Simpson";
person.address = "Springfield";
person.age = 8;
person.birthday = DateTime(1982, 5, 9);
insert.execute();
// a simple query
Statement select(session);
select << "SELECT Name, Address, Age, Birthday FROM Person",
into(person),
range(0, 1); // iterate over result set one row at a time
while (!select.done())
{
select.execute();
std::cout << person.name << "\t"
<< person.address << "\t"
<< person.age << "\t"
<< DateTimeFormatter::format(person.birthday, "%b %d %Y")
<< std::endl;
}
// another query - store the result in a container
std::vector<Person> persons;
session << "SELECT Name, Address, Age, Birthday FROM Person",
into(persons),
now;
for (std::vector<Person>::const_iterator it = persons.begin(); it != persons.end(); ++it)
{
std::cout << it->name << "\t"
<< it->address << "\t"
<< it->age << "\t"
<< DateTimeFormatter::format(it->birthday, "%b %d %Y")
<< std::endl;
}
return 0;
}