Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #841 from corona-warn-app/hotfix/13-of-14-days-fix
Browse files Browse the repository at this point in the history
Fixed number of active days
  • Loading branch information
inf2381 authored Jul 3, 2020
2 parents 505e264 + 60690e8 commit 4521a54
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/xcode/ENA/ENA/Source/Workers/TracingStatusHistory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ extension Array where Element == TracingStatusEntry {
///
/// - parameter since: Date to use as the baseline. Defaults to `Date()`
func countEnabledDays(since date: Date = Date()) -> Int {
Int(getContinuousEnabledInterval(since: date) / (60 * 60 * 24))
// 5.5 days => 6 days
// 0.5 days => 1 day
// 13.99999 days => 14 days
Int(Double(getContinuousEnabledInterval(since: date) / (60 * 60 * 24)).rounded(.toNearestOrAwayFromZero))
}

/// Mark returns the count of hours that tracing has been enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ final class TracingStatusHistoryTests: XCTestCase {
history = history.consumingState(badState, now.addingTimeInterval(.init(hours: -1))) // active for 23 hours

XCTAssertEqual(history.countEnabledHours(since: now), 24 * 4 + 23)
XCTAssertEqual(history.countEnabledDays(since: now), 4)
XCTAssertEqual(history.countEnabledDays(since: now), 5)
}

func testGetEnabledInterval_Accumulator_Good() {
Expand Down Expand Up @@ -280,6 +280,26 @@ final class TracingStatusHistoryTests: XCTestCase {
XCTAssertEqual(history.countEnabledHours(since: now), 24 * 2)
XCTAssertEqual(history.countEnabledDays(since: now), 2)
}

func testNumberOfDays_Rounding() {
let now = Date()

var history: TracingStatusHistory = [
.init(on: true, date: now.addingTimeInterval(.init(hours: -((24 * 5) + 4))))
]

XCTAssertEqual(history.countEnabledDays(since: now), 5)

history = [
.init(on: true, date: now.addingTimeInterval(.init(hours: -((24 * 5) + 13))))
]
XCTAssertEqual(history.countEnabledDays(since: now), 6)

history = [
.init(on: true, date: now.addingTimeInterval(.init(hours: -((24 * 5) + 0))))
]
XCTAssertEqual(history.countEnabledDays(since: now), 5)
}
}

private extension TimeInterval {
Expand Down

0 comments on commit 4521a54

Please sign in to comment.