gregorian.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_GREGORIAN_DATE_HPP_JOFA_080416
  9. #define BOOST_ICL_GREGORIAN_DATE_HPP_JOFA_080416
  10. #include <boost/icl/detail/boost_config.hpp>
  11. #include <boost/detail/workaround.hpp>
  12. #ifdef BOOST_MSVC
  13. #pragma warning(push)
  14. #pragma warning(disable:4100) // unreferenced formal parameter
  15. #pragma warning(disable:4127) // conditional expression is constant
  16. #pragma warning(disable:4244) // 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
  17. #pragma warning(disable:4702) // boost\lexical_cast.hpp(1159) : warning C4702: unreachable code
  18. #pragma warning(disable:4996) // Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
  19. #endif
  20. #include <stdio.h>
  21. #include <string>
  22. #include <sstream>
  23. #include <iostream>
  24. #include <boost/date_time/gregorian/gregorian.hpp>
  25. #ifdef BOOST_MSVC
  26. #pragma warning(pop)
  27. #endif
  28. #include <boost/icl/type_traits/identity_element.hpp>
  29. #include <boost/icl/type_traits/is_discrete.hpp>
  30. #include <boost/icl/type_traits/difference_type_of.hpp>
  31. #include <boost/icl/type_traits/size_type_of.hpp>
  32. namespace boost{namespace icl
  33. {
  34. template<> struct is_discrete<boost::gregorian::date>
  35. {
  36. typedef is_discrete type;
  37. BOOST_STATIC_CONSTANT(bool, value = true);
  38. };
  39. template<>
  40. inline boost::gregorian::date identity_element<boost::gregorian::date>::value()
  41. {
  42. return boost::gregorian::date(boost::gregorian::min_date_time);
  43. }
  44. template<>
  45. struct identity_element<boost::gregorian::date_duration>
  46. {
  47. static boost::gregorian::date_duration value()
  48. {
  49. return boost::gregorian::date(boost::gregorian::min_date_time)
  50. - boost::gregorian::date(boost::gregorian::min_date_time);
  51. }
  52. };
  53. template<>
  54. struct has_difference<boost::gregorian::date>
  55. {
  56. typedef has_difference type;
  57. BOOST_STATIC_CONSTANT(bool, value = true);
  58. };
  59. template<>
  60. struct difference_type_of<boost::gregorian::date>
  61. { typedef boost::gregorian::date_duration type; };
  62. template<>
  63. struct size_type_of<boost::gregorian::date>
  64. { typedef boost::gregorian::date_duration type; };
  65. // ------------------------------------------------------------------------
  66. inline boost::gregorian::date operator ++(boost::gregorian::date& x)
  67. {
  68. return x += boost::gregorian::date::duration_type::unit();
  69. }
  70. inline boost::gregorian::date operator --(boost::gregorian::date& x)
  71. {
  72. return x -= boost::gregorian::date::duration_type::unit();
  73. }
  74. // ------------------------------------------------------------------------
  75. template<> struct is_discrete<boost::gregorian::date_duration>
  76. {
  77. typedef is_discrete type;
  78. BOOST_STATIC_CONSTANT(bool, value = true);
  79. };
  80. template<>
  81. struct has_difference<boost::gregorian::date_duration>
  82. {
  83. typedef has_difference type;
  84. BOOST_STATIC_CONSTANT(bool, value = true);
  85. };
  86. template<>
  87. struct size_type_of<boost::gregorian::date_duration>
  88. {
  89. typedef boost::gregorian::date_duration type;
  90. };
  91. inline boost::gregorian::date_duration operator ++(boost::gregorian::date_duration& x)
  92. {
  93. return x += boost::gregorian::date::duration_type::unit();
  94. }
  95. inline boost::gregorian::date_duration operator --(boost::gregorian::date_duration& x)
  96. {
  97. return x -= boost::gregorian::date::duration_type::unit();
  98. }
  99. // ------------------------------------------------------------------------
  100. }} // namespace icl boost
  101. #endif