testdate_input_facet.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /* Copyright (c) 2005 CrystalClear Software, Inc.
  2. * Use, modification and distribution is subject to the
  3. * Boost Software License, Version 1.0. (See accompanying
  4. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  5. * Author: Jeff Garland, Bart Garst
  6. * $Date$
  7. */
  8. #include "boost/date_time/gregorian/gregorian.hpp"
  9. #include "../testfrmwk.hpp"
  10. #include <iostream>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. #ifndef USE_DATE_TIME_PRE_1_33_FACET_IO
  15. // for tests that are expected to fail and throw exceptions
  16. template<class temporal_type, class exception_type>
  17. bool failure_test(temporal_type component,
  18. const std::string& input,
  19. exception_type const& /*except*/,
  20. boost::gregorian::date_input_facet* facet)
  21. {
  22. using namespace boost::gregorian;
  23. bool result = false;
  24. std::istringstream iss(input);
  25. iss.exceptions(std::ios_base::failbit); // turn on exceptions
  26. iss.imbue(std::locale(std::locale::classic(), facet));
  27. try {
  28. iss >> component;
  29. }
  30. catch(exception_type& e) {
  31. std::cout << "Expected exception caught: \""
  32. << e.what() << "\"" << std::endl;
  33. result = iss.fail(); // failbit must be set to pass test
  34. }
  35. catch(...) {
  36. result = false;
  37. }
  38. return result;
  39. }
  40. // for tests that are expected to fail quietly
  41. template<class temporal_type>
  42. bool failure_test(temporal_type component,
  43. const std::string& input,
  44. boost::gregorian::date_input_facet* facet)
  45. {
  46. using namespace boost::gregorian;
  47. std::istringstream iss(input);
  48. /* leave exceptions turned off
  49. * iss.exceptions(std::ios_base::failbit); */
  50. iss.imbue(std::locale(std::locale::classic(), facet));
  51. try {
  52. iss >> component;
  53. }
  54. catch(...) {
  55. std::cout << "Caught unexpected exception" << std::endl;
  56. return false;
  57. }
  58. return iss.fail(); // failbit must be set to pass test
  59. }
  60. #endif
  61. int main(){
  62. #ifndef USE_DATE_TIME_PRE_1_33_FACET_IO
  63. using namespace boost::gregorian;
  64. {
  65. // verify no extra character are consumed
  66. greg_month m(1);
  67. std::stringstream ss("Mar.");
  68. std::istreambuf_iterator<char> sitr(ss), str_end;
  69. date_input_facet f;
  70. f.get(sitr, str_end, ss, m);
  71. check("No extra characters consumed", m == greg_month(Mar) && *sitr == '.');
  72. }
  73. // set up initial objects
  74. date d(not_a_date_time);
  75. days dd(not_a_date_time);
  76. greg_month m(1);
  77. greg_weekday gw(0);
  78. greg_day gd(1);
  79. greg_year gy(2000);
  80. // exceptions for failure_tests
  81. std::ios_base::failure e_failure("default");
  82. bad_month e_bad_month;
  83. bad_year e_bad_year;
  84. bad_day_of_month e_bad_day_of_month;
  85. bad_weekday e_bad_weekday;
  86. bad_day_of_year e_bad_day_of_year;
  87. // default format tests: date, days, month, weekday, day, year
  88. std::istringstream iss("2005-Jan-15 21 Feb Tue 4 2002");
  89. iss >> d;
  90. check_equal("Default format date", d, date(2005,Jan,15));
  91. iss >> dd;
  92. check_equal("Default (only) format positive days", dd, days(21));
  93. iss >> m;
  94. check_equal("Default format month", m, greg_month(2));
  95. iss >> gw;
  96. check_equal("Default format weekday", gw, greg_weekday(2));
  97. iss >> gd;
  98. check_equal("Default (only) format day of month", gd, greg_day(4));
  99. iss >> gy;
  100. check_equal("Default format year", gy, greg_year(2002));
  101. // failure tests
  102. check("Input Misspelled in year (date) w/exceptions",
  103. failure_test(d, "205-Jan-15", e_bad_year, new date_input_facet()));
  104. check("Input Misspelled in year (date) no-exceptions",
  105. failure_test(d, "205-Jan-15", new date_input_facet()));
  106. check("Input Misspelled in month (date) w/exceptions",
  107. failure_test(d, "2005-Jsn-15", e_bad_month, new date_input_facet()));
  108. check("Input Misspelled in month (date) no-exceptions",
  109. failure_test(d, "2005-Jsn-15", new date_input_facet()));
  110. check("Input Misspelled in day (date) w/exceptions",
  111. failure_test(d, "2005-Jan-51", e_bad_day_of_month, new date_input_facet()));
  112. check("Input Misspelled in day (date) no-exceptions",
  113. failure_test(d, "2005-Jan-51", new date_input_facet()));
  114. check("Input Misspelled greg_weekday w/exceptions",
  115. failure_test(gw, "San", e_bad_weekday, new date_input_facet()));
  116. check("Input Misspelled greg_weekday no-exceptions",
  117. failure_test(gw, "San", new date_input_facet()));
  118. check("Input Misspelled month w/exceptions",
  119. failure_test(m, "Jsn", e_bad_month, new date_input_facet()));
  120. check("Input Misspelled month no-exceptions",
  121. failure_test(m, "Jsn", new date_input_facet()));
  122. check("Bad Input greg_day w/exceptions",
  123. failure_test(gd, "Sun", e_bad_day_of_month, new date_input_facet()));
  124. check("Bad Input greg_day no-exceptions",
  125. failure_test(gd, "Sun", new date_input_facet()));
  126. check("Input Misspelled greg_year w/exceptions",
  127. failure_test(gy, "205", e_bad_year, new date_input_facet()));
  128. check("Input Misspelled greg_year no-exceptions",
  129. failure_test(gy, "205", new date_input_facet()));
  130. // change to full length names, iso date format, and 2 digit year
  131. date_input_facet* facet = new date_input_facet();
  132. facet->set_iso_format();
  133. facet->month_format("%B");
  134. facet->weekday_format("%A");
  135. facet->year_format("%y");
  136. iss.str("20050115 -55 February Tuesday 02");
  137. iss.imbue(std::locale(std::locale::classic(), facet));
  138. iss >> d;
  139. check_equal("ISO format date", d, date(2005,Jan,15));
  140. iss >> dd;
  141. check_equal("Default (only) format negative days", dd, days(-55));
  142. iss >> m;
  143. check_equal("Full format month", m, greg_month(2));
  144. iss >> gw;
  145. check_equal("Full format weekday", gw, greg_weekday(2));
  146. iss >> gy;
  147. check_equal("2 digit format year", gy, greg_year(2002));
  148. date_input_facet* f1 = new date_input_facet();
  149. date_input_facet* f2 = new date_input_facet();
  150. f1->set_iso_format();
  151. f2->set_iso_format();
  152. check("Missing digit(s) in ISO string", failure_test(d,"2005071", f1));
  153. check("Missing digit(s) in ISO string",
  154. failure_test(d,"2005071", e_bad_day_of_month, f2));
  155. { // literal % in format tests
  156. date dx(not_a_date_time);
  157. greg_month mx(1);
  158. greg_weekday gwx(0);
  159. greg_year y(1400);
  160. date_input_facet* f = new date_input_facet("%%d %Y-%b-%d");
  161. std::stringstream ss;
  162. ss.imbue(std::locale(ss.getloc(), f));
  163. ss.str("%d 2005-Jun-14");
  164. ss >> dx;
  165. check_equal("Literal '%' in date format", dx, date(2005,Jun,14));
  166. f->format("%%%d %Y-%b-%d");
  167. ss.str("%14 2005-Jun-14");
  168. ss >> dx;
  169. check_equal("Multiple literal '%'s in date format", dx, date(2005,Jun,14));
  170. f->month_format("%%b %b");
  171. ss.str("%b Jun");
  172. ss >> mx;
  173. check_equal("Literal '%' in month format", mx, greg_month(6));
  174. f->month_format("%%%b");
  175. ss.str("%Jun");
  176. ss >> mx;
  177. check_equal("Multiple literal '%'s in month format", mx, greg_month(6));
  178. f->weekday_format("%%a %a");
  179. ss.str("%a Tue");
  180. ss >> gwx;
  181. check_equal("Literal '%' in weekday format", gwx, greg_weekday(2));
  182. f->weekday_format("%%%a");
  183. ss.str("%Tue");
  184. ss >> gwx;
  185. check_equal("Multiple literal '%'s in weekday format", gwx, greg_weekday(2));
  186. f->year_format("%%Y %Y");
  187. ss.str("%Y 2005");
  188. ss >> y;
  189. check_equal("Literal '%' in year format", y, greg_year(2005));
  190. f->year_format("%%%Y");
  191. ss.str("%2005");
  192. ss >> y;
  193. check_equal("Multiple literal '%'s in year format", y, greg_year(2005));
  194. f->year_format("%Y%");
  195. ss.str("2005%");
  196. ss >> y;
  197. check_equal("Trailing'%'s in year format", y, greg_year(2005));
  198. }
  199. // All days, month, weekday, day, and year formats have been tested
  200. // begin testing other date formats
  201. facet->set_iso_extended_format();
  202. iss.str("2005-01-15");
  203. iss >> d;
  204. check_equal("ISO Extended format date", d, date(2005,Jan,15));
  205. facet->format("%B %d, %Y");
  206. iss.str("March 15, 2006");
  207. iss >> d;
  208. check_equal("Custom date format: \"%B %d, %Y\" => 'March 15, 2006'",
  209. d, date(2006,Mar,15));
  210. facet->format("%Y-%j"); // Ordinal format ISO8601(2000 sect 5.2.2.1 extended)
  211. iss.str("2006-074");
  212. iss >> d;
  213. check_equal("Custom date format: \"%Y-%j\" => '2006-074'",
  214. d, date(2006,Mar,15));
  215. check("Bad input Custom date format: \"%Y-%j\" => '2006-74' (w/exceptions)",
  216. failure_test(d, "2006-74", e_bad_day_of_year, facet));
  217. check("Bad input Custom date format: \"%Y-%j\" => '2006-74' (no exceptions)",
  218. failure_test(d, "2006-74", facet));
  219. // date_period tests
  220. // A date_period is constructed with an open range. So the periods
  221. // [2000-07--04/2000-07-25) <-- open range
  222. // And
  223. // [2000-07--04/2000-07-24] <-- closed range
  224. // Are equal
  225. date begin(2002, Jul, 4);
  226. days len(21);
  227. date_period dp(date(2000,Jan,1), days(1));
  228. iss.str("[2002-07-04/2002-07-24]");
  229. facet->set_iso_extended_format();
  230. iss >> dp;
  231. check_equal("Default period (closed range)", dp, date_period(begin,len));
  232. {
  233. std::stringstream ss;
  234. date dx(not_a_date_time);
  235. date d2 = day_clock::local_day();
  236. date d3(neg_infin);
  237. date d4(pos_infin);
  238. date_period dpx(d2, dx); // date/nadt
  239. date_period dp2(dx, dx); // nadt/nadt
  240. date_period dp3(d3, d4);
  241. ss << dpx;
  242. ss >> dp2;
  243. check_equal("Special values period (reversibility test)", dpx, dp2);
  244. ss.str("[-infinity/+infinity]");
  245. ss >> dp2;
  246. check_equal("Special values period (infinities)", dp3, dp2);
  247. }
  248. // open range
  249. period_parser pp(period_parser::AS_OPEN_RANGE);
  250. iss.str("[2002-07-04/2002-07-25)");
  251. facet->period_parser(pp);
  252. iss >> dp;
  253. check_equal("Open range period", dp, date_period(begin,len));
  254. // custom period delimiters
  255. pp.delimiter_strings(" to ", "from ", " exclusive", " inclusive");
  256. iss.str("from 2002-07-04 to 2002-07-25 exclusive");
  257. facet->period_parser(pp);
  258. iss >> dp;
  259. check_equal("Open range period - custom delimiters", dp, date_period(begin,len));
  260. pp.range_option(period_parser::AS_CLOSED_RANGE);
  261. iss.str("from 2002-07-04 to 2002-07-24 inclusive");
  262. facet->period_parser(pp);
  263. iss >> dp;
  264. check_equal("Closed range period - custom delimiters", dp, date_period(begin,len));
  265. // date_generator tests
  266. // date_generators use formats contained in the
  267. // date_input_facet for weekdays and months
  268. // reset month & weekday formats to defaults
  269. facet->month_format("%b");
  270. facet->weekday_format("%a");
  271. partial_date pd(1,Jan);
  272. nth_kday_of_month nkd(nth_kday_of_month::first, Sunday, Jan);
  273. first_kday_of_month fkd(Sunday, Jan);
  274. last_kday_of_month lkd(Sunday, Jan);
  275. first_kday_before fkb(Sunday);
  276. first_kday_after fka(Sunday);
  277. // using default date_generator_parser "nth_strings"
  278. iss.str("29 Feb");
  279. iss >> pd;
  280. // Feb-29 is a valid date_generator, get_date() will fail in a non-leap year
  281. check_equal("Default strings, partial_date",
  282. pd.get_date(2004), date(2004,Feb,29));
  283. iss.str("second Mon of Mar");
  284. iss >> nkd;
  285. check_equal("Default strings, nth_day_of_the_week_in_month",
  286. nkd.get_date(2004), date(2004,Mar,8));
  287. iss.str("first Tue of Apr");
  288. iss >> fkd;
  289. check_equal("Default strings, first_day_of_the_week_in_month",
  290. fkd.get_date(2004), date(2004,Apr,6));
  291. iss.str("last Wed of May");
  292. iss >> lkd;
  293. check_equal("Default strings, last_day_of_the_week_in_month",
  294. lkd.get_date(2004), date(2004,May,26));
  295. iss.str("Thu before");
  296. iss >> fkb;
  297. check_equal("Default strings, first_day_of_the_week_before",
  298. fkb.get_date(date(2004,Feb,8)), date(2004,Feb,5));
  299. iss.str("Fri after");
  300. iss >> fka;
  301. check_equal("Default strings, first_day_of_the_week_after",
  302. fka.get_date(date(2004,Feb,1)), date(2004,Feb,6));
  303. // failure tests
  304. check("Incorrect elements (date_generator) w/exceptions", // after/before type mixup
  305. failure_test(fkb, "Fri after", e_failure, new date_input_facet()));
  306. check("Incorrect elements (date_generator) no exceptions", // after/before type mixup
  307. failure_test(fkb, "Fri after", new date_input_facet()));
  308. check("Incorrect elements (date_generator) w/exceptions", // first/last type mixup
  309. failure_test(lkd, "first Tue of Apr", e_failure, new date_input_facet()));
  310. check("Incorrect elements (date_generator) no exceptions", // first/last type mixup
  311. failure_test(lkd, "first Tue of Apr", new date_input_facet()));
  312. check("Incorrect elements (date_generator) w/exceptions", // 'in' is wrong
  313. failure_test(nkd, "second Mon in Mar", e_failure, new date_input_facet()));
  314. check("Incorrect elements (date_generator) no exceptions", // 'in' is wrong
  315. failure_test(nkd, "second Mon in Mar", new date_input_facet()));
  316. // date_generators - custom element strings
  317. facet->date_gen_element_strings("1st","2nd","3rd","4th","5th","final","prior to","past","in");
  318. iss.str("3rd Sat in Jul");
  319. iss >> nkd;
  320. check_equal("Custom strings, nth_day_of_the_week_in_month",
  321. nkd.get_date(2004), date(2004,Jul,17));
  322. iss.str("1st Wed in May");
  323. iss >> fkd;
  324. check_equal("Custom strings, first_day_of_the_week_in_month",
  325. fkd.get_date(2004), date(2004,May,5));
  326. iss.str("final Tue in Apr");
  327. iss >> lkd;
  328. check_equal("Custom strings, last_day_of_the_week_in_month",
  329. lkd.get_date(2004), date(2004,Apr,27));
  330. iss.str("Fri prior to");
  331. iss >> fkb;
  332. check_equal("Custom strings, first_day_of_the_week_before",
  333. fkb.get_date(date(2004,Feb,8)), date(2004,Feb,6));
  334. iss.str("Thu past");
  335. iss >> fka;
  336. check_equal("Custom strings, first_day_of_the_week_after",
  337. fka.get_date(date(2004,Feb,1)), date(2004,Feb,5));
  338. // date_generators - special case with empty element string
  339. /* Doesn't work. Empty string returns -1 from string_parse_tree
  340. * because it attempts to match the next set of characters in the
  341. * stream to the wrong element. Ex. It attempts to match "Mar" to
  342. * the 'of' element in the test below.
  343. *
  344. facet->date_gen_element_strings("1st","2nd","3rd","4th","5th","final","prior to","past",""); // the 'of' string is an empty string
  345. iss.str("final Mon Mar");
  346. iss >> lkd;
  347. check_equal("Special case, empty element string",
  348. lkd.get_date(2005), date(2005,Mar,28));
  349. */
  350. // special values tests (date and days only)
  351. iss.str("minimum-date-time +infinity");
  352. iss >> d;
  353. iss >> dd;
  354. check_equal("Special values, default strings, min_date_time date",
  355. d, date(min_date_time));
  356. check_equal("Special values, default strings, pos_infin days",
  357. dd, days(pos_infin));
  358. iss.str("-infinity maximum-date-time");
  359. iss >> d;
  360. iss >> dd;
  361. check_equal("Special values, default strings, neg_infin date",
  362. d, date(neg_infin));
  363. check_equal("Special values, default strings, max_date_time days",
  364. dd, days(max_date_time));
  365. iss.str("not-a-date-time");
  366. iss >> d;
  367. check_equal("Special values, default strings, not_a_date_time date",
  368. d, date(not_a_date_time));
  369. // in addition check that special_value_from_string also works correctly for other special values
  370. check_equal("Special values, default strings, not_special test",
  371. special_value_from_string("not_special"), not_special);
  372. check_equal("Special values, default strings, junk test",
  373. special_value_from_string("junk"), not_special);
  374. // special values custom, strings
  375. special_values_parser svp("NADT", "MINF", "INF", "MINDT", "MAXDT");
  376. facet->special_values_parser(svp);
  377. iss.str("MINDT INF");
  378. iss >> d;
  379. iss >> dd;
  380. check_equal("Special values, custom strings, min_date_time date",
  381. d, date(min_date_time));
  382. check_equal("Special values, custom strings, pos_infin days",
  383. dd, days(pos_infin));
  384. iss.str("MINF MAXDT");
  385. iss >> d;
  386. iss >> dd;
  387. check_equal("Special values, custom strings, neg_infin date",
  388. d, date(neg_infin));
  389. check_equal("Special values, custom strings, max_date_time days",
  390. dd, days(max_date_time));
  391. iss.str("NADT");
  392. iss >> dd;
  393. check_equal("Special values, custom strings, not_a_date_time days",
  394. dd, days(not_a_date_time));
  395. // failure test
  396. check("Misspelled input, special_value date w/exceptions",
  397. failure_test(d, "NSDT", e_bad_year, new date_input_facet()));
  398. check("Misspelled input, special_value date no exceptions",
  399. failure_test(d, "NSDT", new date_input_facet()));
  400. check("Misspelled input, special_value days w/exceptions",
  401. failure_test(dd, "NSDT", e_failure, new date_input_facet()));
  402. check("Misspelled input, special_value days no exceptions",
  403. failure_test(dd, "NSDT", new date_input_facet()));
  404. {
  405. // German names. Please excuse any errors, I don't speak German and
  406. // had to rely on an on-line translation service.
  407. // These tests check one of each (at least) from all sets of custom strings
  408. // create a custom format_date_parser
  409. std::string m_a[] = {"Jan","Feb","Mar","Apr","Mai",
  410. "Jun","Jul","Aug","Sep","Okt","Nov","Dez"};
  411. std::string m_f[] = {"Januar","Februar","Marz","April",
  412. "Mai","Juni","Juli","August",
  413. "September","Oktober","November","Dezember"};
  414. std::string w_a[] = {"Son", "Mon", "Die","Mit", "Don", "Fre", "Sam"};
  415. std::string w_f[] = {"Sonntag", "Montag", "Dienstag","Mittwoch",
  416. "Donnerstag", "Freitag", "Samstag"};
  417. typedef boost::date_time::format_date_parser<date, char> date_parser;
  418. date_parser::input_collection_type months_abbrev;
  419. date_parser::input_collection_type months_full;
  420. date_parser::input_collection_type wkdays_abbrev;
  421. date_parser::input_collection_type wkdays_full;
  422. months_abbrev.assign(m_a, m_a+12);
  423. months_full.assign(m_f, m_f+12);
  424. wkdays_abbrev.assign(w_a, w_a+7);
  425. wkdays_full.assign(w_f, w_f+7);
  426. date_parser d_parser("%B %d %Y",
  427. months_abbrev, months_full,
  428. wkdays_abbrev, wkdays_full);
  429. // create a special_values parser
  430. special_values_parser sv_parser("NichtDatumzeit",
  431. "Negativ Unendlichkeit",
  432. "Positiv Unendlichkeit",
  433. "Wenigstes Datum",
  434. "Maximales Datum");
  435. // create a period_parser
  436. period_parser p_parser; // default will do
  437. // create date_generator_parser
  438. typedef boost::date_time::date_generator_parser<date,char> date_gen_parser;
  439. date_gen_parser dg_parser("Zuerst","Zweitens","Dritt","Viert",
  440. "F\xC3\xBCnft","Letzt","Vor","Nach","Von");
  441. // create the date_input_facet
  442. date_input_facet* de_facet =
  443. new date_input_facet("%B %d %Y",
  444. d_parser,
  445. sv_parser,
  446. p_parser,
  447. dg_parser);
  448. std::istringstream iss2;
  449. iss2.imbue(std::locale(std::locale::classic(), de_facet));
  450. // June 06 2005, Dec, minimum date, Tues
  451. iss2.str("Juni 06 2005 Dez Wenigstes Datum Die");
  452. iss2 >> d;
  453. iss2 >> m;
  454. check_equal("German names: date", d, date(2005, Jun, 6));
  455. check_equal("German names: month", m, greg_month(Dec));
  456. iss2 >> d;
  457. iss2 >> gw;
  458. check_equal("German names: special value date", d, date(min_date_time));
  459. check_equal("German names: short weekday", gw, greg_weekday(Tuesday));
  460. de_facet->weekday_format("%A"); // long weekday
  461. // Tuesday, Second Tuesday of Mar
  462. iss2.str("Dienstag Zweitens Dienstag von Mar");
  463. iss2 >> gw;
  464. iss2 >> nkd;
  465. check_equal("German names: long weekday", gw, greg_weekday(Tuesday));
  466. check_equal("German names, nth_day_of_the_week_in_month",
  467. nkd.get_date(2005), date(2005,Mar,8));
  468. // Tuesday after
  469. iss2.str("Dienstag Nach");
  470. iss2 >> fka;
  471. check_equal("German names, first_day_of_the_week_after",
  472. fka.get_date(date(2005,Apr,5)), date(2005,Apr,12));
  473. }
  474. {
  475. // test name replacement functions
  476. // collections for adding to facet
  477. const char* const month_short_names[]={"*jan*","*feb*","*mar*",
  478. "*apr*","*may*","*jun*",
  479. "*jul*","*aug*","*sep*",
  480. "*oct*","*nov*","*dec*"};
  481. const char* const month_long_names[]={"**January**","**February**","**March**",
  482. "**April**","**May**","**June**",
  483. "**July**","**August**","**September**",
  484. "**October**","**November**","**December**"};
  485. const char* const weekday_short_names[]={"day1", "day2","day3","day4",
  486. "day5","day6","day7"};
  487. const char* const weekday_long_names[]= {"Sun-0", "Mon-1", "Tue-2",
  488. "Wed-3", "Thu-4",
  489. "Fri-5", "Sat-6"};
  490. std::vector<std::basic_string<char> > short_weekday_names;
  491. std::vector<std::basic_string<char> > long_weekday_names;
  492. std::vector<std::basic_string<char> > short_month_names;
  493. std::vector<std::basic_string<char> > long_month_names;
  494. std::copy(&weekday_short_names[0],
  495. &weekday_short_names[7],
  496. std::back_inserter(short_weekday_names));
  497. std::copy(&weekday_long_names[0],
  498. &weekday_long_names[7],
  499. std::back_inserter(long_weekday_names));
  500. std::copy(&month_short_names[0],
  501. &month_short_names[12],
  502. std::back_inserter(short_month_names));
  503. std::copy(&month_long_names[0],
  504. &month_long_names[12],
  505. std::back_inserter(long_month_names));
  506. date dx(not_a_date_time);
  507. date_input_facet* facetx = new date_input_facet();
  508. std::stringstream ss;
  509. ss.imbue(std::locale(std::locale::classic(), facetx));
  510. facetx->short_month_names(short_month_names);
  511. facetx->short_weekday_names(short_weekday_names);
  512. facetx->long_month_names(long_month_names);
  513. facetx->long_weekday_names(long_weekday_names);
  514. facetx->format("%a %b %d, %Y");
  515. ss.str("day7 *apr* 23, 2005");
  516. ss >> dx;
  517. check_equal("Short custom names, set via accessor function", dx.day_of_week(), greg_weekday(6));
  518. check_equal("Short custom names, set via accessor function", dx.month(), greg_month(4));
  519. ss.str("");
  520. ss.str("Sun-0 **April** 24, 2005");
  521. facetx->format("%A %B %d, %Y");
  522. ss >> dx;
  523. check_equal("Long custom names, set via accessor function", dx.day_of_week(), greg_weekday(0));
  524. check_equal("Long custom names, set via accessor function", dx.month(), greg_month(4));
  525. }
  526. #else
  527. check("This test is a nop for platforms with USE_DATE_TIME_PRE_1_33_FACET_IO",
  528. true);
  529. #endif
  530. return printTestStats();
  531. }