gnucash maint: Fix unlocalized date in status bar.
John Ralls
jralls at code.gnucash.org
Sat Jan 19 17:21:45 EST 2019
Updated via https://github.com/Gnucash/gnucash/commit/e31f4c3f (commit)
from https://github.com/Gnucash/gnucash/commit/72ef48cb (commit)
commit e31f4c3f95f12871f8633843cf5cffe53196830d
Author: John Ralls <jralls at ceridwen.us>
Date: Sat Jan 19 13:41:17 2019 -0800
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.
diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index c73fc0a..e1946ec 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -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();
}
diff --git a/libgnucash/engine/test/gtest-gnc-datetime.cpp b/libgnucash/engine/test/gtest-gnc-datetime.cpp
index 108bcf4..970ad0d 100644
--- a/libgnucash/engine/test/gtest-gnc-datetime.cpp
+++ b/libgnucash/engine/test/gtest-gnc-datetime.cpp
@@ -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");
}
}
Summary of changes:
libgnucash/engine/gnc-datetime.cpp | 30 ++++++++-------------------
libgnucash/engine/test/gtest-gnc-datetime.cpp | 2 +-
2 files changed, 10 insertions(+), 22 deletions(-)
More information about the gnucash-changes
mailing list