2015-09-29 19:19:54 +00:00
|
|
|
#include <common/DateLUT.h>
|
2015-06-26 17:57:49 +00:00
|
|
|
|
2017-01-22 09:27:51 +00:00
|
|
|
#include <Poco/Exception.h>
|
|
|
|
|
2016-11-02 09:29:39 +00:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#ifdef __APPLE__
|
|
|
|
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
|
|
|
#endif
|
2015-06-26 15:11:31 +00:00
|
|
|
#include <unicode/timezone.h>
|
|
|
|
#include <unicode/unistr.h>
|
2016-11-02 09:29:39 +00:00
|
|
|
#pragma GCC diagnostic pop
|
2009-05-28 18:19:51 +00:00
|
|
|
|
2017-01-22 09:27:51 +00:00
|
|
|
|
2013-08-11 03:40:14 +00:00
|
|
|
DateLUT::DateLUT()
|
2009-05-28 18:19:51 +00:00
|
|
|
{
|
2016-11-13 19:34:31 +00:00
|
|
|
/// Initialize the pointer to the default DateLUTImpl.
|
2015-07-07 23:11:30 +00:00
|
|
|
|
2017-01-22 09:27:51 +00:00
|
|
|
std::unique_ptr<icu::TimeZone> tz(icu::TimeZone::createDefault());
|
2016-11-13 19:34:31 +00:00
|
|
|
if (tz == nullptr)
|
|
|
|
throw Poco::Exception("Failed to determine the host time zone.");
|
2013-08-11 03:40:14 +00:00
|
|
|
|
2017-01-22 09:27:51 +00:00
|
|
|
icu::UnicodeString u_out;
|
2016-11-13 19:34:31 +00:00
|
|
|
tz->getID(u_out);
|
|
|
|
std::string default_time_zone;
|
|
|
|
u_out.toUTF8String(default_time_zone);
|
2013-08-11 03:40:14 +00:00
|
|
|
|
2016-11-13 19:34:31 +00:00
|
|
|
default_impl.store(&getImplementation(default_time_zone), std::memory_order_release);
|
2009-05-28 18:19:51 +00:00
|
|
|
}
|
2017-01-22 09:27:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
const DateLUTImpl & DateLUT::getImplementation(const std::string & time_zone) const
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
|
|
|
|
auto it = impls.find(time_zone);
|
|
|
|
if (it == impls.end())
|
|
|
|
it->second = std::make_unique<DateLUTImpl>(time_zone);
|
|
|
|
|
2017-01-22 10:03:28 +00:00
|
|
|
return *it->second;
|
2017-01-22 09:27:51 +00:00
|
|
|
}
|