diff options
| -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 |
