date icon indicating copy to clipboard operation
date copied to clipboard

current_zone() not working on Android

Open oviano opened this issue 3 years ago • 6 comments

Specifically a Samsung Galaxy Tab running Android 10.

It drops threw to the bottom of the function and throws an exception. I've verified the locations this function searches for aren't present on the device.

So far I've only found a Java API for accessing this information, so if you wanted to add Android support there would need to be some JNI shenanigans undertaken.

oviano avatar Aug 02 '21 09:08 oviano

Thanks for the report.

current_zone() is the most non-portable function in this library. I don't have a Samsung Galaxy Tab to experiment with.

I'm 80% sure that there is somewhere on disk this information exists. JNI has to get it from somewhere. If you can find it, I'd be glad to accept a patch, or create one myself to have you test.

HowardHinnant avatar Aug 02 '21 14:08 HowardHinnant

So I've located the tzdata data, which is in /system/usr/share/zoneinfo.

But after some more web trawling, I found only that I can retrieve the timezone using the following command from a terminal in Android Studio:

% adb shell getprop persist.sys.timezone Europe/London

Where this comes from....who knows, as there appears to be no folders related to clocks or anything other locations mentioned on the web for different Linux distros.

For me, I've already done the JNI dance for some other stuff, so it's not a big deal to get the string returned by the Java call

TimeZone.getDefault().getID()

oviano avatar Aug 02 '21 15:08 oviano

Can std::system be used to execute adb shell getprop persist.sys.timezone from C++?

HowardHinnant avatar Aug 02 '21 15:08 HowardHinnant

Or perhaps do a global search of files that contain "Europe/London"?

HowardHinnant avatar Aug 02 '21 15:08 HowardHinnant

Perhaps helpful: https://stackoverflow.com/a/48442083/576911

HowardHinnant avatar Aug 02 '21 16:08 HowardHinnant

In other words, they've taken their own custom approach.

Not too sure where this /data/property folder is, can't see that one on my device.

oviano avatar Aug 02 '21 16:08 oviano