summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/date_time/test/local_time
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/date_time/test/local_time
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/date_time/test/local_time')
-rw-r--r--src/boost/libs/date_time/test/local_time/README.poorly_formed_zonespec4
-rw-r--r--src/boost/libs/date_time/test/local_time/poorly_formed_zonespec.csv2
-rw-r--r--src/boost/libs/date_time/test/local_time/testclocks.cpp40
-rw-r--r--src/boost/libs/date_time/test/local_time/testcustom_time_zone.cpp88
-rw-r--r--src/boost/libs/date_time/test/local_time/testdst_transition_day_rule.cpp65
-rw-r--r--src/boost/libs/date_time/test/local_time/testlocal_time.cpp370
-rw-r--r--src/boost/libs/date_time/test/local_time/testlocal_time_facet.cpp188
-rw-r--r--src/boost/libs/date_time/test/local_time/testlocal_time_input_facet.cpp239
-rw-r--r--src/boost/libs/date_time/test/local_time/testlocal_time_iterator.cpp95
-rw-r--r--src/boost/libs/date_time/test/local_time/testlocal_time_period.cpp82
-rw-r--r--src/boost/libs/date_time/test/local_time/testposix_time_zone.cpp221
-rw-r--r--src/boost/libs/date_time/test/local_time/testtz_database.cpp116
-rw-r--r--src/boost/libs/date_time/test/local_time/testwcustom_time_zone.cpp89
-rw-r--r--src/boost/libs/date_time/test/local_time/testwposix_time_zone.cpp224
14 files changed, 1823 insertions, 0 deletions
diff --git a/src/boost/libs/date_time/test/local_time/README.poorly_formed_zonespec b/src/boost/libs/date_time/test/local_time/README.poorly_formed_zonespec
new file mode 100644
index 000000000..b417cc8a6
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/README.poorly_formed_zonespec
@@ -0,0 +1,4 @@
+The file "poorly_formed_zonespec.csv" is only used for testing.
+
+This file has the wrong number of fields in it and should not be used for
+any other prupose.
diff --git a/src/boost/libs/date_time/test/local_time/poorly_formed_zonespec.csv b/src/boost/libs/date_time/test/local_time/poorly_formed_zonespec.csv
new file mode 100644
index 000000000..d5eb87149
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/poorly_formed_zonespec.csv
@@ -0,0 +1,2 @@
+"ID","STD ABBR","STD NAME","DST ABBR","DST NAME","GMT offset","DST adjustment","DST Start Date rule","Start time","DST End date rule","End time"
+"Unique/Zone_name","GMT","","+00:00:00"
diff --git a/src/boost/libs/date_time/test/local_time/testclocks.cpp b/src/boost/libs/date_time/test/local_time/testclocks.cpp
new file mode 100644
index 000000000..6744631e2
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testclocks.cpp
@@ -0,0 +1,40 @@
+/* Copyright (c) 2003-2004 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include "boost/date_time/local_time/local_time.hpp"
+#include <iostream>
+
+// The actual clocks are tested in posix_time/testclock.cpp.
+// These tests are to verify that the time zone is applied correctly
+
+int
+main()
+{
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+
+
+ boost::shared_ptr<time_zone> az_tz(new posix_time_zone("MST-07"));
+ boost::shared_ptr<time_zone> ny_tz(new posix_time_zone("EST-05EDT,M4.1.0,M10.5.0"));
+
+ ptime tl = second_clock::local_time();
+ std::cout << tl << std::endl;
+ local_date_time ldt1 = local_sec_clock::local_time(az_tz);
+ std::cout << ldt1.to_string() << std::endl;
+ local_date_time ldt2 = local_sec_clock::local_time(ny_tz);
+ std::cout << ldt2.to_string() << std::endl;
+
+ tl = microsec_clock::local_time();
+ std::cout << tl << std::endl;
+ local_date_time ldt3 = local_microsec_clock::local_time(az_tz);
+ std::cout << ldt3.to_string() << std::endl;
+ local_date_time ldt4 = local_microsec_clock::local_time(ny_tz);
+ std::cout << ldt4.to_string() << std::endl;
+
+ return 0;
+}
diff --git a/src/boost/libs/date_time/test/local_time/testcustom_time_zone.cpp b/src/boost/libs/date_time/test/local_time/testcustom_time_zone.cpp
new file mode 100644
index 000000000..c45965e55
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testcustom_time_zone.cpp
@@ -0,0 +1,88 @@
+/* Copyright (c) 2003-2005 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+#include <iostream>
+
+int
+main()
+{
+
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+
+
+ boost::shared_ptr<dst_calc_rule>
+ rule1(new partial_date_dst_rule(partial_date(30,Apr),
+ partial_date(30,Oct)));
+
+ boost::shared_ptr<dst_calc_rule>
+ rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr),
+ first_last_dst_rule::end_rule(Sunday,Oct)));
+ boost::shared_ptr<dst_calc_rule>
+ rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar),
+ last_last_dst_rule::end_rule(Sunday,Oct)));
+ boost::shared_ptr<dst_calc_rule> rule4; // no daylight savings
+
+ time_zone_names pst("Pacific Standard Time",
+ "PST",
+ "Pacific Daylight Time" ,
+ "PDT");
+ time_zone_names mst("Mountain Standard Time",
+ "MST",
+ "" ,
+ "");
+
+ dst_adjustment_offsets of(hours(1), hours(2), hours(2));
+ dst_adjustment_offsets of2(hours(0), hours(0), hours(0)); // no daylight savings
+
+ time_zone_ptr tz1(new custom_time_zone(pst, hours(-8), of, rule1));
+ time_zone_ptr tz2(new custom_time_zone(pst, hours(-8), of, rule2));
+ time_zone_ptr tz3(new custom_time_zone(pst, hours(-8), of, rule3));
+ time_zone_ptr tz4(new custom_time_zone(mst, hours(-7), of2, rule4));
+
+ check("out string",
+ tz1->dst_zone_abbrev() == std::string("PDT"));
+ check("out string",
+ tz1->std_zone_abbrev() == std::string("PST"));
+ check("out string",
+ tz1->std_zone_name() == std::string("Pacific Standard Time"));
+ check("out string",
+ tz1->dst_zone_name() == std::string("Pacific Daylight Time"));
+
+ check("dst offset", tz1->dst_offset() == hours(1));
+ check("base offset", tz1->base_utc_offset() == hours(-8));
+ check("has dst", tz1->has_dst());
+
+ check("dst start time",
+ tz1->dst_local_start_time(2003) == ptime(date(2003,Apr,30),hours(2)));
+ check("dst end time",
+ tz1->dst_local_end_time(2003) == ptime(date(2003,Oct,30),hours(2)));
+
+ check("tz1 to posix string",
+ tz1->to_posix_string() == std::string("PST-08PDT+01,120/02:00,303/02:00"));
+ check("tz2 to posix string",
+ tz2->to_posix_string() == std::string("PST-08PDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+ check("tz3 to posix string",
+ tz3->to_posix_string() == std::string("PST-08PDT+01,M3.5.0/02:00,M10.5.0/02:00"));
+ check("tz4 to posix string",
+ tz4->to_posix_string() == std::string("MST-07"));
+
+ // test start/end for non-dst zone
+ check("has dst in non-dst zone", !tz4->has_dst());
+ check("dst start in non-dst zone",
+ tz4->dst_local_start_time(2005) == ptime(not_a_date_time));
+ check("dst end in non-dst zone",
+ tz4->dst_local_end_time(2005) == ptime(not_a_date_time));
+
+
+ return printTestStats();
+}
+
+
diff --git a/src/boost/libs/date_time/test/local_time/testdst_transition_day_rule.cpp b/src/boost/libs/date_time/test/local_time/testdst_transition_day_rule.cpp
new file mode 100644
index 000000000..d3ca19afa
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testdst_transition_day_rule.cpp
@@ -0,0 +1,65 @@
+/* Copyright (c) 2003-2004 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include "boost/date_time/gregorian/gregorian.hpp"
+#include "boost/date_time/local_time/dst_transition_day_rules.hpp"
+#include "boost/shared_ptr.hpp"
+#include "../testfrmwk.hpp"
+
+
+
+// see http://www.timeanddate.com/time/aboutdst.html for some info
+// also
+int
+main()
+{
+ // using namespace boost::posix_time;
+ using namespace boost::local_time;
+ using namespace boost::gregorian;
+
+ boost::shared_ptr<dst_calc_rule>
+ rule1(new partial_date_dst_rule(partial_date(30,Apr),
+ partial_date(30,Oct)));
+
+ check("partial date rule", rule1->start_day(2001) == date(2001, Apr, 30));
+ check("partial date rule", rule1->end_day(2001) == date(2001, Oct, 30));
+
+ boost::shared_ptr<dst_calc_rule>
+ rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr),
+ first_last_dst_rule::end_rule(Sunday,Oct)));
+
+ check("first last rule", rule2->start_day(2001) == date(2001, Apr, 1));
+ check("first last rule", rule2->end_day(2001) == date(2001, Oct, 28));
+
+ boost::shared_ptr<dst_calc_rule>
+ rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar),
+ last_last_dst_rule::end_rule(Sunday,Oct)));
+
+ check("last last rule", rule3->start_day(2001) == date(2001, Mar, 25));
+ check("last last rule", rule3->end_day(2001) == date(2001, Oct, 28));
+
+ typedef nth_kday_of_month nkday;
+ boost::shared_ptr<dst_calc_rule>
+ rule4(new nth_last_dst_rule(nth_last_dst_rule::start_rule(nkday::first,Sunday,Mar),
+ nth_last_dst_rule::end_rule(Sunday,Oct)));
+
+ check("nth Last rule", rule4->start_day(2001) == date(2001, Mar, 4));
+ check("nth Last rule", rule4->end_day(2001) == date(2001, Oct, 28));
+
+ boost::shared_ptr<dst_calc_rule>
+ rule5(new nth_kday_dst_rule(nth_kday_dst_rule::start_rule(nkday::first,Sunday,Mar),
+ nth_kday_dst_rule::end_rule(nkday::fourth,Sunday,Oct)));
+
+ check("nth_kday rule", rule5->start_day(2001) == date(2001, Mar, 4));
+ check("nth_kday rule", rule5->end_day(2001) == date(2001, Oct, 28));
+
+
+
+ return printTestStats();
+
+}
+
diff --git a/src/boost/libs/date_time/test/local_time/testlocal_time.cpp b/src/boost/libs/date_time/test/local_time/testlocal_time.cpp
new file mode 100644
index 000000000..058090fc0
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testlocal_time.cpp
@@ -0,0 +1,370 @@
+/* Copyright (c) 2003-2005 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+
+#include "boost/date_time/local_time/custom_time_zone.hpp"
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include "boost/date_time/local_time/local_time.hpp"
+// #include "boost/date_time/local_time/posix_time_zone.hpp"
+#include "../testfrmwk.hpp"
+//#include "boost/date_time/c_time.hpp"
+#include <iostream>
+
+#include <sstream>
+// function eases testing
+std::string tm_out(const tm& ptr){
+ std::stringstream ss;
+
+ ss
+ << ptr.tm_wday << ' ' << ptr.tm_yday << ' '
+ << std::setw(2) << std::setfill('0') << ptr.tm_mon + 1 << '/'
+ << std::setw(2) << std::setfill('0') << ptr.tm_mday << '/'
+ << std::setw(2) << std::setfill('0') << ptr.tm_year + 1900 << ' '
+ << std::setw(2) << std::setfill('0') << ptr.tm_hour << ':'
+ << std::setw(2) << std::setfill('0') << ptr.tm_min << ':'
+ << std::setw(2) << std::setfill('0') << ptr.tm_sec << ' ';
+ if(ptr.tm_isdst >= 0){
+ ss << (ptr.tm_isdst ? "DST" : "STD");
+ }
+ else{
+ ss << "DST/STD unknown";
+ }
+ return ss.str();
+}
+
+int
+main()
+{
+
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+
+ // since local_date_time inherits it's math operations from time, the
+ // tests here only show that the operations work. The thorough testing
+ // of these operations is done in the posix_time tests
+
+ try {
+ time_zone_ptr az_tz(new posix_time_zone("MST-07"));
+ time_zone_ptr ny_tz(new posix_time_zone("EST-05EDT,M4.1.0,M10.5.0"));
+ // EST & EST for sydney is correct, according to zoneinfo files
+ time_zone_ptr sydney(new posix_time_zone("EST+10EST,M10.5.0,M3.5.0/03:00"));
+ time_zone_ptr null_tz;
+ date d(2003, 12, 20);
+ hours h(12);
+ ptime t(d,h);
+ local_date_time az_time(t, az_tz); // ptime constructor is a UTC time
+
+ check("Zone abbreviation", az_time.zone()->std_zone_abbrev() == std::string("MST"));
+ check("base offset", az_time.zone()->base_utc_offset() == hours(-7));
+ check("zone has dst", az_time.zone()->has_dst() == false);
+ check("is_dst check", az_time.is_dst() == false);
+ check("to_string: " + az_time.to_string(),
+ az_time.to_string() == "2003-Dec-20 05:00:00 MST");
+
+
+
+ std::cout << "\nChecking copy construction" << std::endl;
+ local_date_time az_time2(az_time); //copy constructor
+ // Now test the copy
+ check("is_dst check", az_time2.is_dst() == false);
+ check("to_string: " + az_time2.to_string(),
+ az_time2.to_string() == "2003-Dec-20 05:00:00 MST");
+ check("zone has dst", az_time2.zone()->has_dst() == false);
+ check("base offset", az_time2.zone()->base_utc_offset() == hours(-7));
+
+
+ std::cout << "\nChecking special_value construction" << std::endl;
+ // since local_date_time inherits its special value operatorations
+ // from time, we only need to show here that they work as thorough
+ // testing is done in the posix_time tests
+ ptime svpt(not_a_date_time);
+ local_date_time sv_time(svpt, ny_tz);
+ check("is special_value", sv_time.is_not_a_date_time());
+ check("to_string: " + sv_time.to_string(),
+ sv_time.to_string() == "not-a-date-time");
+ check("is_dst", sv_time.is_dst() == false);
+ local_date_time sv_time2(pos_infin);
+ check("is special_value", sv_time2.is_pos_infinity());
+ check("to_string: " + sv_time2.to_string(),
+ sv_time2.to_string() == "+infinity");
+ check("is_dst", sv_time2.is_dst() == false);
+ sv_time2 += days(12); // add a duration to a special value
+ check("Add a duration to a special value", sv_time2.is_pos_infinity());
+
+ local_date_time sv_time3(max_date_time, ny_tz);
+#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
+ check("max_date_time to_string: " + sv_time3.to_string(),
+ sv_time3.to_string() == "9999-Dec-31 18:59:59.999999999 EST");
+#else
+ check("max_date_time to_string: " + sv_time3.to_string(),
+ sv_time3.to_string() == "9999-Dec-31 18:59:59.999999 EST");
+#endif
+
+ try {
+ local_date_time sv_time4(min_date_time);
+ check("min_date_time to_string: " + sv_time4.to_string(),
+ sv_time4.to_string() == "1400-Jan-01 00:00:00 UTC");
+ }
+ catch (std::exception& e) {
+ check("min_date_time to_string -- exception" , false);
+ std::cout << "Exception is : " << e.what() << std::endl;
+ }
+
+/** todo -- this will cause an out of range when min_date is adjusted for ny_tz
+ local_date_time sv_time5(min_date_time, ny_tz);
+ std::cout << sv_time5.to_string() << std::endl;
+**/
+
+ std::cout << "\nChecking calc_options construction" << std::endl;
+ { // invalid NADT
+ date dx(2004, Apr, 4);
+ time_duration td(2,30,0); // invalid local time in ny_tz
+ local_date_time calcop(dx, td, ny_tz, local_date_time::NOT_DATE_TIME_ON_ERROR);
+ check("is NADT", calcop.is_not_a_date_time());
+ }
+ { // invalid exception
+ date dx(2004, Apr, 4);
+ time_duration td(2,30,0); // invalid local time in ny_tz
+ try{
+ local_date_time calcop(dx, td, ny_tz, local_date_time::EXCEPTION_ON_ERROR);
+ check("Did not catch expected exception", false);
+ }catch(time_label_invalid& /*i*/){
+ check("Caught expected exception", true);
+ }catch(...){
+ check("Caught unexpected exception", false);
+ }
+ }
+ { // ambig NADT
+ date dx(2004, Oct, 31);
+ time_duration td(1,30,0); // ambig local time in ny_tz
+ local_date_time calcop(dx, td, ny_tz, local_date_time::NOT_DATE_TIME_ON_ERROR);
+ check("is NADT", calcop.is_not_a_date_time());
+ }
+ { // ambig exception
+ date dx(2004, Oct, 31);
+ time_duration td(1,30,0); // ambig local time in ny_tz
+ try{
+ local_date_time calcop(dx, td, ny_tz, local_date_time::EXCEPTION_ON_ERROR);
+ check("Did not catch expected exception", false);
+ }catch(ambiguous_result& /*a*/){
+ check("Caught expected exception", true);
+ }catch(...){
+ check("Caught unexpected exception", false);
+ }
+ }
+
+
+ //Now construct with a date and time
+ std::cout << "\nChecking construct with date and time_duration" << std::endl;
+ local_date_time az_time3(d, h, az_tz, false);
+ check("Zone abbreviation", az_time3.zone()->std_zone_abbrev() == std::string("MST"));
+ check("base offset", az_time3.zone()->base_utc_offset() == hours(-7));
+ check("base offset", az_time3.zone()->has_dst() == false);
+ check("is_dst check", az_time3.is_dst() == false);
+ check("to_string: " + az_time3.to_string(),
+ az_time3.to_string() == "2003-Dec-20 12:00:00 MST");
+
+ // construct with a null tz
+ //local_date_time null_tz_time(d, h, null_tz, false);
+ local_date_time null_tz_time(d, h, null_tz, true);
+ // TODO: how to handle calls to null_tz_time.zone()->...
+ check("is_dst check", null_tz_time.is_dst() == false);
+ check("to_string: " + null_tz_time.to_string(),
+ null_tz_time.to_string() == "2003-Dec-20 12:00:00 UTC");
+
+ //Now construct with a date and time - invalid parameters
+ try{
+ local_date_time blt(d, h, ny_tz, true);
+ check("Did not catch expected exception (dst_not_valid)", false);
+ }catch(dst_not_valid& e){
+ check(std::string("Caught expected exception (dst_not_valid) ") + e.what(), true);
+ }catch(std::exception& e){
+ check(std::string("Caught unexpected exception ") + e.what(), false);
+ }
+ try{
+ local_date_time blt(date(2004,Apr,4), time_duration(2,30,0), ny_tz, true);
+ check("Did not catch expected exception (Invalid_Time_Label)", false);
+ }catch(time_label_invalid& e){
+ check(std::string("Caught expected exception (Invalid_Time_Label) ") + e.what(), true);
+ }catch(std::exception& e){
+ check(std::string("Caught unexpected exception ") + e.what(), false);
+ }
+
+
+ // thorough is_dst() tests, tests againts null_tz and non dst tz are
+ // done where those local times were tested
+ {
+ date dx(2004,Apr,4);
+ time_duration td(1,15,0); // local
+ local_date_time lt1(dx,td,ny_tz,false);
+ local_date_time lt2(ptime(dx,time_duration(6,15,0)), ny_tz);
+ check("are local_times equal", lt1.utc_time() == lt2.utc_time());
+ check("is_dst - transition in 1", lt1.is_dst() == false);
+ check("is_dst - transition in 2", lt2.is_dst() == false);
+ lt1 += hours(1);
+ lt2 += hours(1);
+ check("is_dst - transition in 1", lt1.is_dst() == true);
+ check("is_dst - transition in 2", lt2.is_dst() == true);
+ }
+ {
+ date dx(2004,Oct,31);
+ time_duration td(1,15,0); // local
+ local_date_time lt1(dx,td,ny_tz,true);
+ /*try{
+ //local_date_time lt1(dx,td,ny_tz,false);
+ local_date_time lt1(dx,td,ny_tz,true);
+ std::cout << "no exception thrown" << std::endl;
+ }catch(time_label_invalid& e){
+ std::cout << "caught: " << e.what() << std::endl;
+ }*/
+ local_date_time lt2(ptime(dx,time_duration(5,15,0)), ny_tz);
+ check("are local_times equal", lt1.utc_time() == lt2.utc_time());
+ check("is_dst - transition out 1", lt1.is_dst() == true);
+ check("is_dst - transition out 2", lt2.is_dst() == true);
+ lt1 += hours(1);
+ lt2 += hours(1);
+ check("is_dst - transition out 1", lt1.is_dst() == false);
+ check("is_dst - transition out 2", lt2.is_dst() == false);
+ }
+ { // southern hemisphere
+ date dx(2004,Oct,31);
+ time_duration td(1,15,0); // local
+ local_date_time lt1(dx,td,sydney,false);
+ check("is_dst - transition in (sydney)", lt1.is_dst() == false);
+ lt1 += hours(1);
+ check("is_dst - transition in (sydney)", lt1.is_dst() == true);
+ }
+ {
+ date dx(2004,Mar,28);
+ time_duration td(2,15,0); // local; sydney has a weird trans time
+ local_date_time lt1(dx,td,sydney,true);
+ check("is_dst - transition out (sydney)", lt1.is_dst() == true);
+ lt1 += hours(1);
+ check("is_dst - transition out (sydney)", lt1.is_dst() == false);
+ }
+
+
+
+ std::cout << "\nTest conversion of time zone from Arizona to New York" << std::endl;
+ local_date_time ny_time = az_time.local_time_in(ny_tz);
+ check("Zone abbreviation", ny_time.zone()->std_zone_abbrev() == std::string("EST"));
+ check("base offset", ny_time.zone()->base_utc_offset() == hours(-5));
+ check("base offset", ny_time.zone()->has_dst() == true);
+ check("to_string: " + ny_time.to_string(),
+ ny_time.to_string() == "2003-Dec-20 07:00:00 EST");
+ ny_time += hours(3);
+ check("to_string after add 3 hours: " + ny_time.to_string(),
+ ny_time.to_string() == "2003-Dec-20 10:00:00 EST");
+ ny_time += days(3);
+ check("to_string after add 3 days: " + ny_time.to_string(),
+ ny_time.to_string() == "2003-Dec-23 10:00:00 EST");
+
+
+ { // test comparisons & math operations
+ date dx(2003, Aug, 28);
+ ptime sv_pt(pos_infin);
+ local_date_time sv_lt(sv_pt, ny_tz);
+ ptime utc_pt(dx, hours(12));
+ // all 4 of the following local times happen at the same instant
+ // so they are all equal
+ local_date_time utc_lt(utc_pt, null_tz); // noon in utc
+ local_date_time az_lt(dx, hours(5), az_tz, false); // 5am local std
+ local_date_time ny_lt(dx, hours(8), ny_tz, true); // 8am local dst
+ local_date_time au_lt(dx, hours(22), sydney, false);// 10pm local std
+
+ check("local_date_time to tm",
+ std::string("4 239 08/28/2003 05:00:00 STD") == tm_out(to_tm(az_lt)));
+ check("local_date_time to tm",
+ std::string("4 239 08/28/2003 08:00:00 DST") == tm_out(to_tm(ny_lt)));
+ check("local_date_time to tm",
+ std::string("4 239 08/28/2003 22:00:00 STD") == tm_out(to_tm(au_lt)));
+
+ try{
+ local_date_time ldt(not_a_date_time);
+ tm ldt_tm = to_tm(ldt);
+ check("Exception not thrown (special_value to_tm)", false);
+ //does nothing useful but stops compiler from complaining about unused ldt_tm
+ std::cout << ldt_tm.tm_sec << std::endl;
+ }catch(std::out_of_range&){
+ check("Caught expected exception (special_value to_tm)", true);
+ }catch(...){
+ check("Caught un-expected exception (special_value to_tm)", false);
+ }
+ // check that all are equal to sv_pt
+ check("local == utc", az_lt == utc_lt);
+ check("local == utc", ny_lt == utc_lt);
+ check("local == utc", au_lt == utc_lt);
+ check("local <= utc", au_lt <= utc_lt);
+ check("local >= utc", au_lt >= utc_lt);
+ check("local == local", az_lt == ny_lt);
+ check("local < local", az_lt < ny_lt+seconds(1));
+ check("local > local", az_lt+seconds(1) > ny_lt);
+ check("local <= local", az_lt <= ny_lt);
+ check("local >= local", az_lt >= ny_lt);
+ check("local != local", az_lt+seconds(1) != ny_lt);
+
+ au_lt += hours(1);
+ check("local != after +=", au_lt != utc_lt);
+ check("local <= after +=", utc_lt <= au_lt);
+ check("local >= after +=", au_lt >= utc_lt);
+ check("local < after +=", utc_lt < au_lt);
+ check("local > after +=", au_lt > utc_lt);
+ au_lt -= hours(1);
+ check("local == utc after -=", au_lt == utc_lt);
+
+ check("local + days",
+ (az_lt + days(2)).to_string() == "2003-Aug-30 05:00:00 MST");
+ check("local - days",
+ (az_lt - days(2)).to_string() == "2003-Aug-26 05:00:00 MST");
+ check("local += days",
+ (az_lt += days(2)).to_string() == "2003-Aug-30 05:00:00 MST");
+ check("local -= days",
+ (az_lt -= days(2)).to_string() == "2003-Aug-28 05:00:00 MST");
+ check("local + time_duration",
+ (az_lt + hours(2)).to_string() == "2003-Aug-28 07:00:00 MST");
+ check("local - time_duration",
+ (az_lt - hours(2)).to_string() == "2003-Aug-28 03:00:00 MST");
+ // special_values is more thoroughly tested in posix_time
+ check("pos_infinity > local", sv_lt > au_lt);
+ local_date_time sv_lt2(sv_lt + days(2));
+ check("pos_infin + duration == pos_infin", sv_lt2 == sv_lt);
+
+#if defined(BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES)
+ months m(2);
+ years y(2);
+ check("Local + months",
+ (az_lt + m).to_string() == "2003-Oct-28 05:00:00 MST");
+ az_lt += m;
+ check("Local += months",
+ az_lt.to_string() == "2003-Oct-28 05:00:00 MST");
+ check("Local - months",
+ (az_lt - m).to_string() == "2003-Aug-28 05:00:00 MST");
+ az_lt -= m;
+ check("Local -= months",
+ az_lt.to_string() == "2003-Aug-28 05:00:00 MST");
+ check("Local + years",
+ (az_lt + y).to_string() == "2005-Aug-28 05:00:00 MST");
+ az_lt += y;
+ check("Local += years",
+ az_lt.to_string() == "2005-Aug-28 05:00:00 MST");
+ check("Local - years",
+ (az_lt - y).to_string() == "2003-Aug-28 05:00:00 MST");
+ az_lt -= y;
+ check("Local -= years",
+ az_lt.to_string() == "2003-Aug-28 05:00:00 MST");
+
+#endif // BOOST_DATE_TIME_OPTIONAL_GREGORIAN_TYPES
+ }
+ }
+ catch(std::exception& e) {
+ check(std::string("test failed due to exception: ") + e.what(), false);
+ }
+
+ return printTestStats();
+}
+
diff --git a/src/boost/libs/date_time/test/local_time/testlocal_time_facet.cpp b/src/boost/libs/date_time/test/local_time/testlocal_time_facet.cpp
new file mode 100644
index 000000000..2046ac156
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testlocal_time_facet.cpp
@@ -0,0 +1,188 @@
+
+/* Copyright (c) 2004 CrystalClear Software, Inc.
+ * Use, modification and distribution is subject to the
+ * Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include <iostream>
+#include <sstream>
+#include <boost/shared_ptr.hpp>
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+
+
+template<class temporal_type, typename charT>
+inline
+void
+teststreaming(std::string const& testname,
+ temporal_type value,
+ std::basic_string<charT> const& expected_result,
+ const std::locale& locale)
+{
+ std::basic_stringstream<charT> ss;
+ ss.imbue(locale);
+ ss << value;
+
+ if (!check(testname, ss.str() == expected_result))
+#if !defined(BOOST_NO_STD_WSTRING)
+ std::wcout << L"Expected: \"" << expected_result.c_str() << L"\"\nGot: \"" << ss.str().c_str() << L"\"" << std::endl;
+#else
+ std::cout << "Expected: \"" << expected_result.c_str() << "\"\nGot: \"" << ss.str().c_str() << L"\"" << std::endl;
+#endif
+}
+
+int main(int /* argc */, char const* argv[]){
+ /* use the tz_database for the time zones.
+ * Chicago, Denver, Los_Angeles, New_Tork, and Phoenix
+ * have all had full names added */
+ using namespace boost;
+ using namespace boost::local_time;
+ using namespace boost::posix_time;
+ using namespace boost::gregorian;
+
+ tz_database time_zones;
+
+ try {
+ // first try to find the data file from the test dir
+ time_zones.load_from_file(argv[1]);
+ }
+ catch(const data_not_accessible&) {
+ check("Cannot locate data file - aborting.", false);
+ return printTestStats();
+ }
+
+ time_zone_ptr utc;
+ time_zone_ptr chicago = time_zones.time_zone_from_region("America/Chicago");
+ time_zone_ptr denver = time_zones.time_zone_from_region("America/Denver");
+ time_zone_ptr la = time_zones.time_zone_from_region("America/Los_Angeles");
+ time_zone_ptr nyc = time_zones.time_zone_from_region("America/New_York");
+ time_zone_ptr phx = time_zones.time_zone_from_region("America/Phoenix");
+ // sydney does not have full time zone names in the tz_database
+ time_zone_ptr sydney = time_zones.time_zone_from_region("Australia/Sydney");
+
+ ptime a_time(date(2004,Dec,15), hours(12));
+ ptime b_time(date(2004,Aug,15), hours(12));
+ local_date_time ldt1(a_time, utc);
+ local_date_time ldt2(b_time, chicago);
+ local_date_time ldt3(a_time, denver);
+ local_date_time ldt4(b_time, la);
+ local_date_time ldt5(a_time, nyc);
+ local_date_time ldt6(b_time, phx);
+
+ local_time_period ltp1(ldt1, hours(10) + minutes(24) + seconds(5));
+ local_time_period ltp2(ldt4, hours(15) + minutes(20) + seconds(41));
+
+ typedef boost::date_time::time_facet<local_date_time, char> ldt_facet;
+ //ldt_facet* timefacet = new ldt_facet("%c %Z"); // full name
+ ldt_facet* timefacet = new ldt_facet("%a %b %d %H:%M:%S %Y %Z"); // full name
+ std::locale loc1(std::locale::classic(), timefacet);
+
+ typedef boost::date_time::time_facet<ptime, char> pt_facet;
+ //pt_facet* ptimefacet1 = new pt_facet("%c %Z"); // show that zone is ignored
+ pt_facet* ptimefacet1 = new pt_facet("%a %b %d %H:%M:%S %Y %Z"); // show that zone is ignored
+ std::locale loc2(std::locale::classic(), ptimefacet1);
+
+
+ std::cout << "\nFull time zone names tests" << std::endl;
+ teststreaming("ptime with %Z flag\n", a_time, std::string("Wed Dec 15 12:00:00 2004") , loc2);
+
+ teststreaming("UTC local_date_time", ldt1, std::string("Wed Dec 15 12:00:00 2004 Coordinated Universal Time"), loc1);
+ teststreaming("Chicago in summer", ldt2, std::string("Sun Aug 15 07:00:00 2004 Central Daylight Time") , loc1);
+ teststreaming("Denver in winter", ldt3, std::string("Wed Dec 15 05:00:00 2004 Mountain Standard Time"), loc1);
+ teststreaming("Los Angeles in summer", ldt4, std::string("Sun Aug 15 05:00:00 2004 Pacific Daylight Time"), loc1);
+ teststreaming("New York in winter", ldt5, std::string("Wed Dec 15 07:00:00 2004 Eastern Standard Time"), loc1);
+ teststreaming("Phoenix in Summer", ldt6, std::string("Sun Aug 15 05:00:00 2004 Mountain Standard Time"), loc1);
+
+ teststreaming("UTC local_time_period", ltp1, std::string("[Wed Dec 15 12:00:00 2004 Coordinated Universal Time/Wed Dec 15 22:24:04 2004 Coordinated Universal Time]"), loc1);
+ teststreaming("LA local_time_period", ltp2, std::string("[Sun Aug 15 05:00:00 2004 Pacific Daylight Time/Sun Aug 15 20:20:40 2004 Pacific Daylight Time]"), loc1);
+
+ //ptimefacet1->format("%c %z"); // show that zone abbrev is ignored
+ ptimefacet1->format("%a %b %d %H:%M:%S %Y %z"); // show that zone abbrev is ignored
+ std::cout << "\nTime zone abbreviation tests" << std::endl;
+ teststreaming("ptime with %z flag\n", a_time, std::string("Wed Dec 15 12:00:00 2004") , loc2);
+
+ // using standard format
+ //timefacet->format("%c %z"); // abbreviated zone
+ timefacet->format("%a %b %d %H:%M:%S %Y %z"); // abbreviated zone
+ teststreaming("UTC local_date_time", ldt1, std::string("Wed Dec 15 12:00:00 2004 UTC"), loc1);
+ teststreaming("Chicago in summer", ldt2, std::string("Sun Aug 15 07:00:00 2004 CDT") , loc1);
+ teststreaming("Denver in winter", ldt3, std::string("Wed Dec 15 05:00:00 2004 MST"), loc1);
+ teststreaming("Los Angeles in summer", ldt4, std::string("Sun Aug 15 05:00:00 2004 PDT"), loc1);
+ teststreaming("New York in winter", ldt5, std::string("Wed Dec 15 07:00:00 2004 EST"), loc1);
+ teststreaming("Phoenix in Summer", ldt6, std::string("Sun Aug 15 05:00:00 2004 MST"), loc1);
+
+ // iso format
+ // show that zone offset is ignored
+ ptimefacet1->format(pt_facet::iso_time_format_specifier);
+ std::cout << "\nLocal time iso format tests" << std::endl;
+ teststreaming("ptime with iso format\n", a_time,
+ std::string("20041215T120000") , loc2);
+
+ timefacet->format(ldt_facet::iso_time_format_specifier);
+ teststreaming("UTC local_date_time", ldt1,
+ std::string("20041215T120000Z"), loc1);
+ teststreaming("Chicago in summer", ldt2,
+ std::string("20040815T070000-0500") , loc1);
+ teststreaming("Denver in winter", ldt3,
+ std::string("20041215T050000-0700"), loc1);
+ teststreaming("Los Angeles in summer", ldt4,
+ std::string("20040815T050000-0700"), loc1);
+ teststreaming("New York in winter", ldt5,
+ std::string("20041215T070000-0500"), loc1);
+ teststreaming("Phoenix in Summer", ldt6,
+ std::string("20040815T050000-0700"), loc1);
+ teststreaming("Sydney in December", ldt1.local_time_in(sydney),
+ std::string("20041215T230000+1100"), loc1);
+
+ // iso extended format
+ // show that zone offset is ignored
+ ptimefacet1->format(pt_facet::iso_time_format_extended_specifier);
+ std::cout << "\nLocal time iso_extended tests" << std::endl;
+ teststreaming("ptime with iso extended format\n", a_time,
+ std::string("2004-12-15 12:00:00") , loc2);
+
+ timefacet->format(ldt_facet::iso_time_format_extended_specifier);
+ teststreaming("UTC local_date_time", ldt1,
+ std::string("2004-12-15 12:00:00Z"), loc1);
+ teststreaming("Chicago in summer", ldt2,
+ std::string("2004-08-15 07:00:00-05:00") , loc1);
+ teststreaming("Denver in winter", ldt3,
+ std::string("2004-12-15 05:00:00-07:00"), loc1);
+ teststreaming("Los Angeles in summer", ldt4,
+ std::string("2004-08-15 05:00:00-07:00"), loc1);
+ teststreaming("New York in winter", ldt5,
+ std::string("2004-12-15 07:00:00-05:00"), loc1);
+ teststreaming("Phoenix in Summer", ldt6,
+ std::string("2004-08-15 05:00:00-07:00"), loc1);
+ teststreaming("Sydney in December", ldt1.local_time_in(sydney),
+ std::string("2004-12-15 23:00:00+11:00"), loc1);
+
+#if !defined(BOOST_NO_STD_WSTRING)
+
+ typedef boost::date_time::time_facet<local_date_time, wchar_t> wldt_facet;
+ //wldt_facet* wtimefacet = new wldt_facet(L"%c %Z"); // full name
+ wldt_facet* wtimefacet = new wldt_facet(L"%a %b %d %H:%M:%S %Y %Z"); // full name
+ std::locale loc3(std::locale::classic(), wtimefacet);
+
+ /* Again, wide stream tests are more thoroughly done in the
+ * time_facet tests. Here we just need to show that they work */
+ std::cout << "\nFull time zone names tests - wide stream" << std::endl;
+ teststreaming("UTC local_date_time", ldt1, std::wstring(L"Wed Dec 15 12:00:00 2004 Coordinated Universal Time"), loc3);
+ teststreaming("Chicago in summer", ldt2, std::wstring(L"Sun Aug 15 07:00:00 2004 Central Daylight Time") , loc3);
+
+ teststreaming("UTC local_time_period", ltp1, std::wstring(L"[Wed Dec 15 12:00:00 2004 Coordinated Universal Time/Wed Dec 15 22:24:04 2004 Coordinated Universal Time]"), loc3);
+ teststreaming("LA local_time_period", ltp2, std::wstring(L"[Sun Aug 15 05:00:00 2004 Pacific Daylight Time/Sun Aug 15 20:20:40 2004 Pacific Daylight Time]"), loc3);
+
+ //wtimefacet->format(L"%c %z"); // abbrev
+ wtimefacet->format(L"%a %b %d %H:%M:%S %Y %z"); // abbrev
+ std::cout << "\nAbbreviated time zone names tests - wide stream" << std::endl;
+ teststreaming("UTC local_date_time", ldt1, std::wstring(L"Wed Dec 15 12:00:00 2004 UTC"), loc3);
+ teststreaming("Phoenix in Summer", ldt6, std::wstring(L"Sun Aug 15 05:00:00 2004 MST"), loc3);
+
+#endif // BOOST_NO_STD_WSTRING
+
+ return printTestStats();
+}
diff --git a/src/boost/libs/date_time/test/local_time/testlocal_time_input_facet.cpp b/src/boost/libs/date_time/test/local_time/testlocal_time_input_facet.cpp
new file mode 100644
index 000000000..7622e5676
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testlocal_time_input_facet.cpp
@@ -0,0 +1,239 @@
+/* Copyright (c) 2005 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+#include <iostream>
+#include <sstream>
+#include <string>
+
+// for tests that are expected to fail and throw exceptions
+template<class temporal_type, class exception_type>
+bool failure_test(temporal_type component,
+ const std::string& input,
+ exception_type const& /*except*/,
+ boost::local_time::local_time_input_facet* facet)
+{
+ using namespace boost::local_time;
+ bool result = false;
+ std::istringstream iss(input);
+ iss.exceptions(std::ios_base::failbit); // turn on exceptions
+ iss.imbue(std::locale(std::locale::classic(), facet));
+ try {
+ iss >> component;
+ }
+ catch(exception_type& e) {
+ std::cout << "Expected exception caught: \""
+ << e.what() << "\"" << std::endl;
+ result = iss.fail(); // failbit must be set to pass test
+ }
+ catch(...) {
+ result = false;
+ }
+
+ return result;
+}
+
+// for tests that are expected to fail quietly
+template<class temporal_type>
+bool failure_test(temporal_type component,
+ const std::string& input,
+ boost::local_time::local_time_input_facet* facet)
+{
+ using namespace boost::local_time;
+ std::istringstream iss(input);
+ /* leave exceptions turned off
+ * iss.exceptions(std::ios_base::failbit); */
+ iss.imbue(std::locale(std::locale::classic(), facet));
+ try {
+ iss >> component;
+ }
+ catch(...) {
+ std::cout << "Caught unexpected exception" << std::endl;
+ return false;
+ }
+
+ return iss.fail(); // failbit must be set to pass test
+}
+
+int main() {
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+ time_zone_ptr null_zone;
+ local_date_time ldt1(not_a_date_time, null_zone);
+
+ // verify wide stream works, thorough tests done in narrow stream
+#if !defined(BOOST_NO_STD_WSTRING)
+ {
+ std::wstringstream ws;
+ ws.str(L"2005-Feb-15 12:15:00 EST-05EDT,M4.1.0,M10.5.0");
+ ws >> ldt1;
+ check("Wide stream, Eastern US, daylight savings, winter, minimal input",
+ ldt1.local_time() == ptime(date(2005,2,15), time_duration(12,15,0)));
+ check("Wide stream, Eastern US, daylight savings, winter, minimal input",
+ ldt1.utc_time() == ptime(date(2005,2,15), time_duration(17,15,0)));
+ check("Wide stream, Eastern US, daylight savings, winter, minimal input", !ldt1.is_dst());
+ ws.str(L"");
+ wlocal_time_input_facet* wfacet = new wlocal_time_input_facet(L"%m/%d/%y %ZP");
+ std::locale loc(std::locale::classic(), wfacet);
+ ws.imbue(loc);
+ ws.str(L"10/31/04 PST-08PDT,M4.1.0,M10.5.0"); // midnight on end transition day, still in dst
+ ws >> ldt1;
+ std::wcout << ldt1.local_time() << std::endl;
+ check("Wide stream, Eastern US, daylight savings, winter, custom format",
+ ldt1.local_time() == ptime(date(2004,10,31), time_duration(0,0,0)));
+ check("Wide stream, Eastern US, daylight savings, winter, custom format",
+ ldt1.utc_time() == ptime(date(2004,10,31), time_duration(7,0,0)));
+ check("Wide stream, Eastern US, daylight savings, winter, custom format", ldt1.is_dst());
+ }
+#endif // BOOST_NO_STD_WSTRING
+
+ std::stringstream ss;
+ ss.str("2005-Feb-25 12:15:00 EST-05EDT,M4.1.0,M10.5.0");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, winter, minimal input",
+ ldt1.local_time() == ptime(date(2005,2,25), time_duration(12,15,0)));
+ check("Eastern US, daylight savings, winter, minimal input",
+ ldt1.utc_time() == ptime(date(2005,2,25), time_duration(17,15,0)));
+ check("Eastern US, daylight savings, winter, minimal input", !ldt1.is_dst());
+ ss.str("");
+
+ ss.str("2005-Aug-25 12:15:00 EST-05EDT,M4.1.0,M10.5.0");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, summer, minimal input",
+ ldt1.local_time() == ptime(date(2005,8,25), time_duration(12,15,0)));
+ check("Eastern US, daylight savings, summer, minimal input",
+ ldt1.utc_time() == ptime(date(2005,8,25), time_duration(16,15,0)));
+ check("Eastern US, daylight savings, summer, minimal input", ldt1.is_dst());
+ ss.str("");
+
+ ss.str("2005-Apr-03 01:15:00 EST-05EDT,M4.1.0,M10.5.0");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, transition point", !ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ss.str("");
+ ss.str("2005-Apr-03 01:15:00 EST-05EDT,93,303");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, transition point", !ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ss.str("");
+
+ ss.str("2005-Oct-30 00:15:00 EST-05EDT,M4.1.0,M10.5.0");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", !ldt1.is_dst());
+ ss.str("");
+ ss.str("2005-Oct-30 00:15:00 EST-05EDT,93,303");
+ ss >> ldt1;
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", ldt1.is_dst());
+ ldt1 += hours(1);
+ check("Eastern US, daylight savings, transition point", !ldt1.is_dst());
+ ss.str("");
+
+ ss.str("2005-Aug-25 12:15:00 MST-07");
+ ss >> ldt1;
+ check("Mountain US, no daylight savings",
+ ldt1.local_time() == ptime(date(2005,8,25), time_duration(12,15,0)));
+ check("Mountain US, no daylight savings",
+ ldt1.utc_time() == ptime(date(2005,8,25), time_duration(19,15,0)));
+ check("Mountain US, no daylight savings", !ldt1.is_dst());
+ ss.str("");
+
+ // insure input & output formats match
+ local_time_facet* out_facet =
+ new local_time_facet(local_time_input_facet::default_time_input_format);
+ std::locale loc(std::locale::classic(), out_facet);
+ ss.imbue(loc);
+ time_zone_ptr syd_tz(new posix_time_zone("EST+10EST,M10.5.0,M3.5.0/03:00"));
+ ptime pt(date(2005,6,12), hours(0));
+ local_date_time ldt2(pt, syd_tz);
+ ss << ldt2;
+ ss >> ldt1;
+ check("Output as input makes match", ldt1 == ldt2);
+ check("Output as input makes match",
+ ldt1.zone()->dst_local_start_time(2004) == ldt2.zone()->dst_local_start_time(2004));
+ ss.str("");
+
+ time_zone_ptr f_tz(new posix_time_zone("FST+03FDT,90,300"));
+ ldt2 = local_date_time(ptime(date(2005,6,12), hours(0)), f_tz);
+ ss << ldt2;
+ ss >> ldt1;
+ check("Output as input makes match", ldt1 == ldt2);
+ check("Output as input makes match",
+ ldt1.zone()->dst_local_start_time(2004) == ldt2.zone()->dst_local_start_time(2004));
+ ss.str("");
+
+ // missing input & wrong format tests
+ ss.str("2005-Oct-30 00:15:00");
+ ss >> ldt1;
+ check("Missing time_zone spec makes UTC", ldt1.zone_as_posix_string() == std::string("UTC+00"));
+ check("Missing time_zone spec makes UTC", ldt1.utc_time() == ldt1.local_time());
+ ss.str("");
+ {
+ std::istringstream iss("2005-Aug-25 12:15:00 MST-07");
+ local_time_input_facet* f = new local_time_input_facet("%Y-%b-%d %H:%M:%S %z");
+ std::locale locx(std::locale::classic(), f);
+ iss.imbue(locx);
+ iss >> ldt1;
+ check("Wrong format flag makes UTC", ldt1.zone_as_posix_string() == std::string("UTC+00"));
+ check("Wrong format flag makes UTC", ldt1.utc_time() == ldt1.local_time());
+ }
+
+
+ // failure tests: (posix_time_zone) bad_offset, bad_adjustment,
+ // (local_date_time) ambiguous_result, time_label_invalid,
+ // time/date failures already tested
+ ambiguous_result amb_ex("default");
+ time_label_invalid inv_ex("default");
+ check("Failure test ambiguous time label (w/exceptions)",
+ failure_test(ldt1,
+ "2005-Oct-30 01:15:00 EST-05EDT,M4.1.0,M10.5.0",
+ amb_ex,
+ new local_time_input_facet()));
+ check("Failure test ambiguous time label (no exceptions)",
+ failure_test(ldt1,
+ "2005-Oct-30 01:15:00 EST-05EDT,M4.1.0,M10.5.0",
+ new local_time_input_facet()));
+ check("Failure test ambiguous time label (w/exceptions)",
+ failure_test(ldt1,
+ "2005-Oct-30 01:15:00 EST-05EDT,93,303",
+ amb_ex,
+ new local_time_input_facet()));
+ check("Failure test ambiguous time label (no exceptions)",
+ failure_test(ldt1,
+ "2005-Oct-30 01:15:00 EST-05EDT,93,303",
+ new local_time_input_facet()));
+ check("Failure test invalid time label (w/exceptions)",
+ failure_test(ldt1,
+ "2005-Apr-03 02:15:00 EST-05EDT,M4.1.0,M10.5.0",
+ inv_ex,
+ new local_time_input_facet()));
+ check("Failure test invalid time label (no exceptions)",
+ failure_test(ldt1,
+ "2005-Apr-03 02:15:00 EST-05EDT,M4.1.0,M10.5.0",
+ new local_time_input_facet()));
+ check("Failure test invalid time label (w/exceptions)",
+ failure_test(ldt1,
+ "2005-Apr-03 02:15:00 EST-05EDT,93,303",
+ inv_ex,
+ new local_time_input_facet()));
+ check("Failure test invalid time label (no exceptions)",
+ failure_test(ldt1,
+ "2005-Apr-03 02:15:00 EST-05EDT,93,303",
+ new local_time_input_facet()));
+
+
+ return printTestStats();
+}
diff --git a/src/boost/libs/date_time/test/local_time/testlocal_time_iterator.cpp b/src/boost/libs/date_time/test/local_time/testlocal_time_iterator.cpp
new file mode 100644
index 000000000..670b572f4
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testlocal_time_iterator.cpp
@@ -0,0 +1,95 @@
+/* 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.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include <iostream>
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+// #if defined(BOOST_DATE_TIME_INCLUDE_LIMITED_HEADERS)
+// #include "boost/date_time/gregorian/formatters_limited.hpp"
+// #else
+// #include "boost/date_time/gregorian/formatters.hpp"
+// #endif
+
+using namespace boost::posix_time;
+using namespace boost::gregorian;
+using namespace boost::local_time;
+
+void iterate_backward(const local_date_time *answers,
+ int ary_len,
+ const time_duration& td)
+{
+ int i = ary_len -1;
+ local_date_time end = answers[i];
+ local_time_iterator titr(end,td);
+
+ std::cout << "counting down by previous duration..." << std::endl;
+ for (; titr >= answers[0]; --titr) {
+ std::cout << *titr << std::endl;
+ check("iterating backward", answers[i] == *titr);
+ --i;
+ }
+ check("iterating backward count", i == -1); // check the number of iterations
+ std::cout << std::endl;
+}
+
+int
+main()
+{
+
+ time_zone_ptr ny_tz(new posix_time_zone("EST-05EDT,M4.1.0,M10.5.0"));
+
+ //set up a time right on the dst boundary -- iterator will
+ //jump forward an hour at the boundary
+ date d(2005,Apr,3);
+ time_duration dst_offset(1,59,59);
+ local_date_time start(d, dst_offset, ny_tz, false);
+
+ const local_date_time answer1[] =
+ {
+ local_date_time(d,dst_offset, ny_tz, false),
+ local_date_time(d,hours(3), ny_tz, true),
+ local_date_time(d,hours(3)+seconds(1), ny_tz, true),
+ local_date_time(d,hours(3)+seconds(2), ny_tz, true)
+ };
+
+ int i=0;
+ local_time_iterator titr(start,seconds(1));
+ local_date_time end = start + seconds(4);
+ for (; titr < end; ++titr) {
+ std::cout << (*titr) << std::endl;
+ check("iterator -- 1 sec", answer1[i] == *titr);
+ i++;
+ }
+ check("iterator -- 1 sec -- num iterations", i == 4); // check the number of iterations
+
+ iterate_backward(answer1, 4, seconds(1));
+
+ //iterate by hours
+ const local_date_time answer2[] =
+ { local_date_time(d,dst_offset, ny_tz, false),
+ local_date_time(d,dst_offset+hours(2), ny_tz, true),
+ local_date_time(d,dst_offset+hours(3), ny_tz, true),
+ local_date_time(d,dst_offset+hours(4), ny_tz, true)
+ };
+ i=0;
+ local_time_iterator titr2(start,hours(1));
+ local_date_time end2 = start + hours(4);
+ for (; titr2 < end2; ++titr2) {
+ std::cout << *titr2 << std::endl;
+ check("iterator -- 1 hour", answer2[i] == *titr2);
+ i++;
+ }
+ check("iterator -- 1 hour -- num iterations", i == 4);
+
+ iterate_backward(answer2, 4, hours(1));
+
+
+
+ return printTestStats();
+}
+
diff --git a/src/boost/libs/date_time/test/local_time/testlocal_time_period.cpp b/src/boost/libs/date_time/test/local_time/testlocal_time_period.cpp
new file mode 100644
index 000000000..64c8f7564
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testlocal_time_period.cpp
@@ -0,0 +1,82 @@
+/* Copyright (c) 2005 CrystalClear Software, Inc.
+ * Use, modification and distribution is subject to the
+ * Boost Software License, Version 1.0. (See accompanying
+ * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland
+ */
+
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+
+int main()
+{
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+ date d1(2001,Jan, 1);
+
+ time_zone_ptr az_tz(new posix_time_zone("MST-07"));
+
+ local_date_time t1 (d1,hours(2), az_tz, false);//2001-Jan-1 02:00:00
+
+ local_date_time t2 (d1,hours(3), az_tz, false);//2001-Jan-1 03:00:00
+ local_time_period p1(t1,t2); //2001-Jan-1 02:59:59
+ local_time_period p2(p1);
+ check("copy construct & ==", p1 == p2);
+ local_time_period p3 = p2;
+ check("assignment", p3 == p2);
+ local_time_period p4(t1,hours(1));
+
+ check("length", p4.length() == hours(1));
+
+// std::cout << to_simple_string(t1) << std::endl;
+// std::cout << to_simple_string(p4) << std::endl;
+// std::cout << to_simple_string(p1) << std::endl;
+ check("construction and ==", p1 == p4);
+ check("begin", p1.begin() == t1);
+ check("last", p1.end() == t2);
+ check("end", p1.last() == t2-time_duration::unit());
+
+// std::cout << to_simple_string(p1) << std::endl;
+// // check("last", p1.() == t2);
+ check("contains begin", p1.contains(t1));
+ check("contains end-not", !p1.contains(t2));
+ check("contains last", p1.contains(t2-seconds(1)));
+ local_date_time t3(date(2001,Jan,1),hours(4), az_tz, false);
+ local_time_period p5(t2,t3);
+ check("check contains", !p1.contains(p5.begin()));
+ check("check contains", !p5.contains(p1.begin()));
+ check("operator== not equal case", !(p1 == p5));
+ check("less than order", p1 < p5);
+ check("greater than order", p5 > p1);
+ check("not equal", p5 != p1);
+ check("intersects with myself", p1.intersects(p1));
+ check("not intersects", !(p1.intersects(p5)));
+ check("not intersects", !(p5.intersects(p1)));
+
+ local_time_period p6(p5);
+ p6.shift(minutes(30));
+// std::cout << to_simple_string(p5) << std::endl;
+// std::cout << to_simple_string(p6) << std::endl;
+ check("shifted intersects", p5.intersects(p6));
+ check("shifted intersects", p6.intersects(p5));
+ check("contains begin", p5.contains(p6.begin()));
+ p6.shift(minutes(30));
+// std::cout << to_simple_string(p5) << std::endl;
+// std::cout << to_simple_string(p6) << std::endl;
+ check("shifted !intersects", !p5.intersects(p6));
+ check("shifted !intersects", !p6.intersects(p5));
+ p6.shift(minutes(-30));
+// std::cout << to_simple_string(p5) << std::endl;
+// std::cout << to_simple_string(p6) << std::endl;
+ local_time_period p7 = p5.intersection(p6);
+// std::cout << to_simple_string(p7) << std::endl;
+ check("shifted intersection",
+ p7 == local_time_period(local_date_time(d1,time_duration(3,30,0), az_tz, false),
+ local_date_time(d1,time_duration(4,0,0), az_tz, false)));
+
+
+ return printTestStats();
+
+}
+
diff --git a/src/boost/libs/date_time/test/local_time/testposix_time_zone.cpp b/src/boost/libs/date_time/test/local_time/testposix_time_zone.cpp
new file mode 100644
index 000000000..7bf971e87
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testposix_time_zone.cpp
@@ -0,0 +1,221 @@
+/* Copyright (c) 2003-2004 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+
+#include "boost/date_time/gregorian/gregorian.hpp"
+//#include "boost/date_time/local_time/time_zone.hpp"
+#include "../testfrmwk.hpp"
+
+#include "boost/date_time/local_time/posix_time_zone.hpp"
+
+#include <string>
+#include <iostream>
+
+int main(){
+ using namespace boost::local_time;
+ using namespace boost::posix_time;
+ using namespace boost::gregorian;
+ std::string specs[] = {"MST-07", "MST-07:00:00","EST-05EDT,M4.1.0,M10.5.0", "EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00","PST-08PDT,J46/1:30,J310","PST-08PDT,45,310/0:30:00"};
+
+ posix_time_zone nyc1(specs[2]);
+ posix_time_zone nyc2(specs[3]);
+ time_duration td = hours(-5);
+
+ check("Has DST", nyc1.has_dst() && nyc2.has_dst());
+ check("UTC offset", nyc1.base_utc_offset() == td);
+ check("UTC offsets match", nyc1.base_utc_offset() == nyc2.base_utc_offset());
+ check("Abbrevs", nyc1.std_zone_abbrev() == std::string("EST"));
+ check("Abbrevs", nyc2.std_zone_abbrev() == std::string("EST"));
+ check("Abbrevs", nyc1.dst_zone_abbrev() == std::string("EDT"));
+ check("Abbrevs", nyc2.dst_zone_abbrev() == std::string("EDT"));
+ // names not available for posix_time_zone, abbrevs used in their place
+ check("Names", nyc1.std_zone_name() == std::string("EST"));
+ check("Names", nyc2.std_zone_name() == std::string("EST"));
+ check("Names", nyc1.dst_zone_name() == std::string("EDT"));
+ check("Names", nyc2.dst_zone_name() == std::string("EDT"));
+ td = hours(1);
+ check("dst offset", nyc1.dst_offset() == td);
+ check("dst offsets match", nyc1.dst_offset() == nyc2.dst_offset());
+ check("dst start", nyc1.dst_local_start_time(2003) ==
+ ptime(date(2003,Apr,6),time_duration(2,0,0)));
+ check("dst starts match", nyc1.dst_local_start_time(2003) ==
+ nyc2.dst_local_start_time(2003));
+ check("dst end", nyc1.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,26),time_duration(2,0,0)));
+ check("dst ends match", nyc1.dst_local_end_time(2003) ==
+ nyc2.dst_local_end_time(2003));
+ check("to posix string",
+ nyc1.to_posix_string() == std::string("EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+ check("to posix string",
+ nyc2.to_posix_string() == std::string("EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+
+
+ posix_time_zone az1(specs[0]);
+ posix_time_zone az2(specs[1]);
+ td = hours(-7);
+
+ check("Has DST", !az1.has_dst() && !az2.has_dst());
+ check("UTC offset", az1.base_utc_offset() == td);
+ check("UTC offsets match", az1.base_utc_offset() == az2.base_utc_offset());
+ check("dst start in non-dst zone",
+ az1.dst_local_start_time(2005) == ptime(not_a_date_time));
+ check("dst end in non-dst zone",
+ az2.dst_local_end_time(2005) == ptime(not_a_date_time));
+ check("Abbrevs", az1.std_zone_abbrev() == std::string("MST"));
+ check("Abbrevs", az2.std_zone_abbrev() == std::string("MST"));
+ // non-dst zones default to empty strings for dst names & abbrevs
+ check("Abbrevs", az1.dst_zone_abbrev() == std::string(""));
+ check("Abbrevs", az2.dst_zone_abbrev() == std::string(""));
+ check("Names", az1.std_zone_name() == std::string("MST"));
+ check("Names", az2.std_zone_name() == std::string("MST"));
+ check("Names", az1.dst_zone_name() == std::string(""));
+ check("Names", az2.dst_zone_name() == std::string(""));
+ check("to posix string",
+ az1.to_posix_string() == std::string("MST-07"));
+ check("to posix string",
+ az2.to_posix_string() == std::string("MST-07"));
+
+
+ // bizzar time zone spec to fully test parsing
+ std::cout << "\nFictitious time zone" << std::endl;
+ posix_time_zone bz("BST+11:21:15BDT-00:28,M2.2.4/03:15:42,M11.5.2/01:08:53");
+ check("hast dst", bz.has_dst());
+ check("UTC offset", bz.base_utc_offset() == time_duration(11,21,15));
+ check("Abbrev", bz.std_zone_abbrev() == std::string("BST"));
+ check("Abbrev", bz.dst_zone_abbrev() == std::string("BDT"));
+ check("dst offset", bz.dst_offset() == time_duration(0,-28,0));
+ check("dst start", bz.dst_local_start_time(1962) ==
+ ptime(date(1962,Feb,8),time_duration(3,15,42)));
+ check("dst end", bz.dst_local_end_time(1962) ==
+ ptime(date(1962,Nov,27),time_duration(1,8,53)));
+
+ // only checking start & end rules w/ 'J' notation
+ std::cout << "\n'J' notation Start/End rule tests..." << std::endl;
+ posix_time_zone la1(specs[4]); // "PST-08PDT,J124,J310"
+ //posix_time_zone la1("PST-08PDT,J1,J365");// Jan1/Dec31
+ check("dst start", la1.dst_local_start_time(2003) ==
+ ptime(date(2003,Feb,15),time_duration(1,30,0)));
+ check("dst end", la1.dst_local_end_time(2003) ==
+ ptime(date(2003,Nov,6),time_duration(2,0,0)));
+ /* NOTE: la1 was created from a 'J' notation string but to_posix_string
+ * returns an 'n' notation string. The difference between the two
+ * is Feb-29 is always counted in an 'n' notation string and numbering
+ * starts at zero ('J' notation starts at one).
+ * Every possible date spec that can be written in 'J' notation can also
+ * be written in 'n' notation. The reverse is not true so 'n' notation
+ * is used as the output for to_posix_string(). */
+ check("to posix string",
+ la1.to_posix_string() == std::string("PST-08PDT+01,45/01:30,310/02:00"));
+
+ // only checking start & end rules w/ 'n' notation
+ std::cout << "\n'n' notation Start/End rule tests..." << std::endl;
+ posix_time_zone la2(specs[5]); // "PST-08PDT,124,310"
+ //posix_time_zone la2("PST-08PDT,0,365");// Jan1/Dec31
+ check("dst start", la2.dst_local_start_time(2003) ==
+ ptime(date(2003,Feb,15),time_duration(2,0,0)));
+ check("dst end", la2.dst_local_end_time(2003) ==
+ ptime(date(2003,Nov,6),time_duration(0,30,0)));
+ check("to posix string",
+ la2.to_posix_string() == std::string("PST-08PDT+01,45/02:00,310/00:30"));
+
+ // bad posix time zone strings tests
+ std::cout << "\nInvalid time zone string tests..." << std::endl;
+ try {
+ posix_time_zone badz("EST-13");
+ check("Exception not thrown: bad UTC offset", false);
+ }catch(bad_offset& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ posix_time_zone badz("EST-5EDT24:00:01,J124/1:30,J310");
+ check("Exception not thrown: bad DST adjust", false);
+ }catch(bad_adjustment& badj){
+ std::string msg(badj.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ posix_time_zone badz("EST-5EDT01:00:00,J124/-1:30,J310");
+ check("Exception not thrown: bad DST start/end offset", false);
+ }catch(bad_offset& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ posix_time_zone badz("EST-5EDT01:00:00,J124/1:30,J370");
+ check("Exception not thrown: invalid date spec", false);
+ }catch(boost::gregorian::bad_day_of_month& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }catch(boost::gregorian::bad_month& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }catch(...){
+ check("Unexpected exception caught: ", false);
+ }
+
+ std::cout << "\nTest some Central Europe specs" << std::endl;
+
+ //Test a timezone spec on the positive side of the UTC line.
+ //This is the time for central europe which is one hour in front of UTC
+ //Note these Summer time transition rules aren't actually correct.
+ posix_time_zone cet_tz("CET+01:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00");
+ check("Has DST", cet_tz.has_dst());
+ check("UTC offset", cet_tz.base_utc_offset() == hours(1));
+ check("Abbrevs", cet_tz.std_zone_abbrev() == std::string("CET"));
+// check("Abbrevs", nyc2.std_zone_abbrev() == std::string("EST"));
+
+ std::cout << "\nTest some Central Austrialia UTC+8:30" << std::endl;
+
+ //Test a timezone spec on the positive side of the UTC line.
+ //This is the time for central europe which is one hour in front of UTC
+ //Note these Summer time transition rules aren't actually correct.
+ posix_time_zone caus_tz("CAS+08:30:00CDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00");
+ check("Has DST", caus_tz.has_dst());
+ check("UTC offset", caus_tz.base_utc_offset() == hours(8)+minutes(30));
+ check("Abbrevs", caus_tz.std_zone_abbrev() == std::string("CAS"));
+// check("Abbrevs", nyc2.std_zone_abbrev() == std::string("EST"));
+
+ {
+ /**** first/last of month Julian & non-Julian tests ****/
+ // Mar-01 & Oct-31, count begins at 1
+ std::string spec("FST+3FDT,J60,J304");
+ posix_time_zone fl_1(spec);
+ check("Julian First/last of month", fl_1.dst_local_start_time(2003) ==
+ ptime(date(2003,Mar,1),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,31),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_start_time(2004) ==
+ ptime(date(2004,Mar,1),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_end_time(2004) ==
+ ptime(date(2004,Oct,31),hours(2)));
+
+ // Mar-01 & Oct-31 Non-leap year, count begins at 0
+ spec = "FST+3FDT,59,304"; // "304" is not a mistake here, see posix_time_zone docs
+ posix_time_zone fl_2(spec);
+ try{
+ check("Non-Julian First/last of month", fl_2.dst_local_start_time(2003) ==
+ ptime(date(2003,Mar,1),hours(2)));
+ }catch(std::exception&){
+ check("Expected exception caught for Non-Julian day of 59, in non-leap year (Feb-29)", true);
+ }
+ check("Non-Julian First/last of month", fl_2.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,31),hours(2)));
+
+ // Mar-01 & Oct-31 leap year, count begins at 0
+ spec = "FST+3FDT,60,304";
+ posix_time_zone fl_3(spec);
+ check("Non-Julian First/last of month", fl_3.dst_local_start_time(2004) ==
+ ptime(date(2004,Mar,1),hours(2)));
+ check("Non-Julian First/last of month", fl_3.dst_local_end_time(2004) ==
+ ptime(date(2004,Oct,31),hours(2)));
+ }
+
+ printTestStats();
+ return 0;
+}
+
diff --git a/src/boost/libs/date_time/test/local_time/testtz_database.cpp b/src/boost/libs/date_time/test/local_time/testtz_database.cpp
new file mode 100644
index 000000000..add2943b3
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testtz_database.cpp
@@ -0,0 +1,116 @@
+/* Copyright (c) 2003-2005 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+
+#include "../testfrmwk.hpp"
+#include "boost/date_time/gregorian/gregorian.hpp"
+#include "boost/date_time/posix_time/posix_time.hpp"
+#include "boost/date_time/local_time/custom_time_zone.hpp"
+#include "boost/date_time/local_time/local_time_types.hpp"
+#include "boost/date_time/local_time/tz_database.hpp"
+#include "boost/date_time/local_time/posix_time_zone.hpp"
+#include <iostream>
+
+bool run_bad_field_count_test(char const* fn);
+
+int main(int /* argc */, char const* argv[]){
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+
+ /* NOTE: The testlocal_time_facet tests required full names
+ * be added to some of the date_time_zonespec.csv entries. The
+ * tests here also use those full names. Those entries are:
+ * Chicago, Denver, Los_Angeles, New_York, and Phoenix
+ * have all had full names added */
+
+ // run the exception tests first
+ try{
+ tz_database tz_db;
+ tz_db.load_from_file("missing_file.csv"); // file does not exist
+ }catch(data_not_accessible&){
+ check("Caught Missing data file exception", true);
+ }catch(...){
+ check("Caught first unexpected exception", false);
+ }
+ check("Caught Bad field count exception", run_bad_field_count_test(argv[2]));
+
+ tz_database tz_db;
+ try {
+ tz_db.load_from_file(argv[1]);
+ }catch(...) {
+ check("Cannot locate data file - aborting.", false);
+ return printTestStats();
+ }
+
+ time_zone_ptr bad_tz = tz_db.time_zone_from_region("Invalid/name");
+ check("Expected null pointer return", bad_tz == time_zone_ptr());
+
+ time_zone_ptr nyc_test = tz_db.time_zone_from_region("America/New_York");
+ check("nyc Valid pointer", nyc_test != time_zone_ptr() );
+ check("nyc Abbreviations",nyc_test->std_zone_abbrev() == std::string("EST"));
+ check("nyc Full Name", nyc_test->std_zone_name() == std::string("Eastern Standard Time"));
+ check("nyc Abbreviations",nyc_test->dst_zone_abbrev() == std::string("EDT"));
+ //std::cout << nyc_test->std_zone_name() << std::endl;
+ check("nyc Full Name", nyc_test->dst_zone_name() == std::string("Eastern Daylight Time"));
+ check("nyc GMT Offset", nyc_test->base_utc_offset() == hours(-5));
+ check("nyc DST Offset", nyc_test->dst_offset() == hours(1));
+ //std::cout << nyc_test->dst_local_start_time(2004) << std::endl;
+ check("nyc dst start", nyc_test->dst_local_start_time(2007) == ptime(date(2007, Mar, 11), hours(2)));
+ check("nyc dst end", nyc_test->dst_local_end_time(2007) == ptime(date(2007, Nov, 4), hours(2)));
+ check("nyc has dst", nyc_test->has_dst());
+
+ time_zone_ptr phx_test = tz_db.time_zone_from_region("America/Phoenix");
+ check("az Valid pointer", phx_test != time_zone_ptr() );
+ check("az Abbreviations",phx_test->std_zone_abbrev() == std::string("MST"));
+ check("az Full Name", phx_test->std_zone_name() == std::string("Mountain Standard Time"));
+ check("az Abbreviations", phx_test->dst_zone_abbrev() == std::string(""));
+ check("az Full Name", phx_test->dst_zone_name() == std::string(""));
+ check("az GMT Offset", phx_test->base_utc_offset() == hours(-7));
+ check("az DST Offset", phx_test->dst_offset() == hours(0));
+ //std::cout << phx_test->dst_local_start_time(2004) << std::endl;
+ check("az has dst", phx_test->has_dst() == false);
+
+ //Now add and retrieve a Posix tz spec from the database
+ 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"));
+ tz_db.add_record("United States/Eastern", eastern);
+ time_zone_ptr eastern_test = tz_db.time_zone_from_region("United States/Eastern");
+ check("eastern Valid pointer", eastern_test != time_zone_ptr() );
+ check("eastern Abbreviations",
+ eastern_test->std_zone_abbrev() == std::string("EST"));
+ check("eastern Abbreviations",
+ eastern_test->std_zone_name() == std::string("EST"));
+ check("eastern Abbreviations",
+ eastern_test->dst_zone_abbrev() == std::string("EDT"));
+ check("eastern Abbreviations",
+ eastern_test->dst_zone_name() == std::string("EDT"));
+ check("eastern GMT Offset", eastern_test->base_utc_offset() == hours(-5));
+ check("eastern dst start", eastern_test->dst_local_start_time(2004) == ptime(date(2004, Apr, 4), hours(2)));
+ check("eastern dst end", eastern_test->dst_local_end_time(2004) == ptime(date(2004, Oct, 31), hours(2)));
+ check("eastern has dst", eastern_test->has_dst() == true);
+
+
+ return printTestStats();
+}
+
+/* This test only checks to make sure the bad_field_count exception
+ * is properly thrown. It does not pay any attention to any other
+ * exception, those are tested elsewhere. */
+bool run_bad_field_count_test(char const* fn)
+{
+ using namespace boost::local_time;
+ bool caught_bfc = false;
+ tz_database other_db;
+ try{
+ other_db.load_from_file(fn);
+ }catch(bad_field_count&){
+ caught_bfc = true;
+ }catch(...) {
+ // do nothing (file not found)
+ }
+ return caught_bfc;
+}
diff --git a/src/boost/libs/date_time/test/local_time/testwcustom_time_zone.cpp b/src/boost/libs/date_time/test/local_time/testwcustom_time_zone.cpp
new file mode 100644
index 000000000..ad25ac31d
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testwcustom_time_zone.cpp
@@ -0,0 +1,89 @@
+/* Copyright (c) 2003-2005 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+#include "boost/date_time/local_time/local_time.hpp"
+#include "../testfrmwk.hpp"
+#include <iostream>
+
+int
+main()
+{
+
+ using namespace boost::gregorian;
+ using namespace boost::posix_time;
+ using namespace boost::local_time;
+
+ typedef custom_time_zone_base<wchar_t> wcustom_time_zone;
+
+ boost::shared_ptr<dst_calc_rule>
+ rule1(new partial_date_dst_rule(partial_date(30,Apr),
+ partial_date(30,Oct)));
+
+ boost::shared_ptr<dst_calc_rule>
+ rule2(new first_last_dst_rule(first_last_dst_rule::start_rule(Sunday,Apr),
+ first_last_dst_rule::end_rule(Sunday,Oct)));
+ boost::shared_ptr<dst_calc_rule>
+ rule3(new last_last_dst_rule(last_last_dst_rule::start_rule(Sunday,Mar),
+ last_last_dst_rule::end_rule(Sunday,Oct)));
+ boost::shared_ptr<dst_calc_rule> rule4; // no daylight savings
+
+ wtime_zone_names pst(L"Pacific Standard Time",
+ L"PST",
+ L"Pacific Daylight Time" ,
+ L"PDT");
+ wtime_zone_names mst(L"Mountain Standard Time",
+ L"MST",
+ L"" ,
+ L"");
+
+ dst_adjustment_offsets of(hours(1), hours(2), hours(2));
+ dst_adjustment_offsets of2(hours(0), hours(0), hours(0)); // no daylight savings
+
+ wtime_zone_ptr tz1(new wcustom_time_zone(pst, hours(-8), of, rule1));
+ wtime_zone_ptr tz2(new wcustom_time_zone(pst, hours(-8), of, rule2));
+ wtime_zone_ptr tz3(new wcustom_time_zone(pst, hours(-8), of, rule3));
+ wtime_zone_ptr tz4(new wcustom_time_zone(mst, hours(-7), of2, rule4));
+
+ check("out string",
+ tz1->dst_zone_abbrev() == std::wstring(L"PDT"));
+ check("out string",
+ tz1->std_zone_abbrev() == std::wstring(L"PST"));
+ check("out string",
+ tz1->std_zone_name() == std::wstring(L"Pacific Standard Time"));
+ check("out string",
+ tz1->dst_zone_name() == std::wstring(L"Pacific Daylight Time"));
+
+ check("dst offset", tz1->dst_offset() == hours(1));
+ check("base offset", tz1->base_utc_offset() == hours(-8));
+ check("has dst", tz1->has_dst());
+
+ check("dst start time",
+ tz1->dst_local_start_time(2003) == ptime(date(2003,Apr,30),hours(2)));
+ check("dst end time",
+ tz1->dst_local_end_time(2003) == ptime(date(2003,Oct,30),hours(2)));
+
+ check("tz1 to posix string",
+ tz1->to_posix_string() == std::wstring(L"PST-08PDT+01,120/02:00,303/02:00"));
+ check("tz2 to posix string",
+ tz2->to_posix_string() == std::wstring(L"PST-08PDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+ check("tz3 to posix string",
+ tz3->to_posix_string() == std::wstring(L"PST-08PDT+01,M3.5.0/02:00,M10.5.0/02:00"));
+ check("tz4 to posix string",
+ tz4->to_posix_string() == std::wstring(L"MST-07"));
+
+ // test start/end for non-dst zone
+ check("has dst in non-dst zone", !tz4->has_dst());
+ check("dst start in non-dst zone",
+ tz4->dst_local_start_time(2005) == ptime(not_a_date_time));
+ check("dst end in non-dst zone",
+ tz4->dst_local_end_time(2005) == ptime(not_a_date_time));
+
+
+ return printTestStats();
+}
+
+
diff --git a/src/boost/libs/date_time/test/local_time/testwposix_time_zone.cpp b/src/boost/libs/date_time/test/local_time/testwposix_time_zone.cpp
new file mode 100644
index 000000000..2bd11cbd6
--- /dev/null
+++ b/src/boost/libs/date_time/test/local_time/testwposix_time_zone.cpp
@@ -0,0 +1,224 @@
+/* Copyright (c) 2003-2004 CrystalClear Software, Inc.
+ * Subject to the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
+ * Author: Jeff Garland, Bart Garst
+ * $Date$
+ */
+
+
+#include "boost/date_time/gregorian/gregorian.hpp"
+//#include "boost/date_time/local_time/time_zone.hpp"
+#include "../testfrmwk.hpp"
+
+#include "boost/date_time/local_time/posix_time_zone.hpp"
+
+#include <string>
+#include <iostream>
+
+int main(){
+ using namespace boost::local_time;
+ using namespace boost::posix_time;
+ using namespace boost::gregorian;
+
+ typedef posix_time_zone_base<wchar_t> w_posix_time_zone;
+
+ std::wstring specs[] = {L"MST-07", L"MST-07:00:00",L"EST-05EDT,M4.1.0,M10.5.0", L"EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00",L"PST-08PDT,J46/1:30,J310",L"PST-08PDT,45,310/0:30:00"};
+
+ w_posix_time_zone nyc1(specs[2]);
+ w_posix_time_zone nyc2(specs[3]);
+ time_duration td = hours(-5);
+
+ check("Has DST", nyc1.has_dst() && nyc2.has_dst());
+ check("UTC offset", nyc1.base_utc_offset() == td);
+ check("UTC offsets match", nyc1.base_utc_offset() == nyc2.base_utc_offset());
+ check("Abbrevs", nyc1.std_zone_abbrev() == std::wstring(L"EST"));
+ check("Abbrevs", nyc2.std_zone_abbrev() == std::wstring(L"EST"));
+ check("Abbrevs", nyc1.dst_zone_abbrev() == std::wstring(L"EDT"));
+ check("Abbrevs", nyc2.dst_zone_abbrev() == std::wstring(L"EDT"));
+ // names not available for w_posix_time_zone, abbrevs used in their place
+ check("Names", nyc1.std_zone_name() == std::wstring(L"EST"));
+ check("Names", nyc2.std_zone_name() == std::wstring(L"EST"));
+ check("Names", nyc1.dst_zone_name() == std::wstring(L"EDT"));
+ check("Names", nyc2.dst_zone_name() == std::wstring(L"EDT"));
+ td = hours(1);
+ check("dst offset", nyc1.dst_offset() == td);
+ check("dst offsets match", nyc1.dst_offset() == nyc2.dst_offset());
+ check("dst start", nyc1.dst_local_start_time(2003) ==
+ ptime(date(2003,Apr,6),time_duration(2,0,0)));
+ check("dst starts match", nyc1.dst_local_start_time(2003) ==
+ nyc2.dst_local_start_time(2003));
+ check("dst end", nyc1.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,26),time_duration(2,0,0)));
+ check("dst ends match", nyc1.dst_local_end_time(2003) ==
+ nyc2.dst_local_end_time(2003));
+ check("to posix string",
+ nyc1.to_posix_string() == std::wstring(L"EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+ check("to posix string",
+ nyc2.to_posix_string() == std::wstring(L"EST-05EDT+01,M4.1.0/02:00,M10.5.0/02:00"));
+
+
+ w_posix_time_zone az1(specs[0]);
+ w_posix_time_zone az2(specs[1]);
+ td = hours(-7);
+
+ check("Has DST", !az1.has_dst() && !az2.has_dst());
+ check("UTC offset", az1.base_utc_offset() == td);
+ check("UTC offsets match", az1.base_utc_offset() == az2.base_utc_offset());
+ check("dst start in non-dst zone",
+ az1.dst_local_start_time(2005) == ptime(not_a_date_time));
+ check("dst end in non-dst zone",
+ az2.dst_local_end_time(2005) == ptime(not_a_date_time));
+ check("Abbrevs", az1.std_zone_abbrev() == std::wstring(L"MST"));
+ check("Abbrevs", az2.std_zone_abbrev() == std::wstring(L"MST"));
+ // non-dst zones default to empty strings for dst names & abbrevs
+ check("Abbrevs", az1.dst_zone_abbrev() == std::wstring(L""));
+ check("Abbrevs", az2.dst_zone_abbrev() == std::wstring(L""));
+ check("Names", az1.std_zone_name() == std::wstring(L"MST"));
+ check("Names", az2.std_zone_name() == std::wstring(L"MST"));
+ check("Names", az1.dst_zone_name() == std::wstring(L""));
+ check("Names", az2.dst_zone_name() == std::wstring(L""));
+ check("to posix string",
+ az1.to_posix_string() == std::wstring(L"MST-07"));
+ check("to posix string",
+ az2.to_posix_string() == std::wstring(L"MST-07"));
+
+
+ // bizzar time zone spec to fully test parsing
+ std::cout << "\nFictitious time zone" << std::endl;
+ w_posix_time_zone bz(L"BST+11:21:15BDT-00:28,M2.2.4/03:15:42,M11.5.2/01:08:53");
+ check("hast dst", bz.has_dst());
+ check("UTC offset", bz.base_utc_offset() == time_duration(11,21,15));
+ check("Abbrev", bz.std_zone_abbrev() == std::wstring(L"BST"));
+ check("Abbrev", bz.dst_zone_abbrev() == std::wstring(L"BDT"));
+ check("dst offset", bz.dst_offset() == time_duration(0,-28,0));
+ check("dst start", bz.dst_local_start_time(1962) ==
+ ptime(date(1962,Feb,8),time_duration(3,15,42)));
+ check("dst end", bz.dst_local_end_time(1962) ==
+ ptime(date(1962,Nov,27),time_duration(1,8,53)));
+
+ // only checking start & end rules w/ 'J' notation
+ std::cout << "\n'J' notation Start/End rule tests..." << std::endl;
+ w_posix_time_zone la1(specs[4]); // "PST-08PDT,J124,J310"
+ //w_posix_time_zone la1("PST-08PDT,J1,J365");// Jan1/Dec31
+ check("dst start", la1.dst_local_start_time(2003) ==
+ ptime(date(2003,Feb,15),time_duration(1,30,0)));
+ check("dst end", la1.dst_local_end_time(2003) ==
+ ptime(date(2003,Nov,6),time_duration(2,0,0)));
+ /* NOTE: la1 was created from a 'J' notation string but to_posix_string
+ * returns an 'n' notation string. The difference between the two
+ * is Feb-29 is always counted in an 'n' notation string and numbering
+ * starts at zero ('J' notation starts at one).
+ * Every possible date spec that can be written in 'J' notation can also
+ * be written in 'n' notation. The reverse is not true so 'n' notation
+ * is used as the output for to_posix_string(). */
+ check("to posix string",
+ la1.to_posix_string() == std::wstring(L"PST-08PDT+01,45/01:30,310/02:00"));
+
+ // only checking start & end rules w/ 'n' notation
+ std::cout << "\n'n' notation Start/End rule tests..." << std::endl;
+ w_posix_time_zone la2(specs[5]); // "PST-08PDT,124,310"
+ //w_posix_time_zone la2("PST-08PDT,0,365");// Jan1/Dec31
+ check("dst start", la2.dst_local_start_time(2003) ==
+ ptime(date(2003,Feb,15),time_duration(2,0,0)));
+ check("dst end", la2.dst_local_end_time(2003) ==
+ ptime(date(2003,Nov,6),time_duration(0,30,0)));
+ check("to posix string",
+ la2.to_posix_string() == std::wstring(L"PST-08PDT+01,45/02:00,310/00:30"));
+
+ // bad posix time zone strings tests
+ std::cout << "\nInvalid time zone string tests..." << std::endl;
+ try {
+ w_posix_time_zone badz(L"EST-13");
+ check("Exception not thrown: bad UTC offset", false);
+ }catch(bad_offset& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ w_posix_time_zone badz(L"EST-5EDT24:00:01,J124/1:30,J310");
+ check("Exception not thrown: bad DST adjust", false);
+ }catch(bad_adjustment& badj){
+ std::string msg(badj.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ w_posix_time_zone badz(L"EST-5EDT01:00:00,J124/-1:30,J310");
+ check("Exception not thrown: bad DST start/end offset", false);
+ }catch(bad_offset& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }
+ try {
+ w_posix_time_zone badz(L"EST-5EDT01:00:00,J124/1:30,J370");
+ check("Exception not thrown: invalid date spec", false);
+ }catch(boost::gregorian::bad_day_of_month& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }catch(boost::gregorian::bad_month& boff){
+ std::string msg(boff.what());
+ check("Exception caught: "+msg , true);
+ }catch(...){
+ check("Unexpected exception caught: ", false);
+ }
+
+ std::cout << "\nTest some Central Europe specs" << std::endl;
+
+ //Test a timezone spec on the positive side of the UTC line.
+ //This is the time for central europe which is one hour in front of UTC
+ //Note these Summer time transition rules aren't actually correct.
+ w_posix_time_zone cet_tz(L"CET+01:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00");
+ check("Has DST", cet_tz.has_dst());
+ check("UTC offset", cet_tz.base_utc_offset() == hours(1));
+ check("Abbrevs", cet_tz.std_zone_abbrev() == std::wstring(L"CET"));
+// check("Abbrevs", nyc2.std_zone_abbrev() == std::wstring("EST"));
+
+ std::cout << "\nTest some Central Austrialia UTC+8:30" << std::endl;
+
+ //Test a timezone spec on the positive side of the UTC line.
+ //This is the time for central europe which is one hour in front of UTC
+ //Note these Summer time transition rules aren't actually correct.
+ w_posix_time_zone caus_tz(L"CAS+08:30:00CDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00");
+ check("Has DST", caus_tz.has_dst());
+ check("UTC offset", caus_tz.base_utc_offset() == hours(8)+minutes(30));
+ check("Abbrevs", caus_tz.std_zone_abbrev() == std::wstring(L"CAS"));
+// check("Abbrevs", nyc2.std_zone_abbrev() == std::wstring("EST"));
+
+ {
+ /**** first/last of month Julian & non-Julian tests ****/
+ // Mar-01 & Oct-31, count begins at 1
+ std::wstring spec(L"FST+3FDT,J60,J304");
+ w_posix_time_zone fl_1(spec);
+ check("Julian First/last of month", fl_1.dst_local_start_time(2003) ==
+ ptime(date(2003,Mar,1),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,31),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_start_time(2004) ==
+ ptime(date(2004,Mar,1),hours(2)));
+ check("Julian First/last of month", fl_1.dst_local_end_time(2004) ==
+ ptime(date(2004,Oct,31),hours(2)));
+
+ // Mar-01 & Oct-31 Non-leap year, count begins at 0
+ spec = L"FST+3FDT,59,304"; // "304" is not a mistake here, see posix_time_zone docs
+ w_posix_time_zone fl_2(spec);
+ try{
+ check("Non-Julian First/last of month", fl_2.dst_local_start_time(2003) ==
+ ptime(date(2003,Mar,1),hours(2)));
+ }catch(std::exception&){
+ check("Expected exception caught for Non-Julian day of 59, in non-leap year (Feb-29)", true);
+ }
+ check("Non-Julian First/last of month", fl_2.dst_local_end_time(2003) ==
+ ptime(date(2003,Oct,31),hours(2)));
+
+ // Mar-01 & Oct-31 leap year, count begins at 0
+ spec = L"FST+3FDT,60,304";
+ w_posix_time_zone fl_3(spec);
+ check("Non-Julian First/last of month", fl_3.dst_local_start_time(2004) ==
+ ptime(date(2004,Mar,1),hours(2)));
+ check("Non-Julian First/last of month", fl_3.dst_local_end_time(2004) ==
+ ptime(date(2004,Oct,31),hours(2)));
+ }
+
+ printTestStats();
+ return 0;
+}
+