Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:38

0001 #ifndef ISO_FORMAT_HPP___
0002 #define ISO_FORMAT_HPP___
0003 
0004 /* Copyright (c) 2002,2003 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, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include "boost/date_time/parse_format_base.hpp"
0013 
0014 namespace boost {
0015 namespace date_time {
0016 
0017 //! Class to provide common ISO 8601 formatting spec
0018 template<class charT>
0019 class iso_format_base {
0020 public:
0021   //! Describe month format -- its an integer in ISO 8601 format
0022   static month_format_spec month_format()
0023   {
0024     return month_as_integer;
0025   }
0026 
0027   //! String used printed is date is invalid
0028   static const charT* not_a_date()
0029   {     
0030     return "not-a-date-time";
0031   }
0032   //! String used to for positive infinity value
0033   static const charT* pos_infinity()
0034   {
0035     return "+infinity";
0036   }
0037   //! String used to for positive infinity value
0038   static const charT* neg_infinity()
0039   {
0040     return "-infinity";
0041   }
0042 
0043   //! ISO 8601 char for a year -- used in durations
0044   static charT year_sep_char()
0045   {
0046     return 'Y';
0047   }
0048   //! ISO 8601 char for a month
0049   static charT month_sep_char()
0050   {
0051     return '-';
0052   }
0053   //! ISO 8601 char for a day
0054   static charT day_sep_char()
0055   {
0056     return '-';
0057   }
0058   //! char for minute
0059   static charT hour_sep_char()
0060   {
0061     return ':';
0062   }
0063   //! char for minute
0064   static charT minute_sep_char()
0065   {
0066     return ':';
0067   }
0068   //! char for second
0069   static charT second_sep_char()
0070   {
0071     return ':';
0072   }
0073   //! ISO 8601 char for a period
0074   static charT period_start_char()
0075   {
0076     return 'P';
0077   }
0078   //! Used in time in mixed strings to set start of time
0079   static charT time_start_char()
0080   {
0081     return 'T';
0082   }
0083 
0084   //! Used in mixed strings to identify start of a week number
0085   static charT week_start_char()
0086   {
0087     return 'W';
0088   }
0089 
0090   //! Separators for periods
0091   static charT period_sep_char()
0092   {
0093     return '/';
0094   }
0095   //! Separator for hh:mm:ss
0096   static charT time_sep_char()
0097   {
0098     return ':';
0099   }
0100   //! Preferred Separator for hh:mm:ss,decimal_fraction
0101   static charT fractional_time_sep_char()
0102   {
0103     return ',';
0104   }
0105 
0106   static bool is_component_sep(charT sep)
0107   {
0108     switch(sep) {
0109     case 'H':
0110     case 'M':
0111     case 'S':
0112     case 'W':
0113     case 'T':
0114     case 'Y':
0115     case 'D':return true;
0116     default:
0117       return false;
0118     }
0119   }
0120 
0121   static bool is_fractional_time_sep(charT sep)
0122   {
0123     switch(sep) {
0124     case ',':
0125     case '.': return true;
0126     default: return false;
0127     }
0128   }
0129   static bool is_timezone_sep(charT sep)
0130   {
0131     switch(sep) {
0132     case '+':
0133     case '-': return true;
0134     default: return false;
0135     }
0136   }
0137   static charT element_sep_char()
0138   {
0139     return '-';
0140   }
0141 
0142 };
0143 
0144 #ifndef BOOST_NO_STD_WSTRING
0145 
0146 //! Class to provide common ISO 8601 formatting spec
0147 template<>
0148 class iso_format_base<wchar_t> {
0149 public:
0150   //! Describe month format -- its an integer in ISO 8601 format
0151   static month_format_spec month_format()
0152   {
0153     return month_as_integer;
0154   }
0155 
0156   //! String used printed is date is invalid
0157   static const wchar_t* not_a_date()
0158   {      
0159     return L"not-a-date-time";
0160   }
0161   //! String used to for positive infinity value
0162   static const wchar_t* pos_infinity()
0163   {
0164     return L"+infinity";
0165   }
0166   //! String used to for positive infinity value
0167   static const wchar_t* neg_infinity()
0168   {
0169     return L"-infinity";
0170   }
0171 
0172   //! ISO 8601 char for a year -- used in durations
0173   static wchar_t year_sep_char()
0174   {
0175     return 'Y';
0176   }
0177   //! ISO 8601 char for a month
0178   static wchar_t month_sep_char()
0179   {
0180     return '-';
0181   }
0182   //! ISO 8601 char for a day
0183   static wchar_t day_sep_char()
0184   {
0185     return '-';
0186   }
0187   //! char for minute
0188   static wchar_t hour_sep_char()
0189   {
0190     return ':';
0191   }
0192   //! char for minute
0193   static wchar_t minute_sep_char()
0194   {
0195     return ':';
0196   }
0197   //! char for second
0198   static wchar_t second_sep_char()
0199   {
0200     return ':';
0201   }
0202   //! ISO 8601 char for a period
0203   static wchar_t period_start_char()
0204   {
0205     return 'P';
0206   }
0207   //! Used in time in mixed strings to set start of time
0208   static wchar_t time_start_char()
0209   {
0210     return 'T';
0211   }
0212 
0213   //! Used in mixed strings to identify start of a week number
0214   static wchar_t week_start_char()
0215   {
0216     return 'W';
0217   }
0218 
0219   //! Separators for periods
0220   static wchar_t period_sep_char()
0221   {
0222     return '/';
0223   }
0224   //! Separator for hh:mm:ss
0225   static wchar_t time_sep_char()
0226   {
0227     return ':';
0228   }
0229   //! Preferred Separator for hh:mm:ss,decimal_fraction
0230   static wchar_t fractional_time_sep_char()
0231   {
0232     return ',';
0233   }
0234 
0235   static bool is_component_sep(wchar_t sep)
0236   {
0237     switch(sep) {
0238     case 'H':
0239     case 'M':
0240     case 'S':
0241     case 'W':
0242     case 'T':
0243     case 'Y':
0244     case 'D':return true;
0245     default:
0246       return false;
0247     }
0248   }
0249 
0250   static bool is_fractional_time_sep(wchar_t sep)
0251   {
0252     switch(sep) {
0253     case ',':
0254     case '.': return true;
0255     default: return false;
0256     }
0257   }
0258   static bool is_timezone_sep(wchar_t sep)
0259   {
0260     switch(sep) {
0261     case '+':
0262     case '-': return true;
0263     default: return false;
0264     }
0265   }
0266   static wchar_t element_sep_char()
0267   {
0268     return '-';
0269   }
0270 
0271 };
0272 
0273 #endif // BOOST_NO_STD_WSTRING
0274 
0275 //! Format description for ISO 8601 normal YYYYMMDD
0276 template<class charT>
0277 class iso_format : public iso_format_base<charT> {
0278 public:
0279   //! The ios standard format doesn't use char separators
0280   static bool has_date_sep_chars()
0281   {
0282     return false;
0283   }
0284 };
0285 
0286 //! Extended format uses seperators YYYY-MM-DD
0287 template<class charT>
0288 class iso_extended_format : public iso_format_base<charT> {
0289 public:
0290   //! Extended format needs char separators
0291   static bool has_date_sep_chars()
0292   {
0293     return true;
0294   }
0295 
0296 };
0297 
0298 } } //namespace date_time
0299 
0300 
0301 
0302 
0303 #endif