📄 testtime_facet.cpp
字号:
//std::wstring(L"[Wed Oct 13 18:01:56 2004/Wed Oct 20 19:02:57 2004]"),
std::wstring(L"[10/13/04 18:01:56/10/20/04 19:02:57]"),
std::locale(std::locale::classic(), timefacet));
}
{
wtime_facet *timefacet = new wtime_facet(L"%Y-%b-%d %I:%M:%S %p");
teststreaming("widestream time in 12 hours format w/ (AM/PM)", tp.begin(),
std::wstring(L"2004-Oct-13 06:01:56 PM"),
std::locale(std::locale::classic(), timefacet));
}
{
wtime_facet *timefacet = new wtime_facet(wtime_facet::standard_format);
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream time duration", td,
std::wstring(L"03:02:01.009000000"),
std::locale(std::locale::classic(), timefacet));
#else
teststreaming("widestream time duration", td,
std::wstring(L"03:02:01.009000"),
std::locale(std::locale::classic(), timefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream time duration", td,
std::wstring(L"03:02:01.009000000"));
#else
teststreaming("widestream time duration", td,
std::wstring(L"03:02:01.009000"));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
//wtime_facet *timefacet = new wtime_facet();
//std::locale cloc = std::locale(std::locale::classic(), timefacet);
//ss.imbue(cloc);
// ss << L"classic date: " << d << std::endl;
// ss << L"classic dateperiod: " << dp << std::endl;
//ss << L"classic time: " << t << std::endl;
//ss << L"classic timefrac: " << tf << std::endl;
//ss << L"classic timeperiod: " << tp << std::endl;
{
wtime_facet* wtimefacet = new wtime_facet(L"day: %j date: %Y-%b-%d weekday: %A time: %H:%M:%s");
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time facet narly format", t,
std::wstring(L"day: 287 date: 2004-Oct-13 weekday: Wednesday time: 18:01:56.000000000"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time facet narly format", t,
std::wstring(L"day: 287 date: 2004-Oct-13 weekday: Wednesday time: 18:01:56.000000"),
std::locale(std::locale::classic(), wtimefacet));
#endif
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S,%f");
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time fractional seconds: %Y-%b-%d %H:%M:%S,%f", t,
std::wstring(L"2004-Oct-13 18:01:56,000000000"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time fractional seconds: %Y-%b-%d %H:%M:%S,%f", t,
std::wstring(L"2004-Oct-13 18:01:56,000000"),
std::locale(std::locale::classic(), wtimefacet));
#endif
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S");
teststreaming("widestream custom time no frac seconds: %Y-%b-%d %H:%M:%S", t,
std::wstring(L"2004-Oct-13 18:01:56"),
std::locale(std::locale::classic(), wtimefacet));
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S");
wtimefacet->short_month_names(de_short_month_names);
teststreaming("widestream custom time no frac seconds, german months: %Y-%b-%d %H:%M:%S", t,
std::wstring(L"2004-Okt-13 18:01:56"),
std::locale(std::locale::classic(), wtimefacet));
}
{
wtime_facet* wtimefacet = new wtime_facet();
wtimefacet->format(L"%B %b %Y");
wtimefacet->short_month_names(de_short_month_names);
wtimefacet->long_month_names(de_long_month_names);
teststreaming("widestream custom time no frac seconds, german months: %B %b %Y", t,
std::wstring(L"Oktober Okt 2004"),
std::locale(std::locale::classic(), wtimefacet));
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S%F");
teststreaming("widestream custom time no frac seconds %F operator: %Y-%b-%d %H:%M:%S%F", t,
std::wstring(L"2004-Oct-13 18:01:56"),
std::locale(std::locale::classic(), wtimefacet));
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S%F");
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time with frac seconds %F operator: %Y-%b-%d %H:%M:%S%F", tf,
std::wstring(L"2004-Oct-13 18:01:56.000003000"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time with frac seconds %F operator: %Y-%b-%d %H:%M:%S%F", tf,
std::wstring(L"2004-Oct-13 18:01:56.000003"),
std::locale(std::locale::classic(), wtimefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
{
wtime_facet* wtimefacet = new wtime_facet();
wtimefacet->set_iso_format();
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time iso format", tf,
std::wstring(L"20041013T180156.000003000"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time iso format", tf,
std::wstring(L"20041013T180156.000003"),
std::locale(std::locale::classic(), wtimefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
{
wtime_facet* wtimefacet = new wtime_facet();
wtimefacet->set_iso_extended_format();
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time iso extended format", tf,
std::wstring(L"2004-10-13 18:01:56.000003000"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time iso extended format", tf,
std::wstring(L"2004-10-13 18:01:56.000003"),
std::locale(std::locale::classic(), wtimefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%S%F");
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream time period frac seconds %F operator: %Y-%b-%d %H:%M:%S%F", tp,
std::wstring(L"[2004-Oct-13 18:01:56/2004-Oct-20 19:02:57.000002999]"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream time period frac seconds %F operator: %Y-%b-%d %H:%M:%S%F", tp,
std::wstring(L"[2004-Oct-13 18:01:56/2004-Oct-20 19:02:57.000002]"),
std::locale(std::locale::classic(), wtimefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
{
wtime_facet* wtimefacet = new wtime_facet(L"%Y-%b-%d %H:%M:%s");
wperiod_formatter pf(wperiod_formatter::AS_OPEN_RANGE, L" / ", L"[ ", L" )", L" ]");
wtimefacet->period_formatter(pf);
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
teststreaming("widestream custom time : %Y-%b-%d %H:%M:%s", tp,
std::wstring(L"[ 2004-Oct-13 18:01:56.000000000 / 2004-Oct-20 19:02:57.000003000 )"),
std::locale(std::locale::classic(), wtimefacet));
#else
teststreaming("widestream custom time : %Y-%b-%d %H:%M:%s", tp,
std::wstring(L"[ 2004-Oct-13 18:01:56.000000 / 2004-Oct-20 19:02:57.000003 )"),
std::locale(std::locale::classic(), wtimefacet));
#endif // BOOST_DATE_TIME_HAS_NANOSECONDS
}
{
ptime nt(not_a_date_time);
teststreaming("widestream custom time : not a datetime", nt,
std::wstring(L"not-a-date-time"));
}
// //Denmark English has iso extended default format...
// std::locale gloc("en_DK");
// ss.imbue(gloc);
// ss << L"default english-denmark date: " << d << std::endl;
// ss << L"default english-denmark dateperiod: " << dp << std::endl;
// ss << L"default english-denmark time: " << t << std::endl;
// ss << L"default english-denmark timefrac: " << tf << std::endl;
// ss << L"default english-denmark timeperiod: " << tp << std::endl;
#endif
}
catch(std::exception& e) {
std::cout << "Caught std::exception: " << e.what() << std::endl;
}
catch(...) {
std::cout << "bad exception" << std::endl;
}
return printTestStats();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -