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

Initial implementation of MassFormatter. #883

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

jszumski
Copy link
Contributor

Implemented MassFormatter and created tests.

Tests pass 100% on macOS and in a sample iOS project against Objective-C Foundation.

@jszumski
Copy link
Contributor Author

jszumski commented Feb 16, 2017

Localization was not even attempted following the discussion from #791

I also didn't useisForPersonMassUse internally because I couldn't find a locale that had a different result. I informally expected en_GB to use stone for weight, but it uses kilograms. Unfortunately the documentation doesn't point out a case where this property would have a meaningful impact, and I wasn't able to find any examples online either. Looping over NSLocale.availableLocaleIdentifiers and comparing results between two formatters with one setting isForPersonMassUse = true didn't find any differences.



/// The number of pounds in 1 stone
private static let poundsPerStone = 14.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal was to use Measurement<UnitMass>(value:1, unit:.stones).converted(to:.pounds) here, but that ends up being 0.3471688213196 lb instead of the expected 14 lb.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not that I use stones regularly, but this seems like an issue :-)
Coefficient should be 6.35029? https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/Unit.swift#L1330

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@e78l Those are kilograms not pounds.

Copy link
Contributor

Choose a reason for hiding this comment

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

Was referring to the 1 stone=0.347 lb conversion problem by 'this' - changing 0.157473 on L1330 of Unit.swift to 6.35029 should solve that problem.
Appears macOS 10.12.3's Foundation has the stone conversion issue too.
Hard-coding poundsPerStone = 14.0 looks great (and perhaps is the better way)!

@jszumski
Copy link
Contributor Author

@lifeissweetgood Conflicts are resolved, have you had a chance to review? If you have any pointers on the best way to start the localization work I can get started on that in another branch.

Copy link

@lifeissweetgood lifeissweetgood left a comment

Choose a reason for hiding this comment

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

1 minor comment but overall looks good!

///
/// - Parameter numberInKilograms: the magnitude in terms of kilograms
/// - Returns: Returns the appropriate unit
private func unit(fromKilograms numberInKilograms: Double) -> Unit {

Choose a reason for hiding this comment

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

Could we change the name of this method? It's a little hard to immediately get what it's doing from the signature. Maybe something like convertedUnit(fromKilograms numberInKilograms:)?

@lifeissweetgood
Copy link

In regards to pointers for localization, we're still working on figuring out the best approach for it that would work on all platforms.

@lifeissweetgood
Copy link

As an initial implementation, I think this is a pretty solid start. It leaves room for us to make improvements once we have a better story for supporting localization backed with locale data.

@jszumski jszumski force-pushed the sr-1600-mass-formatter branch from f46cd8e to f306ee0 Compare April 27, 2017 00:25
@jszumski
Copy link
Contributor Author

Updated. Thank you for the feedback!

@alblue
Copy link
Contributor

alblue commented Apr 27, 2017

@swift-ci please test

@jszumski jszumski force-pushed the sr-1600-mass-formatter branch from dae0507 to 2cf8700 Compare May 25, 2017 03:23
@jszumski
Copy link
Contributor Author

Conflicts are resolved, I think this is ready to merge if there isn't any more feedback.

@alblue
Copy link
Contributor

alblue commented May 25, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Jun 1, 2017

Looks good to me - @parkera any objections with merging in as is?

@parkera
Copy link
Contributor

parkera commented Jun 2, 2017

Thanks everyone, let's merge it.

@parkera parkera merged commit 766645d into swiftlang:master Jun 2, 2017
internal extension Locale {
/// TODO: Replace calls to the below function to use Locale.usesMetricSystem
/// Temporary workaround due to unpopulated Locale attributes
/// See https://bugs.swift.org/browse/SR-3202
Copy link
Contributor

Choose a reason for hiding this comment

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

SR-3202 is fixed by #1020 - can this workaround be removed @jszumski ?

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.

6 participants