mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix unlocalized date in status bar.
It seems that std::locales created by boost::locale::generator are not entirely compatible: If used to create a new locale with a facet for boost::date_time one ends up with the C locale and the facet. For the time being avoid the problem by using boost::locale to format dates and times. std::chrono gets calendar functions in C++20 so we can switch date-time backends once we can adopt it.
This commit is contained in:
parent
72ef48cbf2
commit
e31f4c3f95
@ -30,6 +30,7 @@ extern "C"
|
||||
#include <boost/date_time/gregorian/gregorian.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/date_time/local_time/local_time.hpp>
|
||||
#include <boost/locale.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
@ -431,35 +432,22 @@ normalize_format (const std::string& format)
|
||||
std::string
|
||||
GncDateTimeImpl::format(const char* format) const
|
||||
{
|
||||
using Facet = boost::local_time::local_time_facet;
|
||||
static std::locale cachedLocale;
|
||||
static bool cachedLocaleAvailable = false;
|
||||
namespace as = boost::locale::as;
|
||||
std::stringstream ss;
|
||||
|
||||
if(!cachedLocaleAvailable)
|
||||
{
|
||||
cachedLocale = std::locale("");
|
||||
cachedLocaleAvailable = true;
|
||||
}
|
||||
|
||||
//The stream destructor frees the facet, so it must be heap-allocated.
|
||||
auto output_facet(new Facet(normalize_format(format).c_str()));
|
||||
// FIXME Rather than imbueing a locale below we probably should set std::locale::global appropriately somewhere.
|
||||
ss.imbue(std::locale(gnc_get_locale(), output_facet));
|
||||
ss << m_time;
|
||||
ss.imbue(gnc_get_locale());
|
||||
ss << as::ftime(format)
|
||||
<< as::time_zone(m_time.zone()->std_zone_name())
|
||||
<< static_cast<time64>(*this);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string
|
||||
GncDateTimeImpl::format_zulu(const char* format) const
|
||||
{
|
||||
using Facet = boost::posix_time::time_facet;
|
||||
namespace as = boost::locale::as;
|
||||
std::stringstream ss;
|
||||
//The stream destructor frees the facet, so it must be heap-allocated.
|
||||
auto output_facet(new Facet(normalize_format(format).c_str()));
|
||||
// FIXME Rather than imbueing a locale below we probably should set std::locale::global appropriately somewhere.
|
||||
ss.imbue(std::locale(gnc_get_locale(), output_facet));
|
||||
ss << m_time.utc_time();
|
||||
ss.imbue(gnc_get_locale());
|
||||
ss << as::ftime(format) << as::gmt << static_cast<time64>(*this);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ TEST(gnc_datetime_constructors, test_gncdate_neutral_constructor)
|
||||
if (gncdt.offset() >= max_western_offset &&
|
||||
gncdt.offset() <= max_eastern_offset)
|
||||
{
|
||||
EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S %z"), "20-04-2017 10:59:00 UTC");
|
||||
EXPECT_EQ(atime.format("%d-%m-%Y %H:%M:%S %Z"), "20-04-2017 10:59:00 GMT");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user