File indexing completed on 2025-01-30 09:35:18
0001 #ifndef GREG_MONTH_HPP___
0002 #define GREG_MONTH_HPP___
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <boost/date_time/constrained_value.hpp>
0013 #include <boost/date_time/date_defs.hpp>
0014 #include <boost/date_time/compiler_config.hpp>
0015 #include <stdexcept>
0016 #include <string>
0017
0018 namespace boost {
0019 namespace gregorian {
0020
0021 typedef date_time::months_of_year months_of_year;
0022
0023
0024 using date_time::Jan;
0025 using date_time::Feb;
0026 using date_time::Mar;
0027 using date_time::Apr;
0028 using date_time::May;
0029 using date_time::Jun;
0030 using date_time::Jul;
0031 using date_time::Aug;
0032 using date_time::Sep;
0033 using date_time::Oct;
0034 using date_time::Nov;
0035 using date_time::Dec;
0036 using date_time::NotAMonth;
0037 using date_time::NumMonths;
0038
0039
0040 struct BOOST_SYMBOL_VISIBLE bad_month : public std::out_of_range
0041 {
0042 bad_month() : std::out_of_range(std::string("Month number is out of range 1..12")) {}
0043 };
0044
0045 typedef CV::simple_exception_policy<unsigned short, 1, 12, bad_month> greg_month_policies;
0046
0047 typedef CV::constrained_value<greg_month_policies> greg_month_rep;
0048
0049
0050
0051 class BOOST_SYMBOL_VISIBLE greg_month : public greg_month_rep {
0052 public:
0053 typedef date_time::months_of_year month_enum;
0054
0055
0056 BOOST_CXX14_CONSTEXPR greg_month(month_enum theMonth) :
0057 greg_month_rep(static_cast<greg_month_rep::value_type>(theMonth)) {}
0058
0059 BOOST_CXX14_CONSTEXPR greg_month(value_type theMonth) : greg_month_rep(theMonth) {}
0060
0061 BOOST_CXX14_CONSTEXPR operator value_type() const {return value_;}
0062
0063 BOOST_CXX14_CONSTEXPR value_type as_number() const {return value_;}
0064 BOOST_CXX14_CONSTEXPR month_enum as_enum() const {return static_cast<month_enum>(value_);}
0065
0066
0067 const char*
0068 as_short_string() const
0069 {
0070 static const char* const short_month_names[NumMonths]
0071 = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAM"};
0072 return short_month_names[value_-1];
0073 }
0074
0075
0076 const char*
0077 as_long_string() const
0078 {
0079 static const char* const long_month_names[NumMonths]
0080 = {"January","February","March","April","May","June","July","August",
0081 "September","October","November","December","NotAMonth"};
0082 return long_month_names[value_-1];
0083 }
0084
0085 #ifndef BOOST_NO_STD_WSTRING
0086
0087
0088 const wchar_t*
0089 as_short_wstring() const
0090 {
0091 static const wchar_t* const w_short_month_names[NumMonths]
0092 = {L"Jan",L"Feb",L"Mar",L"Apr",L"May",L"Jun",L"Jul",L"Aug",L"Sep",L"Oct",
0093 L"Nov",L"Dec",L"NAM"};
0094 return w_short_month_names[value_-1];
0095 }
0096
0097
0098 const wchar_t*
0099 as_long_wstring() const
0100 {
0101 static const wchar_t* const w_long_month_names[NumMonths]
0102 = {L"January",L"February",L"March",L"April",L"May",L"June",L"July",L"August",
0103 L"September",L"October",L"November",L"December",L"NotAMonth"};
0104 return w_long_month_names[value_-1];
0105 }
0106
0107 #endif
0108
0109
0110
0111 const char* as_short_string(char) const
0112 {
0113 return as_short_string();
0114 }
0115 const char* as_long_string(char) const
0116 {
0117 return as_long_string();
0118 }
0119 #ifndef BOOST_NO_STD_WSTRING
0120 const wchar_t* as_short_string(wchar_t) const
0121 {
0122 return as_short_wstring();
0123 }
0124 const wchar_t* as_long_string(wchar_t) const
0125 {
0126 return as_long_wstring();
0127 }
0128 #endif
0129 };
0130
0131 } }
0132
0133 #endif