iso_format.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #ifndef ISO_FORMAT_HPP___
  2. #define ISO_FORMAT_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, Bart Garst
  8. * $Date$
  9. */
  10. #include "boost/date_time/parse_format_base.hpp"
  11. namespace boost {
  12. namespace date_time {
  13. //! Class to provide common iso formatting spec
  14. template<class charT>
  15. class iso_format_base {
  16. public:
  17. //! Describe month format -- its an integer in iso format
  18. static month_format_spec month_format()
  19. {
  20. return month_as_integer;
  21. }
  22. //! String used printed is date is invalid
  23. static const charT* not_a_date()
  24. {
  25. return "not-a-date-time";
  26. }
  27. //! String used to for positive infinity value
  28. static const charT* pos_infinity()
  29. {
  30. return "+infinity";
  31. }
  32. //! String used to for positive infinity value
  33. static const charT* neg_infinity()
  34. {
  35. return "-infinity";
  36. }
  37. //! ISO char for a year -- used in durations
  38. static charT year_sep_char()
  39. {
  40. return 'Y';
  41. }
  42. //! ISO char for a month
  43. static charT month_sep_char()
  44. {
  45. return '-';
  46. }
  47. //! ISO char for a day
  48. static charT day_sep_char()
  49. {
  50. return '-';
  51. }
  52. //! char for minute
  53. static charT hour_sep_char()
  54. {
  55. return ':';
  56. }
  57. //! char for minute
  58. static charT minute_sep_char()
  59. {
  60. return ':';
  61. }
  62. //! char for second
  63. static charT second_sep_char()
  64. {
  65. return ':';
  66. }
  67. //! ISO char for a period
  68. static charT period_start_char()
  69. {
  70. return 'P';
  71. }
  72. //! Used in time in mixed strings to set start of time
  73. static charT time_start_char()
  74. {
  75. return 'T';
  76. }
  77. //! Used in mixed strings to identify start of a week number
  78. static charT week_start_char()
  79. {
  80. return 'W';
  81. }
  82. //! Separators for periods
  83. static charT period_sep_char()
  84. {
  85. return '/';
  86. }
  87. //! Separator for hh:mm:ss
  88. static charT time_sep_char()
  89. {
  90. return ':';
  91. }
  92. //! Preferred Separator for hh:mm:ss,decimal_fraction
  93. static charT fractional_time_sep_char()
  94. {
  95. return ',';
  96. }
  97. static bool is_component_sep(charT sep)
  98. {
  99. switch(sep) {
  100. case 'H':
  101. case 'M':
  102. case 'S':
  103. case 'W':
  104. case 'T':
  105. case 'Y':
  106. case 'D':return true;
  107. default:
  108. return false;
  109. }
  110. }
  111. static bool is_fractional_time_sep(charT sep)
  112. {
  113. switch(sep) {
  114. case ',':
  115. case '.': return true;
  116. default: return false;
  117. }
  118. }
  119. static bool is_timezone_sep(charT sep)
  120. {
  121. switch(sep) {
  122. case '+':
  123. case '-': return true;
  124. default: return false;
  125. }
  126. }
  127. static charT element_sep_char()
  128. {
  129. return '-';
  130. }
  131. };
  132. #ifndef BOOST_NO_STD_WSTRING
  133. //! Class to provide common iso formatting spec
  134. template<>
  135. class iso_format_base<wchar_t> {
  136. public:
  137. //! Describe month format -- its an integer in iso format
  138. static month_format_spec month_format()
  139. {
  140. return month_as_integer;
  141. }
  142. //! String used printed is date is invalid
  143. static const wchar_t* not_a_date()
  144. {
  145. return L"not-a-date-time";
  146. }
  147. //! String used to for positive infinity value
  148. static const wchar_t* pos_infinity()
  149. {
  150. return L"+infinity";
  151. }
  152. //! String used to for positive infinity value
  153. static const wchar_t* neg_infinity()
  154. {
  155. return L"-infinity";
  156. }
  157. //! ISO char for a year -- used in durations
  158. static wchar_t year_sep_char()
  159. {
  160. return 'Y';
  161. }
  162. //! ISO char for a month
  163. static wchar_t month_sep_char()
  164. {
  165. return '-';
  166. }
  167. //! ISO char for a day
  168. static wchar_t day_sep_char()
  169. {
  170. return '-';
  171. }
  172. //! char for minute
  173. static wchar_t hour_sep_char()
  174. {
  175. return ':';
  176. }
  177. //! char for minute
  178. static wchar_t minute_sep_char()
  179. {
  180. return ':';
  181. }
  182. //! char for second
  183. static wchar_t second_sep_char()
  184. {
  185. return ':';
  186. }
  187. //! ISO char for a period
  188. static wchar_t period_start_char()
  189. {
  190. return 'P';
  191. }
  192. //! Used in time in mixed strings to set start of time
  193. static wchar_t time_start_char()
  194. {
  195. return 'T';
  196. }
  197. //! Used in mixed strings to identify start of a week number
  198. static wchar_t week_start_char()
  199. {
  200. return 'W';
  201. }
  202. //! Separators for periods
  203. static wchar_t period_sep_char()
  204. {
  205. return '/';
  206. }
  207. //! Separator for hh:mm:ss
  208. static wchar_t time_sep_char()
  209. {
  210. return ':';
  211. }
  212. //! Preferred Separator for hh:mm:ss,decimal_fraction
  213. static wchar_t fractional_time_sep_char()
  214. {
  215. return ',';
  216. }
  217. static bool is_component_sep(wchar_t sep)
  218. {
  219. switch(sep) {
  220. case 'H':
  221. case 'M':
  222. case 'S':
  223. case 'W':
  224. case 'T':
  225. case 'Y':
  226. case 'D':return true;
  227. default:
  228. return false;
  229. }
  230. }
  231. static bool is_fractional_time_sep(wchar_t sep)
  232. {
  233. switch(sep) {
  234. case ',':
  235. case '.': return true;
  236. default: return false;
  237. }
  238. }
  239. static bool is_timezone_sep(wchar_t sep)
  240. {
  241. switch(sep) {
  242. case '+':
  243. case '-': return true;
  244. default: return false;
  245. }
  246. }
  247. static wchar_t element_sep_char()
  248. {
  249. return '-';
  250. }
  251. };
  252. #endif // BOOST_NO_STD_WSTRING
  253. //! Format description for iso normal YYYYMMDD
  254. template<class charT>
  255. class iso_format : public iso_format_base<charT> {
  256. public:
  257. //! The ios standard format doesn't use char separators
  258. static bool has_date_sep_chars()
  259. {
  260. return false;
  261. }
  262. };
  263. //! Extended format uses seperators YYYY-MM-DD
  264. template<class charT>
  265. class iso_extended_format : public iso_format_base<charT> {
  266. public:
  267. //! Extended format needs char separators
  268. static bool has_date_sep_chars()
  269. {
  270. return true;
  271. }
  272. };
  273. } } //namespace date_time
  274. #endif