-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract timezone info from tzdata file on Android #978
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,19 +68,18 @@ struct Cache { | |
last_checked: SystemTime, | ||
} | ||
|
||
#[cfg(target_os = "android")] | ||
RumovZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const TZDB_LOCATION: &str = " /system/usr/share/zoneinfo"; | ||
|
||
#[cfg(target_os = "aix")] | ||
const TZDB_LOCATION: &str = "/usr/share/lib/zoneinfo"; | ||
|
||
#[allow(dead_code)] // keeps the cfg simpler | ||
#[cfg(not(any(target_os = "android", target_os = "aix")))] | ||
const TZDB_LOCATION: &str = "/usr/share/zoneinfo"; | ||
|
||
fn fallback_timezone() -> Option<TimeZone> { | ||
let tz_name = iana_time_zone::get_timezone().ok()?; | ||
#[cfg(not(target_os = "android"))] | ||
let bytes = fs::read(format!("{}/{}", TZDB_LOCATION, tz_name)).ok()?; | ||
#[cfg(target_os = "android")] | ||
let bytes = android_tzdata::find_tz_data(&tz_name).ok()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In PR code for Should
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. 👍 |
||
TimeZone::from_tz_data(&bytes).ok() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this moved up to above line 46? Also what do we do in the case that the
tz_string
is "localtime" on android?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have yet to find exhaustive documentation on this, but from what I can tell,
tzdata
doesn't contain alocaltime
entry, and there is/etc/localtime
like on other Unix systems. Moving thetzdata
block up sounds good to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked an Android device here, and it does not have an /etc/localtime - perhaps they did away with it in later Android releases, or it varies by manufacturer? Android appears to set TZ to the timezone configured in the settings by default, so presumably users would not hit this unless they explicitly overwrote the default value.