Skip to content

Remove temporary workaround for SR-3202 #1043

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 2 commits into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Foundation/NSLengthFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ open class LengthFormatter : Formatter {
//Extract the number from the measurement
let numberInUnit = unitMeasurement.value

if isForPersonHeightUse && !numberFormatter.locale.sr3202_fix_isMetricSystemLocale() {
if isForPersonHeightUse && !numberFormatter.locale.usesMetricSystem {
let feet = numberInUnit.rounded(.towardZero)
let feetString = string(fromValue: feet, unit: .foot)

Expand Down Expand Up @@ -123,7 +123,7 @@ open class LengthFormatter : Formatter {
/// - Parameter numberInMeters: the magnitude in terms of meters
/// - Returns: Returns the appropriate unit
private func unit(fromMeters numberInMeters: Double) -> Unit {
if numberFormatter.locale.sr3202_fix_isMetricSystemLocale() {
if numberFormatter.locale.usesMetricSystem {
//Person height is always returned in cm for metric system
if isForPersonHeightUse { return .centimeter }

Expand Down
21 changes: 1 addition & 20 deletions Foundation/NSMassFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ open class MassFormatter : Formatter {
/// - Parameter numberInKilograms: the magnitude in terms of kilograms
/// - Returns: Returns the appropriate unit
private func convertedUnit(fromKilograms numberInKilograms: Double) -> Unit {
if numberFormatter.locale.sr3202_fix_isMetricSystemLocale() {
if numberFormatter.locale.usesMetricSystem {
if numberInKilograms > 1.0 || numberInKilograms <= 0.0 {
return .kilogram
} else {
Expand Down Expand Up @@ -236,22 +236,3 @@ open class MassFormatter : Formatter {
.pound: "pounds",
.stone: "stones"]
}

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
internal func sr3202_fix_isMetricSystemLocale() -> Bool {
switch self.identifier {
case "en_US": return false
case "en_US_POSIX": return false
case "haw_US": return false
case "es_US": return false
case "chr_US": return false
case "my_MM": return false
case "en_LR": return false
case "vai_LR": return false
default: return true
}
}
}
4 changes: 2 additions & 2 deletions TestFoundation/TestNSLengthFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestNSLengthFormatter: XCTestCase {
}

func test_stringFromMetersMetric() {
formatter.numberFormatter.locale = Locale(identifier: "en_UK")
formatter.numberFormatter.locale = Locale(identifier: "en_GB")
XCTAssertEqual(formatter.string(fromMeters: -10000), "-10 km")
XCTAssertEqual(formatter.string(fromMeters: -1), "-0.001 km")
XCTAssertEqual(formatter.string(fromMeters: 0.00001), "0.01 mm")
Expand All @@ -85,7 +85,7 @@ class TestNSLengthFormatter: XCTestCase {
}

func test_stringFromMetersMetricPersonHeight() {
formatter.numberFormatter.locale = Locale(identifier: "en_UK")
formatter.numberFormatter.locale = Locale(identifier: "en_GB")
formatter.isForPersonHeightUse = true
XCTAssertEqual(formatter.string(fromMeters: -1), "-100 cm")
XCTAssertEqual(formatter.string(fromMeters: 0.001), "0.1 cm")
Expand Down