123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- #ifndef GREG_MONTH_HPP___
- #define GREG_MONTH_HPP___
- #include <boost/date_time/constrained_value.hpp>
- #include <boost/date_time/date_defs.hpp>
- #include <boost/date_time/compiler_config.hpp>
- #include <stdexcept>
- #include <string>
- namespace boost {
- namespace gregorian {
- typedef date_time::months_of_year months_of_year;
-
- using date_time::Jan;
- using date_time::Feb;
- using date_time::Mar;
- using date_time::Apr;
- using date_time::May;
- using date_time::Jun;
- using date_time::Jul;
- using date_time::Aug;
- using date_time::Sep;
- using date_time::Oct;
- using date_time::Nov;
- using date_time::Dec;
- using date_time::NotAMonth;
- using date_time::NumMonths;
-
- struct BOOST_SYMBOL_VISIBLE bad_month : public std::out_of_range
- {
- bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
- };
-
- typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies;
-
- typedef CV::constrained_value<greg_month_policies> greg_month_rep;
-
- class BOOST_SYMBOL_VISIBLE greg_month : public greg_month_rep {
- public:
- typedef date_time::months_of_year month_enum;
-
- BOOST_CXX14_CONSTEXPR greg_month(month_enum theMonth) :
- greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
-
- BOOST_CXX14_CONSTEXPR greg_month(value_type theMonth) : greg_month_rep(theMonth) {}
-
- BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;}
-
- BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;}
- BOOST_CXX14_CONSTEXPR month_enum as_enum() const {return static_cast<month_enum>(value_);}
-
- const char*
- as_short_string() const
- {
- static const char* const short_month_names[NumMonths]
- = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAM"};
- return short_month_names[value_-1];
- }
-
- const char*
- as_long_string() const
- {
- static const char* const long_month_names[NumMonths]
- = {"January","February","March","April","May","June","July","August",
- "September","October","November","December","NotAMonth"};
- return long_month_names[value_-1];
- }
- #ifndef BOOST_NO_STD_WSTRING
-
- const wchar_t*
- as_short_wstring() const
- {
- static const wchar_t* const w_short_month_names[NumMonths]
- = {L"Jan",L"Feb",L"Mar",L"Apr",L"May",L"Jun",L"Jul",L"Aug",L"Sep",L"Oct",
- L"Nov",L"Dec",L"NAM"};
- return w_short_month_names[value_-1];
- }
-
- const wchar_t*
- as_long_wstring() const
- {
- static const wchar_t* const w_long_month_names[NumMonths]
- = {L"January",L"February",L"March",L"April",L"May",L"June",L"July",L"August",
- L"September",L"October",L"November",L"December",L"NotAMonth"};
- return w_long_month_names[value_-1];
- }
- #endif
-
- const char* as_short_string(char) const
- {
- return as_short_string();
- }
- const char* as_long_string(char) const
- {
- return as_long_string();
- }
- #ifndef BOOST_NO_STD_WSTRING
- const wchar_t* as_short_string(wchar_t) const
- {
- return as_short_wstring();
- }
- const wchar_t* as_long_string(wchar_t) const
- {
- return as_long_wstring();
- }
- #endif
- };
- } }
- #endif
|