-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[android] Support for time zones in Android. #2168
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
[android] Support for time zones in Android. #2168
Conversation
e416b11
to
76bd79d
Compare
@swift-ci test |
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.
Thanks for the feedback. I will split the PR in two, and fix all the memory management problems.
76bd79d
to
cf58b49
Compare
This might not apply cleanly without #2172. But one can look only at the second commit, if you want the Android specific changes only. |
cf58b49
to
473cd46
Compare
After fighting a little with the removal of |
@@ -702,7 +829,9 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) { | |||
} else { | |||
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf, strlen(linkbuf), kCFStringEncodingUTF8, false); | |||
} | |||
} else { | |||
} else |
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 think it might be nicer to just end the previous block with the one duplicated line for the return and then avoid the else
and braces for the remainder.
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 think it is not possible here, since there’s a block in the middle that has to be run for both branches. The return cannot be moved here.
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.
Hmm, did I miss that? What is the block which needs to be executed?
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.
The if (name)
block that starts in L890 (new version). The previous branches (the if
and the else
branch, only the else
is valid for Android), are trying to find the name
, while that last bit is find the information about the time zone with that name.
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.
How about folding !TARGET_OS_ANDROID
into the if
condition on L868?
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'm not sure exactly why you mean (please provide the code of what you mean), but __tzZoneInfo
is used in L866, and that variable doesn't exist in Android, so it has to be compiled out.
473cd46
to
102da92
Compare
@swift-ci please test |
The time zone database in Android sits in a non-standard place, and it can be overridedn by a second location. Besides not sitting in a standard place, it differs from other Unixes in that the database is bundled into one binary file, and there are no folders with small files for each time zone. Luckily the database is generated from Olson, so most of the CFTimeZone code already handles the details. The code implements a generic enumeration of the time zones contained in the database (checking for both the override and the standard location). The enumeration code is used for both enumerating the known time zones, as well as creating time zones by name. At many points there was code blocking the usage of time zones in Android that has been removed. This allows the tests in TestDateFormatter, TestCalendar and TestTimeZone to pass on Android.
102da92
to
6454141
Compare
Fixed some merge errors for the Android code. @swift-ci please test |
Heh, I had to make almost the same changes to the previous commit to get it to compile, though I didn't spot the fclose fix and it would segfault. Now, several dozen more timezone tests pass on Android AArch64 with this latest commit, nice work. |
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.
Minor style things which I think would be nice, but I think this is good to go otherwise.
* - context1: The argument passed into __CFAndroidTimeZoneListEnumerate. | ||
* - context2: The argument passed into __CFAndroidTimeZoneListEnumerate. | ||
*/ | ||
typedef Boolean (*__CFAndroidTimeZoneListEnumerateCallback)(const char name[ANDROID_TZ_ENTRY_NAME_LENGTH], int32_t offset, int32_t length, FILE *fp, void *context1, void *context2); |
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 would give them proper names rather than context1
and context2
. (e.g. name
, data
)
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.
They are name
and data
in the case you are calling __CFTimeZoneDataCreateCallback
, but context1
is actually a CFMutableArrayRef
in the case of calling __CFCopyAndroidTimeZoneListCallback
. That's why I used just one context
before.
@@ -702,7 +829,9 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) { | |||
} else { | |||
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf, strlen(linkbuf), kCFStringEncodingUTF8, false); | |||
} | |||
} else { | |||
} else |
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.
How about folding !TARGET_OS_ANDROID
into the if
condition on L868?
Revert an Android-specific block that was already removed in swiftlang#2168 and don't check for baseURL in _CFTimeZoneInit(), since Android doesn't use it anyway.
The time zone database in Android sits in a non-standard place, and it
can be overriden by a second location. Besides not sitting in a standard
place, it differs from other Unixes in that the database is bundled into
one binary file, and there are no folders with small files for each time
zone. Luckily the database is generated from Olson, so most of the
CFTimeZone code already handles the details.
The code implements a generic enumeration of the time zones contained in
the database (checking for both the override and the standard location).
The enumeration code is used for both enumerating the known time zones,
as well as creating time zones by name.
At many points there was code blocking the usage of time zones in
Android that has been removed.
This allows the tests in TestDateFormatter, TestCalendar and
TestTimeZone to pass on Android.