Skip to content
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

Add support for querying timezone on Android #846

Closed
wants to merge 1 commit into from
Closed

Add support for querying timezone on Android #846

wants to merge 1 commit into from

Conversation

skyline75489
Copy link
Contributor

No description provided.

@skyline75489
Copy link
Contributor Author

OK the code does not work. The compiler complains:

error[E0283]: type annotations needed
   --> src/output/table.rs:324:20
    |
324 |             return CompiledData::parse(output.stdout);
    |                    ^^^^^^^^^^^^^^^^^^^ cannot infer type
    |
    = note: cannot satisfy `_: CompiledData`
    = note: required by `zoneinfo_compiled::CompiledData::parse`

error: aborting due to previous error; 1 warning emitted

But I honestly don't know what's wrong with it.

let mut get_time_zone = Command::new("getprop");
get_time_zone.arg("persist.sys.timezone");
let output = get_time_zone.output().expect("fail to get time zone");
return CompiledData::parse(output.stdout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompiledData is a trait, and TimeZone is implementing this trait:

Suggested change
return CompiledData::parse(output.stdout);
return TimeZone::parse(output.stdout);

@@ -316,7 +316,15 @@ fn determine_time_zone() -> TZResult<TimeZone> {
}
})
} else {
TimeZone::from_file("/etc/localtime")
if env::consts::OS == "android" {
Copy link
Collaborator

@ariasuni ariasuni May 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it’s a good practice to include the “documentation” for this change.

Suggested change
if env::consts::OS == "android" {
// https://android.googlesource.com/platform/bionic/+/master/libc/tzcode/bionic.cpp
if env::consts::OS == "android" {

@ariasuni
Copy link
Collaborator

ariasuni commented May 8, 2021

Well actually your approach is wrong. persist.sys.timezone doesn’t contain the data to parse but I guess the filename relative to the directory containing the TZDATA, and Bionic’s source code seems to also take into account the «first format» described at https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html.

I’m really starting to think we should stop trying to replace the libc and use standard C function so that compatibility with OS isn’t such a nightmare of trying to understand what such or such libc are actually doing.

@skyline75489
Copy link
Contributor Author

Closed in favor of #867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants