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

source code of include/boost/date_time/iso_format.hpp