diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-05-09 15:29:51 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-05-09 15:29:51 +0200 |
| commit | a3299ad74fcd58f9c4b435ea57cf2c7350f1dd9f (patch) | |
| tree | 3d1d0ee49c924744cd2104a499a7b6e1386ea8f0 | |
| parent | dca116e7c22f76e4c71e252f3ade65bd3dfac713 (diff) | |
| parent | 187aa352b00dc6001ad58c8e8ef8f3d24c48f9f9 (diff) | |
| download | mullvadvpn-a3299ad74fcd58f9c4b435ea57cf2c7350f1dd9f.tar.xz mullvadvpn-a3299ad74fcd58f9c4b435ea57cf2c7350f1dd9f.zip | |
Merge branch 'fix-out-of-time-formatter-again-ios-158'
| -rw-r--r-- | ios/MullvadVPN/Classes/CustomDateComponentsFormatting.swift | 2 | ||||
| -rw-r--r-- | ios/MullvadVPNTests/CustomDateComponentsFormattingTests.swift | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/ios/MullvadVPN/Classes/CustomDateComponentsFormatting.swift b/ios/MullvadVPN/Classes/CustomDateComponentsFormatting.swift index ad5eed5f36..f0b227fa14 100644 --- a/ios/MullvadVPN/Classes/CustomDateComponentsFormatting.swift +++ b/ios/MullvadVPN/Classes/CustomDateComponentsFormatting.swift @@ -32,6 +32,6 @@ extension CustomDateComponentsFormatting { formatter.maximumUnitCount = 1 formatter.allowedUnits = years >= 2 ? .year : .day - return formatter.string(from: start, to: end) + return formatter.string(from: start, to: max(start, end)) } } diff --git a/ios/MullvadVPNTests/CustomDateComponentsFormattingTests.swift b/ios/MullvadVPNTests/CustomDateComponentsFormattingTests.swift index 3a14264b1d..58cb17d685 100644 --- a/ios/MullvadVPNTests/CustomDateComponentsFormattingTests.swift +++ b/ios/MullvadVPNTests/CustomDateComponentsFormattingTests.swift @@ -25,6 +25,22 @@ class CustomDateComponentsFormattingTests: XCTestCase { XCTAssertEqual(result, "2 years") } + func testTimeIsPassedFormatting() throws { + var dateComponents = DateComponents() + dateComponents.day = -1 + + let (startDate, endDate) = makeDateRange(addingComponents: dateComponents) + + let result = CustomDateComponentsFormatting.localizedString( + from: startDate, + to: endDate, + calendar: calendar, + unitsStyle: .full + ) + + XCTAssertEqual(result, "0 days") + } + func testLessThanTwoYearsFormatting() throws { var dateComponents = DateComponents() dateComponents.day = 365 |
