Skip to content

Add support for querying timezone on Android#846

Closed
skyline75489 wants to merge 1 commit into
ogham:masterfrom
skyline75489:chesterliu/dev/android-1
Closed

Add support for querying timezone on Android#846
skyline75489 wants to merge 1 commit into
ogham:masterfrom
skyline75489:chesterliu/dev/android-1

Conversation

@skyline75489

Copy link
Copy Markdown
Contributor

No description provided.

@skyline75489

Copy link
Copy Markdown
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.

Comment thread src/output/table.rs
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
Copy Markdown
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);

Comment thread src/output/table.rs
})
} else {
TimeZone::from_file("/etc/localtime")
if env::consts::OS == "android" {

@ariasuni ariasuni May 8, 2021

Copy link
Copy Markdown
Collaborator

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

ariasuni commented May 8, 2021

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

2 participants