date_duration_operators.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #ifndef LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___
  2. #define LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___
  3. /* Copyright (c) 2004 CrystalClear Software, Inc.
  4. * Subject to the Boost Software License, Version 1.0.
  5. * (See accompanying file LICENSE_1_0.txt or
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland, Bart Garst
  8. * $Date$
  9. */
  10. #include "boost/date_time/gregorian/greg_duration_types.hpp"
  11. #include "boost/date_time/local_time/local_date_time.hpp"
  12. namespace boost {
  13. namespace local_time {
  14. /*!@file date_duration_operators.hpp Operators for local_date_time and
  15. * optional gregorian types. Operators use snap-to-end-of-month behavior.
  16. * Further details on this behavior can be found in reference for
  17. * date_time/date_duration_types.hpp and documentation for
  18. * month and year iterators.
  19. */
  20. /*! Adds a months object and a local_date_time. Result will be same
  21. * day-of-month as local_date_time unless original day was the last day of month.
  22. * see date_time::months_duration for more details */
  23. inline
  24. local_date_time
  25. operator+(const local_date_time& t, const boost::gregorian::months& m)
  26. {
  27. return t + m.get_offset(t.utc_time().date());
  28. }
  29. /*! Adds a months object to a local_date_time. Result will be same
  30. * day-of-month as local_date_time unless original day was the last day of month.
  31. * see date_time::months_duration for more details */
  32. inline
  33. local_date_time
  34. operator+=(local_date_time& t, const boost::gregorian::months& m)
  35. {
  36. return t += m.get_offset(t.utc_time().date());
  37. }
  38. /*! Subtracts a months object and a local_date_time. Result will be same
  39. * day-of-month as local_date_time unless original day was the last day of month.
  40. * see date_time::months_duration for more details */
  41. inline
  42. local_date_time
  43. operator-(const local_date_time& t, const boost::gregorian::months& m)
  44. {
  45. // get_neg_offset returns a negative duration, so we add
  46. return t + m.get_neg_offset(t.utc_time().date());
  47. }
  48. /*! Subtracts a months object from a local_date_time. Result will be same
  49. * day-of-month as local_date_time unless original day was the last day of month.
  50. * see date_time::months_duration for more details */
  51. inline
  52. local_date_time
  53. operator-=(local_date_time& t, const boost::gregorian::months& m)
  54. {
  55. // get_neg_offset returns a negative duration, so we add
  56. return t += m.get_neg_offset(t.utc_time().date());
  57. }
  58. // local_date_time & years
  59. /*! Adds a years object and a local_date_time. Result will be same
  60. * month and day-of-month as local_date_time unless original day was the
  61. * last day of month. see date_time::years_duration for more details */
  62. inline
  63. local_date_time
  64. operator+(const local_date_time& t, const boost::gregorian::years& y)
  65. {
  66. return t + y.get_offset(t.utc_time().date());
  67. }
  68. /*! Adds a years object to a local_date_time. Result will be same
  69. * month and day-of-month as local_date_time unless original day was the
  70. * last day of month. see date_time::years_duration for more details */
  71. inline
  72. local_date_time
  73. operator+=(local_date_time& t, const boost::gregorian::years& y)
  74. {
  75. return t += y.get_offset(t.utc_time().date());
  76. }
  77. /*! Subtracts a years object and a local_date_time. Result will be same
  78. * month and day-of-month as local_date_time unless original day was the
  79. * last day of month. see date_time::years_duration for more details */
  80. inline
  81. local_date_time
  82. operator-(const local_date_time& t, const boost::gregorian::years& y)
  83. {
  84. // get_neg_offset returns a negative duration, so we add
  85. return t + y.get_neg_offset(t.utc_time().date());
  86. }
  87. /*! Subtracts a years object from a local_date_time. Result will be same
  88. * month and day-of-month as local_date_time unless original day was the
  89. * last day of month. see date_time::years_duration for more details */
  90. inline
  91. local_date_time
  92. operator-=(local_date_time& t, const boost::gregorian::years& y)
  93. {
  94. // get_neg_offset returns a negative duration, so we add
  95. return t += y.get_neg_offset(t.utc_time().date());
  96. }
  97. }} // namespaces
  98. #endif // LOCAL_TIME_DATE_DURATION_OPERATORS_HPP___