File: testformatters.cpp

package info (click to toggle)
boost 1.34.1-14
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 116,412 kB
  • ctags: 259,566
  • sloc: cpp: 642,395; xml: 56,450; python: 17,612; ansic: 14,520; sh: 2,265; yacc: 858; perl: 481; makefile: 478; lex: 94; sql: 74; csh: 6
file content (62 lines) | stat: -rw-r--r-- 2,198 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Copyright (c) 2002,2003 CrystalClear Software, Inc.
 * Use, modification and distribution is subject to the 
 * Boost Software License, Version 1.0. (See accompanying
 * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
 * Author: Jeff Garland, Bart Garst
 */

#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/date_time/testfrmwk.hpp"

int
main() 
{

  boost::gregorian::date d1(2002,01,02);
  std::string ds1 = boost::gregorian::to_simple_string(d1);
  check("check string:     " + ds1, ds1 == "2002-Jan-02");
 
  std::string ids1(boost::gregorian::to_iso_string(d1));
  //  std::cout << boost::gregorian::to_iso_string(d1) << std::endl;
  check("check iso normal: " + ids1, ids1 == "20020102");

  std::string sds1 = boost::gregorian::to_sql_string(d1);
  check("check sql string: "+sds1, sds1 == "2002-01-02");

  boost::gregorian::date d2(2001,12,30);
  std::string ds2 = boost::gregorian::to_simple_string(d2);
  check("check string:     "+ds2, ds2 == "2001-Dec-30");
  std::string ids2 = boost::gregorian::to_iso_extended_string(d2);
  check("check iso extended string: "+ids2, ids2 == "2001-12-30");

  using namespace boost::gregorian;
  date d3(neg_infin);
  std::cout  << "|" << to_simple_string(d3) << "|" << std::endl;
  check("check negative infinity",     
        (to_simple_string(d3) == std::string("-infinity")));
  date d4(pos_infin);
  check("check positive infinity",     
        (to_simple_string(d4) == std::string("+infinity")));
  date d5(not_a_date_time);
  std::cout << to_simple_string(d5) << "|" << std::endl;
  check("check not a date",     
        (to_simple_string(d5) == std::string("not-a-date-time")));

  date_period p1(date(2000,Jan,1), date(2001,Jan,1));
  check("check period format",     
        (to_simple_string(p1) == std::string("[2000-Jan-01/2000-Dec-31]")));
  date_period p2(date(2000,Jan,1), date(pos_infin));
  check("check period format",     
        (to_simple_string(p2) == std::string("[2000-Jan-01/+infinity]")));
  std::cout << to_simple_string(p2) << std::endl;

  

  //  TODO enhance wchar support 
//   std::wstringstream wss;
//   wss << d3 << std::endl;
//   std::wcout << d3;
  return printTestStats();

}