testformatters.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright (c) 2002,2003 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. */
  7. #include "boost/date_time/gregorian/gregorian.hpp"
  8. #include "../testfrmwk.hpp"
  9. int
  10. main()
  11. {
  12. boost::gregorian::date d1(2002,01,02);
  13. std::string ds1 = boost::gregorian::to_simple_string(d1);
  14. check("check string: " + ds1, ds1 == "2002-Jan-02");
  15. std::string ids1(boost::gregorian::to_iso_string(d1));
  16. // std::cout << boost::gregorian::to_iso_string(d1) << std::endl;
  17. check("check iso normal: " + ids1, ids1 == "20020102");
  18. std::string sds1 = boost::gregorian::to_sql_string(d1);
  19. check("check sql string: "+sds1, sds1 == "2002-01-02");
  20. boost::gregorian::date d2(2001,12,30);
  21. std::string ds2 = boost::gregorian::to_simple_string(d2);
  22. check("check string: "+ds2, ds2 == "2001-Dec-30");
  23. std::string ids2 = boost::gregorian::to_iso_extended_string(d2);
  24. check("check iso extended string: "+ids2, ids2 == "2001-12-30");
  25. using namespace boost::gregorian;
  26. date d3(neg_infin);
  27. std::cout << "|" << to_simple_string(d3) << "|" << std::endl;
  28. check("check negative infinity",
  29. (to_simple_string(d3) == std::string("-infinity")));
  30. date d4(pos_infin);
  31. check("check positive infinity",
  32. (to_simple_string(d4) == std::string("+infinity")));
  33. date d5(not_a_date_time);
  34. std::cout << to_simple_string(d5) << "|" << std::endl;
  35. check("check not a date",
  36. (to_simple_string(d5) == std::string("not-a-date-time")));
  37. date_period p1(date(2000,Jan,1), date(2001,Jan,1));
  38. check("check period format",
  39. (to_simple_string(p1) == std::string("[2000-Jan-01/2000-Dec-31]")));
  40. date_period p2(date(2000,Jan,1), date(pos_infin));
  41. check("check period format",
  42. (to_simple_string(p2) == std::string("[2000-Jan-01/+infinity]")));
  43. std::cout << to_simple_string(p2) << std::endl;
  44. // TODO enhance wchar support
  45. // std::wstringstream wss;
  46. // wss << d3 << std::endl;
  47. // std::wcout << d3;
  48. return printTestStats();
  49. }