Skip to content

Detect current time zone, locale, and calendar on Android#564

Open
bbrk24 wants to merge 3 commits into
moreSwift:mainfrom
bbrk24:android-timezone-and-calendar
Open

Detect current time zone, locale, and calendar on Android#564
bbrk24 wants to merge 3 commits into
moreSwift:mainfrom
bbrk24:android-timezone-and-calendar

Conversation

@bbrk24
Copy link
Copy Markdown
Member

@bbrk24 bbrk24 commented May 8, 2026

Draft primarily because I still need to figure out how to refer to Serializable in the implements list for AndroidCalendar. I'll also need to come up with a better name for ifNotEmpty.

@bbrk24 bbrk24 force-pushed the android-timezone-and-calendar branch from 04a2669 to 6f7df5d Compare May 11, 2026 03:19
@bbrk24 bbrk24 force-pushed the android-timezone-and-calendar branch from 6f7df5d to b795ad8 Compare May 11, 2026 12:21
@bbrk24 bbrk24 marked this pull request as ready for review May 12, 2026 02:24
Copy link
Copy Markdown
Collaborator

@stackotter stackotter left a comment

Choose a reason for hiding this comment

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

Looks great; just going to test things locally before merging

// added a whole new method that uses up-to-date information. The new method returns
// TimeZone.UNKNOWN_ZONE_ID on error; the old method returns null on error.
if (Build.VERSION.SDK_INT >= 36) {
val id = TimeZone.getIanaID(tz.getID())
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 get 'unresolved reference getIanaID' when attempting to compile this code locally 🤔 My SDK version appears to be 35. Is there a way for us to only compile that SDK checking code when the compiling SDK is high enough in the first place? Otherwise we always lock compilation to the highest SDK version that we conditionally support features from

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think so -- Kotlin doesn't have #if (nor does Java). One thing we might be able to do, though this would require swift-bundler support, is:

  • Mark a function as expect
  • Have an actual implementation in another file that always calls getCanonicalID
  • Have an actual implementation in another file that checks the version number, like I am here
  • Conditionally compile only one of those two files based on your compile SDK version

(Aside: I'm honestly not 100% sure how expect/actual works in Kotlin. That's just my first idea off the top of my head.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Coming back to this now, the Gradle file that sbun generates for me has compileSdk = 36. Shouldn't that mean you need SDK 36 to build it anyways?

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.

It generates with the latest SDK that you have available (unless the project specifies a compileSDK)

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