Skip to content

Add Duration FormatStyle(s) to swift-foundation #278

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

Merged
merged 6 commits into from
Oct 5, 2023

Conversation

itingliu
Copy link
Contributor

@itingliu itingliu commented Oct 4, 2023

I recommend reviewing this PR commit per commit. I tried my best separating file moves into their own commits, and addressing build issues in follow-up commits.

  • Add Duration formatting and utility files to FoundationInternationalization.
  • Add partial implementation for Measurement.FormatStyle
  • Addressing compatibility issues post file move
  • Move test files
  • Move test files
  • Compatibility fix: typealias Duration.TimeFormatStyle and Duration.UnitsFormatStyle

coauthored by @theMomax

…zation.

This commit moves existing files as-is to FoundationInternationalization. We'll address compatibility fixes in the following commits.
`Duration.FormatStyle` uses `Measurement.FormatStyle.UnitWidth` internally. This PR adds a partial implementation for `Measurement.FormatStyle` to maintain source compatibility for `Duration.FormatStyle`.

`Measurement.FormatStyle` is built on top of `struct Measurement<Dimension>`, which isn't available in the package yet. To unblock ourselves, add stubs for relevant types if they're not available for now.
- Add functions to generate ICU skeleton to `ICUMeasurementNumberFormatter`: The function was originally declared as a `static func` in `Measurement.FormatStyle`. Re-work this into `ICUMeasurementNumberFormatter` since this function is only relevant when used with this class.

- Use Glibc for `pow` when Darwin isn't available
…itsFormatStyle

XCTest explicitly exports Foundation, so referring to `Duration.UnitsFormatStyle` and `Duration.TimeFormatStyle` raises amibiguity errors on Darwin since the compiler doesn't know if they refer to the ones defined in the package or the one in Foundation.

We've been working around this issue by referring common types with prefix of package name (see TestSupport.swift). However we cannot do that for `Duration.UnitsFormatStyle` since this type is declared as `extension Duration`, and there's no way to disambiguate or typealias extensions on stdlib types. Workaround this by declaring `Duration._UnitsFormatStyle` as a typealias of `Duration.FormatStyle`, and use the former in the test. This way, when Darwin is imported, `_UnitsFormatStyle` would refer to the `Duration.UnitsFormatStyle` declared in Foundation, and the one in the package otherwise.
@itingliu
Copy link
Contributor Author

itingliu commented Oct 4, 2023

@swift-ci please test

@itingliu itingliu requested a review from iCharlesHu October 5, 2023 16:31
@itingliu itingliu merged commit 25014fc into swiftlang:main Oct 5, 2023
@itingliu itingliu deleted the duration-formatting-new branch October 5, 2023 22:01
@MaxDesiatov
Copy link
Contributor

When adding swift-foundation package as a dependency, this code fails to build for me with '_range' is inaccessible due to 'internal' protection level error on line 255 in Duration+UnitsFormatStyle.swift:

Screenshot 2023-10-05 at 23 12 24

itingliu added a commit to itingliu/swift-foundation that referenced this pull request Oct 5, 2023
…ionEssentials `package` so we can use it from FoundationI18n
itingliu added a commit that referenced this pull request Oct 6, 2023
…ials `package` so we can use it from FoundationI18n (#286)

* Follow up for #278 : make the required function from FoundationEssentials `package` so we can use it from FoundationI18n

* Workaround TAPI error by removing the default arguments
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.

3 participants