Project

General

Profile

Feature #2840 ยป 0001-Support-postgres-TIMESTAMP-WITH-TIME-ZONE.patch

Bruce Toll, 03/22/2014 03:49 PM

View differences:

src/Wt/Dbo/backend/Postgres.C
else {
v = boost::posix_time::to_iso_extended_string(value);
v[v.find('T')] = ' ';
/*
* Add explicit timezone offset. Postgres will ignore this for a TIMESTAMP
* column, but will treat the timestamp as UTC in a TIMESTAMP WITH TIME ZONE
* column -- possibly in a legacy table.
*/
v.append("+00");
}
setValue(column, v);
......
if (type == SqlDate)
*value = boost::posix_time::ptime(boost::gregorian::from_string(v),
boost::posix_time::hours(0));
else
*value = boost::posix_time::time_from_string(v);
else {
/*
* Handle timezone offset. Postgres will append a timezone offset [+-]dd
* if a column is defined as TIMESTAMP WITH TIME ZONE -- possibly
* in a legacy table. If offset is present, subtract it for UTC output.
*/
if (v.size() >= 3 && std::strchr("+-", v[v.size() - 3]))
*value = boost::posix_time::time_from_string(v.substr(0, v.size() - 3)) -
boost::posix_time::hours(boost::lexical_cast<int>(v.substr(v.size() - 3)));
else
*value = boost::posix_time::time_from_string(v);
}
DEBUG(std::cerr << this
<< " result time_duration " << column << " " << *value << std::endl);
test/dbo/DboTest.C
delete model;
}
}
BOOST_AUTO_TEST_CASE( dbo_test22a )
{
#ifdef POSTGRES
DboFixture f;
dbo::Session *session_ = f.session_;
Wt::WDateTime datetime1 = Wt::WDateTime(Wt::WDate(2009, 10, 1),
Wt::WTime(12, 11, 31));
{
dbo::Transaction t(*session_);
session_->execute("SET TIME ZONE \"America/New_York\"");
dbo::ptr<A> a1(new A());
a1.modify()->datetime = datetime1;
session_->add(a1);
t.commit();
}
{
dbo::Transaction t(*session_);
dbo::ptr<A> a2 = session_->find<A>();
BOOST_REQUIRE(a2->datetime == datetime1);
}
#endif //POSTGRES
}
BOOST_AUTO_TEST_CASE( dbo_test22b )
{
#ifdef POSTGRES
DboFixture f;
dbo::Session *session_ = f.session_;
Wt::WDateTime datetime1 = Wt::WDateTime(Wt::WDate(2009, 10, 1),
Wt::WTime(12, 11, 31));
{
dbo::Transaction t(*session_);
session_->execute("SET TIME ZONE \"Europe/Brussels\"");
dbo::ptr<A> a1(new A());
a1.modify()->datetime = datetime1;
session_->add(a1);
t.commit();
}
{
dbo::Transaction t(*session_);
dbo::ptr<A> a2 = session_->find<A>();
BOOST_REQUIRE(a2->datetime == datetime1);
}
#endif //POSTGRES
}
BOOST_AUTO_TEST_CASE( dbo_test22c )
{
#ifdef POSTGRES
DboFixture f;
dbo::Session *session_ = f.session_;
Wt::WDateTime datetime1 = Wt::WDateTime(Wt::WDate(2009, 10, 1),
Wt::WTime(12, 11, 31));
{
dbo::Transaction t(*session_);
session_->execute("ALTER TABLE table_a ALTER COLUMN datetime "
"SET DATA TYPE TIMESTAMP WITH TIME ZONE" );
session_->execute("SET TIME ZONE \"America/New_York\"");
dbo::ptr<A> a1(new A());
a1.modify()->datetime = datetime1;
session_->add(a1);
t.commit();
}
{
dbo::Transaction t(*session_);
dbo::ptr<A> a2 = session_->find<A>();
BOOST_REQUIRE(a2->datetime == datetime1);
}
#endif //POSTGRES
}
BOOST_AUTO_TEST_CASE( dbo_test22d )
{
#ifdef POSTGRES
DboFixture f;
dbo::Session *session_ = f.session_;
Wt::WDateTime datetime1 = Wt::WDateTime(Wt::WDate(2009, 10, 1),
Wt::WTime(12, 11, 31));
{
dbo::Transaction t(*session_);
session_->execute("ALTER TABLE table_a ALTER COLUMN datetime "
"SET DATA TYPE TIMESTAMP WITH TIME ZONE" );
session_->execute("SET TIME ZONE \"Europe/Brussels\"");
dbo::ptr<A> a1(new A());
a1.modify()->datetime = datetime1;
session_->add(a1);
t.commit();
}
{
dbo::Transaction t(*session_);
dbo::ptr<A> a2 = session_->find<A>();
BOOST_REQUIRE(a2->datetime == datetime1);
}
#endif //POSTGRES
}
    (1-1/1)