• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2003-2004 CrystalClear Software, Inc.
2  * Use, modification and distribution is subject to the
3  * Boost Software License, Version 1.0. (See accompanying
4  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
5  * Author: Bart Garst
6  * $Date$
7  */
8 #include <iostream>
9 #include <sstream>
10 #include <boost/date_time/gregorian/gregorian.hpp>
11 #include <boost/date_time/posix_time/posix_time.hpp>
12 #include "../testfrmwk.hpp"
13 #include <boost/lexical_cast.hpp>
14 
15 using namespace boost::gregorian;
16 using namespace boost::posix_time;
17 using boost::lexical_cast;
18 
main()19 int main(){
20 #if defined(BOOST_NO_STD_WSTRING) || \
21     defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
22   check("No wstring/wstream support for this compiler", false);
23 #else
24 
25   std::wstring res, ws;
26   std::wstringstream wss;
27   /* time_period was used because all the time-type objects
28    * that have operator<< can be easily accessed from it.
29    * Tose are: ptime, time_duration, time_period */
30   date d1(2003,Jan,20), d2(2003,May,10);
31   time_period tp(ptime(d1,hours(1)), ptime(d2,hours(15)));
32 
33   // ptime
34   wss << tp.begin();
35   res = L"2003-Jan-20 01:00:00";
36   check("ptime op<<", res == wss.str());
37   wss.str(L"");
38   ws = to_simple_wstring(tp.begin());
39   check("ptime to_simple_wstring", res == ws);
40   res = L"20030120T010000";
41   ws = to_iso_wstring(tp.begin());
42   check("ptime to_iso_wstring", res == ws);
43   res = L"2003-01-20T01:00:00";
44   ws = to_iso_extended_wstring(tp.begin());
45   check("ptime to_iso_extended_wstring", res == ws);
46 
47   // time_duration
48   wss << tp.length();
49   res = L"2654:00:00";
50   check("time_duration", res == wss.str());
51   wss.str(L"");
52   ws = to_simple_wstring(tp.length());
53   check("time_duration to_simple_wstring", res == ws);
54   res = L"26540000";
55   ws = to_iso_wstring(tp.length());
56   check("time_duration to_iso_wstring", res == ws);
57 
58   // time_period
59   wss << tp;
60 #ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
61   res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999999]";
62 #else
63   res = L"[2003-Jan-20 01:00:00/2003-May-10 14:59:59.999999]";
64 #endif
65   check("time_period", res == wss.str());
66   wss.str(L"");
67   ws = to_simple_wstring(tp);
68   check("time_period to_simple_wstring", res == ws);
69 
70   // special values
71   time_duration sv_td(neg_infin);
72   date sv_d(pos_infin);
73   ptime sv_tp(sv_d,hours(1));
74   res = L"+infinity";
75   wss << sv_tp;
76   check("ptime op<< special value", res == wss.str());
77   wss.str(L"");
78   ws = to_simple_wstring(sv_tp);
79   check("ptime to_simple_wstring special value", res == ws);
80   res = L"-infinity";
81   wss << sv_td;
82   check("time_duration op<< special value", res == wss.str());
83   wss.str(L"");
84   ws = to_simple_wstring(sv_td);
85   check("time_duration to_simple_wstring special value", res == ws);
86 
87 #endif
88   return printTestStats();
89 }
90