Skip to content

Commit 76a58c3

Browse files
authored
On Ubuntu, GetTimezone should return the long time zone name. (#1380)
* On Ubuntu, GetTimezone should return the long time zone name. * Fix buffer size. * Format code.
1 parent 6a59781 commit 76a58c3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/src/locale.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define UCHAR_TYPE wchar_t
3131
#include <icu.h>
3232
#elif FIREBASE_PLATFORM_LINUX
33+
#include <stdio.h>
34+
3335
#include <clocale>
3436
#include <ctime>
3537
#else
@@ -180,6 +182,20 @@ std::string GetTimezone() {
180182
return iana_tz_utf8;
181183

182184
#elif FIREBASE_PLATFORM_LINUX
185+
// Ubuntu: Check /etc/timezone for the full time zone name.
186+
FILE* tz_file = fopen("/etc/timezone", "r");
187+
if (tz_file) {
188+
const size_t kBufSize = 128;
189+
char buf[kBufSize];
190+
if (fgets(buf, kBufSize, tz_file)) {
191+
// Remove a trailing '\n', if any.
192+
size_t len = strlen(buf);
193+
if (buf[len - 1] == '\n') {
194+
buf[len - 1] = '\0';
195+
}
196+
return std::string(buf);
197+
}
198+
}
183199
// If TZ environment variable is defined and not empty, use it, else use
184200
// tzname.
185201
return (getenv("TZ") && *getenv("TZ")) ? getenv("TZ")

0 commit comments

Comments
 (0)