1 /* Copyright (c) 2003-2005 CrystalClear Software, Inc.
2 * Subject to the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
4 * Author: Jeff Garland, Bart Garst
9 #include "../testfrmwk.hpp"
10 #include "boost/date_time/gregorian/gregorian.hpp"
11 #include "boost/date_time/posix_time/posix_time.hpp"
12 #include "boost/date_time/local_time/custom_time_zone.hpp"
13 #include "boost/date_time/local_time/local_time_types.hpp"
14 #include "boost/date_time/local_time/tz_database.hpp"
15 #include "boost/date_time/local_time/posix_time_zone.hpp"
18 bool run_bad_field_count_test(char const* fn
);
20 int main(int /* argc */, char const* argv
[]){
21 using namespace boost::gregorian
;
22 using namespace boost::posix_time
;
23 using namespace boost::local_time
;
25 /* NOTE: The testlocal_time_facet tests required full names
26 * be added to some of the date_time_zonespec.csv entries. The
27 * tests here also use those full names. Those entries are:
28 * Chicago, Denver, Los_Angeles, New_York, and Phoenix
29 * have all had full names added */
31 // run the exception tests first
34 tz_db
.load_from_file("missing_file.csv"); // file does not exist
35 }catch(data_not_accessible
&){
36 check("Caught Missing data file exception", true);
38 check("Caught first unexpected exception", false);
40 check("Caught Bad field count exception", run_bad_field_count_test(argv
[2]));
44 tz_db
.load_from_file(argv
[1]);
46 check("Cannot locate data file - aborting.", false);
47 return printTestStats();
50 time_zone_ptr bad_tz
= tz_db
.time_zone_from_region("Invalid/name");
51 check("Expected null pointer return", bad_tz
== time_zone_ptr());
53 time_zone_ptr nyc_test
= tz_db
.time_zone_from_region("America/New_York");
54 check("nyc Valid pointer", nyc_test
!= time_zone_ptr() );
55 check("nyc Abbreviations",nyc_test
->std_zone_abbrev() == std::string("EST"));
56 check("nyc Full Name", nyc_test
->std_zone_name() == std::string("Eastern Standard Time"));
57 check("nyc Abbreviations",nyc_test
->dst_zone_abbrev() == std::string("EDT"));
58 //std::cout << nyc_test->std_zone_name() << std::endl;
59 check("nyc Full Name", nyc_test
->dst_zone_name() == std::string("Eastern Daylight Time"));
60 check("nyc GMT Offset", nyc_test
->base_utc_offset() == hours(-5));
61 check("nyc DST Offset", nyc_test
->dst_offset() == hours(1));
62 //std::cout << nyc_test->dst_local_start_time(2004) << std::endl;
63 check("nyc dst start", nyc_test
->dst_local_start_time(2007) == ptime(date(2007, Mar
, 11), hours(2)));
64 check("nyc dst end", nyc_test
->dst_local_end_time(2007) == ptime(date(2007, Nov
, 4), hours(2)));
65 check("nyc has dst", nyc_test
->has_dst());
67 time_zone_ptr phx_test
= tz_db
.time_zone_from_region("America/Phoenix");
68 check("az Valid pointer", phx_test
!= time_zone_ptr() );
69 check("az Abbreviations",phx_test
->std_zone_abbrev() == std::string("MST"));
70 check("az Full Name", phx_test
->std_zone_name() == std::string("Mountain Standard Time"));
71 check("az Abbreviations", phx_test
->dst_zone_abbrev() == std::string(""));
72 check("az Full Name", phx_test
->dst_zone_name() == std::string(""));
73 check("az GMT Offset", phx_test
->base_utc_offset() == hours(-7));
74 check("az DST Offset", phx_test
->dst_offset() == hours(0));
75 //std::cout << phx_test->dst_local_start_time(2004) << std::endl;
76 check("az has dst", phx_test
->has_dst() == false);
78 //Now add and retrieve a Posix tz spec from the database
79 time_zone_ptr
eastern(new posix_time_zone("EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00"));
80 tz_db
.add_record("United States/Eastern", eastern
);
81 time_zone_ptr eastern_test
= tz_db
.time_zone_from_region("United States/Eastern");
82 check("eastern Valid pointer", eastern_test
!= time_zone_ptr() );
83 check("eastern Abbreviations",
84 eastern_test
->std_zone_abbrev() == std::string("EST"));
85 check("eastern Abbreviations",
86 eastern_test
->std_zone_name() == std::string("EST"));
87 check("eastern Abbreviations",
88 eastern_test
->dst_zone_abbrev() == std::string("EDT"));
89 check("eastern Abbreviations",
90 eastern_test
->dst_zone_name() == std::string("EDT"));
91 check("eastern GMT Offset", eastern_test
->base_utc_offset() == hours(-5));
92 check("eastern dst start", eastern_test
->dst_local_start_time(2004) == ptime(date(2004, Apr
, 4), hours(2)));
93 check("eastern dst end", eastern_test
->dst_local_end_time(2004) == ptime(date(2004, Oct
, 31), hours(2)));
94 check("eastern has dst", eastern_test
->has_dst() == true);
97 return printTestStats();
100 /* This test only checks to make sure the bad_field_count exception
101 * is properly thrown. It does not pay any attention to any other
102 * exception, those are tested elsewhere. */
103 bool run_bad_field_count_test(char const* fn
)
105 using namespace boost::local_time
;
106 bool caught_bfc
= false;
107 tz_database other_db
;
109 other_db
.load_from_file(fn
);
110 }catch(bad_field_count
&){
113 // do nothing (file not found)