diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-01-06 20:00:59 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-01-07 20:22:28 +0100 |
| commit | 9eb50432aabf0e09f3db66294564ec91fac2c94d (patch) | |
| tree | 1ba55735215ae3f39d061513b6a58d91f0e40f9e /src | |
| parent | cf50dd3ac0153935f6b4f1ae9da16bc2b473d1a0 (diff) | |
Fix email date format in non-English locales (#2928).2928-email
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/email.cc | 7 | ||||
| -rw-r--r-- | src/lib/email.h | 4 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/lib/email.cc b/src/lib/email.cc index 2da57e257..a731501bc 100644 --- a/src/lib/email.cc +++ b/src/lib/email.cc @@ -24,6 +24,7 @@ #include "email.h" #include "exceptions.h" #include "variant.h" +#include <dcp/scope_guard.h> #include <curl/curl.h> #include <boost/algorithm/string.hpp> #include <boost/date_time/c_local_time_adjustor.hpp> @@ -113,7 +114,11 @@ void Email::create(time_t time) { char date_buffer[128]; - strftime(date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime(&time)); + + auto english_locale = newlocale(LC_TIME_MASK, "C", 0); + DCPOMATIC_ASSERT(english_locale); + dcp::ScopeGuard sg = [english_locale]() { freelocale(english_locale); }; + strftime_l(date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime(&time), english_locale); auto const utc_time = boost::posix_time::second_clock::universal_time(); auto const local_time = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local(utc_time); diff --git a/src/lib/email.h b/src/lib/email.h index 24f20956a..3f9cf1dd8 100644 --- a/src/lib/email.h +++ b/src/lib/email.h @@ -24,6 +24,9 @@ #include <boost/scoped_array.hpp> +struct email_date_format_test; + + class Email { public: @@ -51,6 +54,7 @@ public: static std::string address_list(std::vector<std::string> addresses); private: + friend struct ::email_date_format_test; std::string fix (std::string s) const; static std::string encode_rfc1342 (std::string subject); |
