gregorian_calendar.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #ifndef DATE_TIME_GREGORIAN_CALENDAR_HPP__
  2. #define DATE_TIME_GREGORIAN_CALENDAR_HPP__
  3. /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
  4. * Use, modification and distribution is subject to the
  5. * Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  7. * Author: Jeff Garland
  8. * $Date$
  9. */
  10. #include <boost/date_time/compiler_config.hpp>
  11. namespace boost {
  12. namespace date_time {
  13. //! An implementation of the Gregorian calendar
  14. /*! This is a parameterized implementation of a proleptic Gregorian Calendar that
  15. can be used in the creation of date systems or just to perform calculations.
  16. All the methods of this class are static functions, so the intent is to
  17. never create instances of this class.
  18. @tparam ymd_type_ Struct type representing the year, month, day. The ymd_type must
  19. define a of types for the year, month, and day. These types need to be
  20. arithmetic types.
  21. @tparam date_int_type_ Underlying type for the date count. Must be an arithmetic type.
  22. */
  23. template<typename ymd_type_, typename date_int_type_>
  24. class BOOST_SYMBOL_VISIBLE gregorian_calendar_base {
  25. public:
  26. //! define a type a date split into components
  27. typedef ymd_type_ ymd_type;
  28. //! define a type for representing months
  29. typedef typename ymd_type::month_type month_type;
  30. //! define a type for representing days
  31. typedef typename ymd_type::day_type day_type;
  32. //! Type to hold a stand alone year value (eg: 2002)
  33. typedef typename ymd_type::year_type year_type;
  34. //! Define the integer type to use for internal calculations
  35. typedef date_int_type_ date_int_type;
  36. static BOOST_CXX14_CONSTEXPR unsigned short day_of_week(const ymd_type& ymd);
  37. static BOOST_CXX14_CONSTEXPR int week_number(const ymd_type&ymd);
  38. static BOOST_CXX14_CONSTEXPR date_int_type day_number(const ymd_type& ymd);
  39. static BOOST_CXX14_CONSTEXPR date_int_type julian_day_number(const ymd_type& ymd);
  40. static BOOST_CXX14_CONSTEXPR date_int_type modjulian_day_number(const ymd_type& ymd);
  41. static BOOST_CXX14_CONSTEXPR ymd_type from_day_number(date_int_type);
  42. static BOOST_CXX14_CONSTEXPR ymd_type from_julian_day_number(date_int_type);
  43. static BOOST_CXX14_CONSTEXPR ymd_type from_modjulian_day_number(date_int_type);
  44. static BOOST_CXX14_CONSTEXPR bool is_leap_year(year_type);
  45. static BOOST_CXX14_CONSTEXPR unsigned short end_of_month_day(year_type y, month_type m);
  46. static BOOST_CXX14_CONSTEXPR ymd_type epoch();
  47. static BOOST_CXX14_CONSTEXPR unsigned short days_in_week();
  48. };
  49. } } //namespace
  50. #include "boost/date_time/gregorian_calendar.ipp"
  51. #endif