adopt server timezone in non-interactive mode also

This commit is contained in:
Alexey Zatelepin 2016-11-17 00:12:08 +00:00
parent cbed811b95
commit 307e397dce
3 changed files with 32 additions and 29 deletions

View File

@ -130,7 +130,7 @@ public:
void getServerVersion(String & name, UInt64 & version_major, UInt64 & version_minor, UInt64 & revision);
const String & getServerTimezone() const;
const String & getServerTimezone();
/// For log and exception messages.
const String & getDescription() const;

View File

@ -327,6 +327,33 @@ private:
connect();
/// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос.
DateLUT::instance();
if (!context.getSettingsRef().use_client_time_zone)
{
const auto & time_zone = connection->getServerTimezone();
if (!time_zone.empty())
{
try
{
DateLUT::setDefaultTimezone(time_zone);
}
catch (...)
{
std::cerr << "Warning: could not switch to server time zone: " << time_zone
<< ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl
<< "Proceeding with local time zone."
<< std::endl << std::endl;
}
}
else
{
std::cerr << "Warning: could not determine server time zone. "
<< "Proceeding with local time zone."
<< std::endl << std::endl;
}
}
if (is_interactive)
{
if (print_time_to_stderr)
@ -355,33 +382,6 @@ private:
Poco::File(history_file).createFile();
}
/// Инициализируем DateLUT, чтобы потраченное время не отображалось, как время, потраченное на запрос.
DateLUT::instance();
if (!context.getSettingsRef().use_client_time_zone)
{
const auto & time_zone = connection->getServerTimezone();
if (!time_zone.empty())
{
try
{
DateLUT::setDefaultTimezone(time_zone);
}
catch (...)
{
std::cerr << "Warning: could not switch to server time zone: " << time_zone
<< ", reason: " << getCurrentExceptionMessage(/* with_stacktrace = */ false) << std::endl
<< "Proceeding with local time zone."
<< std::endl << std::endl;
}
}
else
{
std::cerr << "Warning: could not determine server time zone. "
<< "Proceeding with local time zone."
<< std::endl << std::endl;
}
}
loop();
std::cout << (isNewYearMode() ? "Happy new year." : "Bye.") << std::endl;

View File

@ -184,8 +184,11 @@ void Connection::getServerVersion(String & name, UInt64 & version_major, UInt64
revision = server_revision;
}
const String & Connection::getServerTimezone() const
const String & Connection::getServerTimezone()
{
if (!connected)
connect();
return server_timezone;
}