test_icu_vs_os_timezone.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOST_LOCALE_WITH_ICU
  9. #include <iostream>
  10. int main()
  11. {
  12. std::cout << "ICU is not build... Skipping" << std::endl;
  13. }
  14. #else
  15. #ifdef _MSC_VER
  16. #define _CRT_SECURE_NO_WARNINGS
  17. // Disable this "security crap"
  18. #endif
  19. #include <boost/locale/formatting.hpp>
  20. #include <boost/locale/format.hpp>
  21. #include <boost/locale/generator.hpp>
  22. #include "test_locale.hpp"
  23. #include "test_locale_tools.hpp"
  24. #include <sstream>
  25. #include <iostream>
  26. #include <iomanip>
  27. #include <time.h>
  28. int main()
  29. {
  30. try {
  31. time_t now=time(0);
  32. boost::locale::generator gen;
  33. std::locale::global(gen("en_US.UTF-8"));
  34. for(int i=0;i<366;i++) {
  35. time_t point = now + i * 24 * 3600;
  36. std::stringstream ss;
  37. ss << boost::locale::format("{1,ftime='%H %M %S'}") % point;
  38. int icu_hour = 0,icu_min = 0,icu_sec = 0;
  39. ss >> icu_hour >> icu_min >> icu_sec;
  40. std::tm *tm=localtime(&point);
  41. TEST(icu_hour == tm->tm_hour);
  42. TEST(icu_min == tm->tm_min);
  43. TEST(icu_sec == tm->tm_sec);
  44. }
  45. }
  46. catch(std::exception const &e) {
  47. std::cerr << "Failed " << e.what() << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. FINALIZE();
  51. }
  52. #endif // NO ICU
  53. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  54. // boostinspect:noascii