1 /* Copyright (c) 2002,2003 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: Jeff Garland, Bart Garst
6 */
7
8 #include "boost/date_time/gregorian/gregorian.hpp"
9 #include "../testfrmwk.hpp"
10
11 int
main()12 main()
13 {
14
15 boost::gregorian::date d1(2002,01,02);
16 std::string ds1 = boost::gregorian::to_simple_string(d1);
17 check("check string: " + ds1, ds1 == "2002-Jan-02");
18
19 std::string ids1(boost::gregorian::to_iso_string(d1));
20 // std::cout << boost::gregorian::to_iso_string(d1) << std::endl;
21 check("check iso normal: " + ids1, ids1 == "20020102");
22
23 std::string sds1 = boost::gregorian::to_sql_string(d1);
24 check("check sql string: "+sds1, sds1 == "2002-01-02");
25
26 boost::gregorian::date d2(2001,12,30);
27 std::string ds2 = boost::gregorian::to_simple_string(d2);
28 check("check string: "+ds2, ds2 == "2001-Dec-30");
29 std::string ids2 = boost::gregorian::to_iso_extended_string(d2);
30 check("check iso extended string: "+ids2, ids2 == "2001-12-30");
31
32 using namespace boost::gregorian;
33 date d3(neg_infin);
34 std::cout << "|" << to_simple_string(d3) << "|" << std::endl;
35 check("check negative infinity",
36 (to_simple_string(d3) == std::string("-infinity")));
37 date d4(pos_infin);
38 check("check positive infinity",
39 (to_simple_string(d4) == std::string("+infinity")));
40 date d5(not_a_date_time);
41 std::cout << to_simple_string(d5) << "|" << std::endl;
42 check("check not a date",
43 (to_simple_string(d5) == std::string("not-a-date-time")));
44
45 date_period p1(date(2000,Jan,1), date(2001,Jan,1));
46 check("check period format",
47 (to_simple_string(p1) == std::string("[2000-Jan-01/2000-Dec-31]")));
48 date_period p2(date(2000,Jan,1), date(pos_infin));
49 check("check period format",
50 (to_simple_string(p2) == std::string("[2000-Jan-01/+infinity]")));
51 std::cout << to_simple_string(p2) << std::endl;
52
53
54
55 // TODO enhance wchar support
56 // std::wstringstream wss;
57 // wss << d3 << std::endl;
58 // std::wcout << d3;
59 return printTestStats();
60
61 }
62
63