Ticket #1078: BoostDateTimeTest.cpp

File BoostDateTimeTest.cpp, 23.0 KB (added by lothar, 15 years ago)

test that shows that date_time cannot parse it's own output

Line 
1/*
2 * Copyright (c) 2007 Tradescape Inc. All rights reserved.
3 * @author lothar
4 */
5
6#include <string>
7#include <iomanip>
8#include <iostream>
9#include <sstream>
10#include <locale>
11
12#include "boost/version.hpp"
13#include "boost/date_time/gregorian/gregorian.hpp"
14#include "boost/date_time/posix_time/posix_time.hpp"
15#include "boost/date_time/local_time/local_time.hpp"
16
17#include "unittest/unittest.h"
18
19#ifndef HIDE_BOOST_DATETIME_BUGS
20#if BOOST_VERSION <= 103500
21#define HIDE_BOOST_DATETIME_BUGS true
22#else
23#define HIDE_BOOST_DATETIME_BUGS false
24#endif
25#endif
26
27
28namespace boost
29{
30
31
32/** Converts a std::wstring into a std::string with iso8859_1 encoding.
33 * This method uses the fact that iso8859-1 is the same as the
34 * low byte of UFT-16 or UTF-32
35 */
36template < typename StringT >
37StringT iso8859_1 ( std::wstring const & rc_string )
38{
39 StringT result;
40 typename StringT::value_type mask = ~0;
41 result.reserve(rc_string.size());
42 for(typename StringT::size_type cnt = 0, max = rc_string.size(); cnt < max; ++cnt)
43 {
44 result.push_back(mask & rc_string[cnt]);
45 }
46 return result;
47}
48
49
50/** Converts a std::String with iso8859_1 encoding into a std::wstring.
51 * This method uses the fact that iso8859-1 is the same as the
52 * low byte of UFT-16 or UTF-32
53 */
54template < typename StringT >
55StringT iso8859_1 ( std::string const & rc_string )
56{
57 StringT result;
58 typename StringT::value_type mask = ~0;
59 result.resize(rc_string.size());
60 for(typename StringT::size_type cnt = 0, max = rc_string.size(); cnt < max; ++cnt)
61 {
62 result.push_back(mask & rc_string[cnt]);
63 }
64 return result;
65}
66
67
68/** Nop specialization for std::string.
69 */
70template < >
71inline std::string iso8859_1 ( std::string const & rc_string )
72{
73 return rc_string;
74}
75
76/** Nop specialization for std::wstring.
77 */
78template < >
79inline std::wstring iso8859_1 ( std::wstring const & rc_string )
80{
81 return rc_string;
82}
83
84// boost::local_time does not (yet) support reading timezones, so do it manually
85template < class charT, class traits >
86void manualIsoTimezoneFix(
87 std::basic_istream < charT, traits > & r_istream,
88 boost::local_time::local_date_time & r_ldt
89)
90{
91 if(!r_ldt.zone().get())
92 {
93 boost::local_time::time_zone_ptr zone;
94 std::basic_string < charT, traits> tzsT;
95
96 // try to read timezone string
97 r_istream >> std::ws >> tzsT;
98 if (!r_istream.fail())
99 {
100 std::string tzs = iso8859_1< std::string >(std::basic_string < charT, traits >(tzsT));
101 // try to find timezone
102 zone = boost::local_time::time_zone_ptr(
103 new boost::local_time::posix_time_zone(tzs)
104 );
105 r_ldt = r_ldt.local_time_in(zone);
106 r_ldt -= zone->base_utc_offset();
107 }
108 }
109}
110
111using namespace unittest;
112
113
114struct BoostDateTimeTest
115:
116 public TestSuite
117{
118 struct constructor
119 {
120 void operator()()
121 {
122 std::stringstream ss;
123 // switch locale to output ISO format
124 boost::local_time::local_time_facet* output_facet =
125 new boost::local_time::local_time_facet();
126 output_facet->format(
127 boost::local_time::local_time_facet::iso_time_format_extended_specifier
128 );
129 ss.imbue(std::locale(std::locale("C"), output_facet));
130
131 boost::posix_time::ptime pt(
132 boost::gregorian::date(
133 2005,
134 9,
135 30
136 ),
137 boost::posix_time::time_duration(
138 18,
139 25,
140 17
141 )
142 );
143 boost::local_time::time_zone_ptr zone(
144 new boost::local_time::posix_time_zone("+01:00")
145 );
146 boost::local_time::local_date_time ldt(
147 pt,
148 zone
149 );
150 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
151 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
152 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
153 UNITTEST_ASSERT(Equal, static_cast<int32_t>(18), ldt.utc_time().time_of_day().hours());
154 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
155 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
156 UNITTEST_ASSERT(Equal, static_cast<int32_t>(1), ldt.zone()->base_utc_offset().hours());
157 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
158
159 ss.str("");
160 ss.clear();
161 ss << ldt;
162 //@? lw: do we really expect "2005-09-30 19:25:17+01:00" instead of "2005-09-30 18:25:17+01:00"
163 UNITTEST_ASSERT(Equal, std::string("2005-09-30 19:25:17+01:00"), ss.str());
164
165 pt = boost::posix_time::ptime(
166 boost::gregorian::date(
167 2005,
168 9,
169 30
170 ),
171 boost::posix_time::time_duration(
172 11,
173 22,
174 17
175 )
176 );
177 zone = boost::local_time::time_zone_ptr(
178 new boost::local_time::posix_time_zone("-08:03")
179 );
180 ldt = boost::local_time::local_date_time(
181 pt,
182 zone
183 );
184 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
185 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
186 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
187 UNITTEST_ASSERT(Equal, static_cast<int32_t>(11), ldt.utc_time().time_of_day().hours());
188 UNITTEST_ASSERT(Equal, static_cast<int32_t>(22), ldt.utc_time().time_of_day().minutes());
189 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
190 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-8), ldt.zone()->base_utc_offset().hours());
191 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-3), ldt.zone()->base_utc_offset().minutes());
192
193 ss.str("");
194 ss.clear();
195 ss << ldt;
196 //@? lw: do we really expect "2005-09-30 03:19:17-08:03" instead of "2005-09-30 11:22:17-08:03"
197 UNITTEST_ASSERT(Equal, std::string("2005-09-30 03:19:17-08:03"), ss.str());
198 }
199 };
200
201 struct input
202 {
203 void operator()()
204 {
205 std::stringstream ss;
206 boost::local_time::time_zone_ptr zone;
207 boost::local_time::local_date_time ndt(
208 boost::posix_time::not_a_date_time,
209 zone
210 );
211 boost::local_time::local_date_time ldt(
212 boost::posix_time::not_a_date_time,
213 zone
214 );
215
216 ldt = ndt;
217 ss.str("2005-Sep-30 19:25:17 CET+01:00");
218 ss.clear();
219 ss >> ldt;
220 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
221 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
222 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
223 UNITTEST_ASSERT(Equal, static_cast<int32_t>(18), ldt.utc_time().time_of_day().hours());
224 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
225 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
226 UNITTEST_ASSERT(Equal, static_cast<int32_t>(1), ldt.zone()->base_utc_offset().hours());
227 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
228
229 ldt = ndt;
230 ss.str("2005-Sep-30 19:25:17 PST-08:00");
231 ss.clear();
232 ss >> ldt;
233 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
234 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(10), ldt.date().month());
235 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(1), ldt.date().day());
236 UNITTEST_ASSERT(Equal, static_cast<int32_t>(3), ldt.utc_time().time_of_day().hours());
237 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
238 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
239 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-8), ldt.zone()->base_utc_offset().hours());
240 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
241 }
242 };
243
244 struct output
245 {
246 void operator()()
247 {
248 std::stringstream ss;
249
250 //@? lw: should it not be "2005-Sep-30 19:25:17 CET+01:00" ?
251 std::string str("2005-Sep-30 19:25:17 CET");
252 boost::local_time::local_date_time ldt(
253 boost::posix_time::ptime(
254 boost::gregorian::date(
255 2005,
256 9,
257 30
258 ),
259 boost::posix_time::time_duration(
260 18,
261 25,
262 17
263 )
264 ),
265 boost::local_time::time_zone_ptr(
266 new boost::local_time::posix_time_zone("CET+01:00")
267 )
268 );
269
270 ss.str("");
271 ss.clear();
272 ss << ldt;
273 UNITTEST_ASSERT(Equal, str, ss.str());
274
275 //@? lw: should it not be "2005-Sep-30 19:25:17 PST-08:00" ?
276 str = "2005-Sep-30 19:25:17 PST";
277 ldt = boost::local_time::local_date_time(
278 boost::posix_time::ptime(
279 boost::gregorian::date(
280 2005,
281 10,
282 1
283 ),
284 boost::posix_time::time_duration(
285 3,
286 25,
287 17
288 )
289 ),
290 boost::local_time::time_zone_ptr(
291 new boost::local_time::posix_time_zone("PST-08:00")
292 )
293 );
294
295 ss.str("");
296 ss.clear();
297 ss << ldt;
298 UNITTEST_ASSERT(Equal, str, ss.str());
299 }
300 };
301
302 struct inputIso
303 {
304 void operator()()
305 {
306 std::stringstream ss;
307
308 // switch locale to read ISO format
309 boost::local_time::local_time_input_facet* input_facet =
310 new boost::local_time::local_time_input_facet();
311 input_facet->set_iso_extended_format();
312 ss.imbue(std::locale(std::locale("C"), input_facet));
313
314 boost::local_time::time_zone_ptr zone;
315 boost::local_time::local_date_time ndt(
316 boost::posix_time::not_a_date_time,
317 zone
318 );
319 boost::local_time::local_date_time ldt(
320 boost::posix_time::not_a_date_time,
321 zone
322 );
323
324 ldt = ndt;
325 ss.str("2005-09-30 19:25:17+01:00");
326 ss.clear();
327 ss >> ldt;
328 //@! lw: bug in boost::date_time
329 #if HIDE_BOOST_DATETIME_BUGS
330 manualIsoTimezoneFix(ss, ldt);
331 #endif
332 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
333 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
334 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
335 UNITTEST_ASSERT(Equal, static_cast<int32_t>(18), ldt.utc_time().time_of_day().hours());
336 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
337 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
338 UNITTEST_ASSERT(Equal, true, 0 != ldt.zone().get());
339 UNITTEST_ASSERT(Equal, static_cast<int32_t>(1), ldt.zone()->base_utc_offset().hours());
340 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
341
342 ldt = ndt;
343 ss.str("2005-09-30 19:25:17-08:00");
344 ss.clear();
345 ss >> ldt;
346 //@! lw: bug in boost::date_time
347 #if HIDE_BOOST_DATETIME_BUGS
348 manualIsoTimezoneFix(ss, ldt);
349 #endif
350 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
351 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(10), ldt.date().month());
352 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(1), ldt.date().day());
353 UNITTEST_ASSERT(Equal, static_cast<int32_t>(3), ldt.utc_time().time_of_day().hours());
354 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
355 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
356 UNITTEST_ASSERT(Equal, true, 0 != ldt.zone().get());
357 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-8), ldt.zone()->base_utc_offset().hours());
358 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
359 }
360 };
361
362 struct outputIso
363 {
364 void operator()()
365 {
366 std::stringstream ss;
367 // switch locale to output ISO format
368 boost::local_time::local_time_facet* output_facet =
369 new boost::local_time::local_time_facet();
370 output_facet->format(
371 boost::local_time::local_time_facet::iso_time_format_extended_specifier
372 );
373 ss.imbue(std::locale(std::locale("C"), output_facet));
374
375 std::string str("2005-09-30 19:25:17+01:00");
376 boost::local_time::local_date_time ldt(
377 boost::posix_time::ptime(
378 boost::gregorian::date(
379 2005,
380 9,
381 30
382 ),
383 boost::posix_time::time_duration(
384 18,
385 25,
386 17
387 )
388 ),
389 boost::local_time::time_zone_ptr(
390 new boost::local_time::posix_time_zone("CET+01:00")
391 )
392 );
393
394 ss.str("");
395 ss.clear();
396 ss << ldt;
397 UNITTEST_ASSERT(Equal, str, ss.str());
398
399 str = "2005-09-30 19:25:17-08:00";
400 ldt = boost::local_time::local_date_time(
401 boost::posix_time::ptime(
402 boost::gregorian::date(
403 2005,
404 10,
405 1
406 ),
407 boost::posix_time::time_duration(
408 3,
409 25,
410 17
411 )
412 ),
413 boost::local_time::time_zone_ptr(
414 new boost::local_time::posix_time_zone("PST-08:00")
415 )
416 );
417
418 ss.str("");
419 ss.clear();
420 ss << ldt;
421 UNITTEST_ASSERT(Equal, str, ss.str());
422 }
423 };
424
425 struct inputWide
426 {
427 void operator()()
428 {
429 std::wstringstream ss;
430 boost::local_time::time_zone_ptr zone;
431 boost::local_time::local_date_time ndt(
432 boost::posix_time::not_a_date_time,
433 zone
434 );
435 boost::local_time::local_date_time ldt(
436 boost::posix_time::not_a_date_time,
437 zone
438 );
439
440 ldt = ndt;
441 ss.str(L"2005-Sep-30 19:25:17 CET+01:00");
442 ss.clear();
443 ss >> ldt;
444 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
445 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
446 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
447 UNITTEST_ASSERT(Equal, static_cast<int32_t>(18), ldt.utc_time().time_of_day().hours());
448 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
449 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
450 UNITTEST_ASSERT(Equal, static_cast<int32_t>(1), ldt.zone()->base_utc_offset().hours());
451 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
452
453 ldt = ndt;
454 ss.str(L"2005-Sep-30 19:25:17 PST-08:00");
455 ss.clear();
456 ss >> ldt;
457 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
458 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(10), ldt.date().month());
459 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(1), ldt.date().day());
460 UNITTEST_ASSERT(Equal, static_cast<int32_t>(3), ldt.utc_time().time_of_day().hours());
461 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
462 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
463 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-8), ldt.zone()->base_utc_offset().hours());
464 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
465 }
466 };
467
468 struct outputWide
469 {
470 void operator()()
471 {
472 std::wstringstream ss;
473
474 std::wstring str(L"2005-Sep-30 19:25:17 CET");
475
476 boost::local_time::local_date_time ldt(
477 boost::posix_time::ptime(
478 boost::gregorian::date(
479 2005,
480 9,
481 30
482 ),
483 boost::posix_time::time_duration(
484 18,
485 25,
486 17
487 )
488 ),
489 boost::local_time::time_zone_ptr(
490 new boost::local_time::posix_time_zone("CET+01:00")
491 )
492 );
493
494 ss.str(L"");
495 ss.clear();
496 ss << ldt;
497 UNITTEST_ASSERT(Equal,
498 iso8859_1<std::string>(str),
499 iso8859_1<std::string>(ss.str())
500 );
501
502 str = L"2005-Sep-30 19:25:17 PST";
503 ldt = boost::local_time::local_date_time(
504 boost::posix_time::ptime(
505 boost::gregorian::date(
506 2005,
507 10,
508 1
509 ),
510 boost::posix_time::time_duration(
511 3,
512 25,
513 17
514 )
515 ),
516 boost::local_time::time_zone_ptr(
517 new boost::local_time::posix_time_zone("PST-08:00")
518 )
519 );
520
521 ss.str(L"");
522 ss.clear();
523 ss << ldt;
524 UNITTEST_ASSERT(Equal,
525 iso8859_1<std::string>(str),
526 iso8859_1<std::string>(ss.str())
527 );
528 }
529 };
530
531 struct inputIsoWide
532 {
533 void operator()()
534 {
535 //@! lw: bug in boost::date_time
536 #if HIDE_BOOST_DATETIME_BUGS
537 // boost::date_time can not parse from wstream correctly in ISO format
538 return;
539 #endif
540 std::wstringstream ss;
541
542 // switch locale to read ISO format
543 boost::local_time::local_time_input_facet* input_facet =
544 new boost::local_time::local_time_input_facet();
545 input_facet->set_iso_extended_format();
546 ss.imbue(std::locale(std::locale("C"), input_facet));
547
548 boost::local_time::time_zone_ptr zone;
549 boost::local_time::local_date_time ndt(
550 boost::posix_time::not_a_date_time,
551 zone
552 );
553 boost::local_time::local_date_time ldt(
554 boost::posix_time::not_a_date_time,
555 zone
556 );
557
558 ldt = ndt;
559 ss.str(L"2005-09-30 19:25:17+01:00");
560 ss.clear();
561 ss >> ldt;
562 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
563 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
564 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
565 UNITTEST_ASSERT(Equal, static_cast<int32_t>(19), ldt.utc_time().time_of_day().hours());
566 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
567 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
568 UNITTEST_ASSERT(Equal, true, 0 != ldt.zone().get());
569 UNITTEST_ASSERT(Equal, static_cast<int32_t>(1), ldt.zone()->base_utc_offset().hours());
570 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
571
572 ldt = ndt;
573 ss.str(L"2005-09-30 19:25:17-08:00");
574 ss.clear();
575 ss >> ldt;
576 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_year>(2005), ldt.date().year());
577 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_month>(9), ldt.date().month());
578 UNITTEST_ASSERT(Equal, static_cast<boost::gregorian::greg_day>(30), ldt.date().day());
579 UNITTEST_ASSERT(Equal, static_cast<int32_t>(19), ldt.utc_time().time_of_day().hours());
580 UNITTEST_ASSERT(Equal, static_cast<int32_t>(25), ldt.utc_time().time_of_day().minutes());
581 UNITTEST_ASSERT(Equal, static_cast<int32_t>(17), ldt.utc_time().time_of_day().seconds());
582 UNITTEST_ASSERT(Equal, true, 0 != ldt.zone().get());
583 UNITTEST_ASSERT(Equal, static_cast<int32_t>(-8), ldt.zone()->base_utc_offset().hours());
584 UNITTEST_ASSERT(Equal, static_cast<int32_t>(0), ldt.zone()->base_utc_offset().minutes());
585 }
586 };
587
588 struct outputIsoWide
589 {
590 void operator()()
591 {
592 std::wstringstream ss;
593 // switch locale to output ISO format
594 boost::local_time::local_time_facet* output_facet =
595 new boost::local_time::local_time_facet();
596 output_facet->format(
597 boost::local_time::local_time_facet::iso_time_format_extended_specifier
598 );
599 ss.imbue(std::locale(std::locale("C"), output_facet));
600
601 std::wstring str(L"2005-09-30 19:25:17+01:00");
602 boost::local_time::local_date_time ldt(
603 boost::posix_time::ptime(
604 boost::gregorian::date(
605 2005,
606 9,
607 30
608 ),
609 boost::posix_time::time_duration(
610 18,
611 25,
612 17
613 )
614 ),
615 boost::local_time::time_zone_ptr(
616 new boost::local_time::posix_time_zone("CET+01:00")
617 )
618 );
619
620 ss.str(L"");
621 ss.clear();
622 ss << ldt;
623 //@! lw: bug in boost::date_time
624 #if HIDE_BOOST_DATETIME_BUGS
625 UNITTEST_ASSERT(Equal,
626 std::string("2005-Sep-30 19:25:17 CET"),
627 iso8859_1<std::string>(ss.str())
628 );
629 #else
630 UNITTEST_ASSERT(Equal,
631 iso8859_1<std::string>(str),
632 iso8859_1<std::string>(ss.str())
633 );
634 #endif
635
636 str = L"2005-09-30 19:25:17-08:00";
637 ldt = boost::local_time::local_date_time(
638 boost::posix_time::ptime(
639 boost::gregorian::date(
640 2005,
641 10,
642 1
643 ),
644 boost::posix_time::time_duration(
645 3,
646 25,
647 17
648 )
649 ),
650 boost::local_time::time_zone_ptr(
651 new boost::local_time::posix_time_zone("PST-08:00")
652 )
653 );
654
655 ss.str(L"");
656 ss.clear();
657 ss << ldt;
658 //@! lw: bug in boost::date_time
659 #if HIDE_BOOST_DATETIME_BUGS
660 UNITTEST_ASSERT(Equal,
661 std::string("2005-Sep-30 19:25:17 PST"),
662 iso8859_1<std::string>(ss.str())
663 );
664 #else
665 UNITTEST_ASSERT(Equal,
666 iso8859_1<std::string>(str),
667 iso8859_1<std::string>(ss.str())
668 );
669 #endif
670 }
671 };
672
673 BoostDateTimeTest(){
674 add(new Test<constructor>);
675 add(new Test<input>);
676 add(new Test<output>);
677 add(new Test<inputIso>);
678 add(new Test<outputIso>);
679 add(new Test<inputWide>);
680 add(new Test<outputWide>);
681 add(new Test<inputIsoWide>);
682 add(new Test<outputIsoWide>);
683 }
684};
685
686static AutoRegister<BoostDateTimeTest> ts;
687
688} /* end of namespace boost */