Skip to content

Commit d908f96

Browse files
lahwaaczdongjoon-hyun
authored andcommitted
ORC-2021: Fallback to UTC when /etc/localtime does not exist
### What changes were proposed in this pull request? This PR aims to fallback to `UTC` when `/etc/localtime` doesn't exist. ### Why are the changes needed? To handle OSes which doesn't have it. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #2225 Closes #2432 from lahwaacz/timezone-fallback. Authored-by: Jakub Klinkovský <1289205+lahwaacz@users.noreply.github.com> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
1 parent b50fb37 commit d908f96

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

c++/src/Timezone.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#include <map>
2929
#include <sstream>
3030

31+
#ifndef _MSC_VER
32+
#include <sys/stat.h>
33+
#include <sys/types.h>
34+
#include <unistd.h>
35+
#endif
36+
3137
namespace orc {
3238

3339
// default location of the timezone files
@@ -780,6 +786,17 @@ namespace orc {
780786
#ifdef _MSC_VER
781787
return getTimezoneByName("UTC");
782788
#else
789+
// The absence of LOCAL_TIMEZONE means UTC conventionally
790+
{
791+
std::string filename(LOCAL_TIMEZONE_DIR);
792+
filename += "/";
793+
filename += LOCAL_TIMEZONE;
794+
struct stat _ignored;
795+
if (stat(filename.c_str(), &_ignored) == -1) {
796+
return getTimezoneByName("UTC");
797+
}
798+
}
799+
783800
return getTimezoneByFilename(LOCAL_TIMEZONE_DIR, LOCAL_TIMEZONE);
784801
#endif
785802
}

0 commit comments

Comments
 (0)