Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-25 09:37:27

0001 #ifndef GREG_DATE_HPP___
0002 #define GREG_DATE_HPP___
0003 
0004 /* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland
0009  * $Date$
0010  */
0011 
0012 #include <boost/throw_exception.hpp>
0013 #include <boost/date_time/compiler_config.hpp>
0014 #include <boost/date_time/date.hpp>
0015 #include <boost/date_time/special_defs.hpp>
0016 #include <boost/date_time/gregorian/greg_calendar.hpp>
0017 #include <boost/date_time/gregorian/greg_duration.hpp>
0018 
0019 namespace boost {
0020 namespace gregorian {
0021 
0022   //bring special enum values into the namespace
0023   using date_time::special_values;
0024   using date_time::not_special;
0025   using date_time::neg_infin;
0026   using date_time::pos_infin;
0027   using date_time::not_a_date_time;
0028   using date_time::max_date_time;
0029   using date_time::min_date_time;
0030 
0031   //! A date type based on gregorian_calendar
0032   /*! This class is the primary interface for programming with
0033       greogorian dates.  The is a lightweight type that can be
0034       freely passed by value.  All comparison operators are
0035       supported.
0036       \ingroup date_basics
0037   */
0038   class BOOST_SYMBOL_VISIBLE date : public date_time::date<date, gregorian_calendar, date_duration>
0039   {
0040    public:
0041     typedef gregorian_calendar::year_type year_type;
0042     typedef gregorian_calendar::month_type month_type;
0043     typedef gregorian_calendar::day_type day_type;
0044     typedef gregorian_calendar::day_of_year_type day_of_year_type;
0045     typedef gregorian_calendar::ymd_type ymd_type;
0046     typedef gregorian_calendar::date_rep_type date_rep_type;
0047     typedef gregorian_calendar::date_int_type date_int_type;
0048     typedef date_duration  duration_type;
0049 #if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR)
0050     //! Default constructor constructs with not_a_date_time
0051     BOOST_CXX14_CONSTEXPR date():
0052       date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(not_a_date_time))
0053     {}
0054 #endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR
0055     //! Main constructor with year, month, day
0056     BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
0057       : date_time::date<date, gregorian_calendar, date_duration>(y, m, d)
0058     {
0059       if (gregorian_calendar::end_of_month_day(y, m) < d) {
0060         boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year")));
0061       }
0062     }
0063     //! Constructor from a ymd_type structure
0064     BOOST_CXX14_CONSTEXPR explicit date(const ymd_type& ymd)
0065       : date_time::date<date, gregorian_calendar, date_duration>(ymd)
0066     {}
0067     //! Needed copy constructor
0068     BOOST_CXX14_CONSTEXPR explicit date(const date_int_type& rhs):
0069       date_time::date<date,gregorian_calendar, date_duration>(rhs)
0070     {}
0071     //! Needed copy constructor
0072     BOOST_CXX14_CONSTEXPR explicit date(date_rep_type rhs):
0073       date_time::date<date,gregorian_calendar, date_duration>(rhs)
0074     {}
0075     //! Constructor for infinities, not a date, max and min date
0076     BOOST_CXX14_CONSTEXPR explicit date(special_values sv):
0077       date_time::date<date, gregorian_calendar, date_duration>(from_special_adjusted(sv))
0078     {}
0079     //!Return the Julian Day number for the date.
0080     BOOST_CXX14_CONSTEXPR date_int_type julian_day() const
0081     {
0082       ymd_type ymd = year_month_day();
0083       return gregorian_calendar::julian_day_number(ymd);
0084     }
0085     //!Return the day of year 1..365 or 1..366 (for leap year)
0086     BOOST_CXX14_CONSTEXPR day_of_year_type day_of_year() const
0087     {
0088       date start_of_year(year(), 1, 1);
0089       unsigned short doy = static_cast<unsigned short>((*this-start_of_year).days() + 1);
0090       return day_of_year_type(doy);
0091     }
0092     //!Return the Modified Julian Day number for the date.
0093     BOOST_CXX14_CONSTEXPR date_int_type modjulian_day() const
0094     {
0095       ymd_type ymd = year_month_day();
0096       return gregorian_calendar::modjulian_day_number(ymd);
0097     }
0098     //!Return the ISO 8601 week number 1..53
0099     BOOST_CXX14_CONSTEXPR int week_number() const
0100     {
0101       ymd_type ymd = year_month_day();
0102       return gregorian_calendar::week_number(ymd);
0103     }
0104     //! Return the day number from the calendar
0105     BOOST_CXX14_CONSTEXPR date_int_type day_number() const
0106     {
0107       return days_;
0108     }
0109     //! Return the last day of the current month
0110     BOOST_CXX14_CONSTEXPR date end_of_month() const
0111     {
0112       ymd_type ymd = year_month_day();
0113       unsigned short eom_day =  gregorian_calendar::end_of_month_day(ymd.year, ymd.month);
0114       return date(ymd.year, ymd.month, eom_day);
0115     }
0116 
0117     friend BOOST_CXX14_CONSTEXPR
0118     bool operator==(const date& lhs, const date& rhs);
0119 
0120    private:
0121 
0122     BOOST_CXX14_CONSTEXPR date_rep_type from_special_adjusted(special_values sv)
0123     {
0124       switch (sv)
0125       {
0126         case min_date_time: return gregorian_calendar::day_number(ymd_type(1400, 1, 1));
0127         case max_date_time: return gregorian_calendar::day_number(ymd_type(9999, 12, 31));
0128         default: return date_rep_type::from_special(sv);
0129       }
0130     }
0131   };
0132 
0133   inline BOOST_CXX14_CONSTEXPR
0134   bool operator==(const date& lhs, const date& rhs)
0135   {
0136     return lhs.days_ == rhs.days_;
0137   }
0138 
0139 
0140 } } //namespace gregorian
0141 
0142 
0143 
0144 #endif