daysRemaining returns a human-readable days-remaining string for an election.
()
| 199 | |
| 200 | // daysRemaining returns a human-readable days-remaining string for an election. |
| 201 | func (m *ElectionsModule) daysRemaining() string { |
| 202 | if m.state.ActiveElection == nil { |
| 203 | return `0 days` |
| 204 | } |
| 205 | gd := gametime.GetDate(m.state.ActiveElection.StartRound) |
| 206 | endRound := gd.AddPeriod(m.electionDuration()) |
| 207 | now := util.GetRoundCount() |
| 208 | if endRound <= now { |
| 209 | return `0 days` |
| 210 | } |
| 211 | remaining := endRound - now |
| 212 | // Use config rounds-per-day for conversion. |
| 213 | roundsPerDay := gd.RoundsPerDay |
| 214 | if roundsPerDay < 1 { |
| 215 | roundsPerDay = 480 |
| 216 | } |
| 217 | days := (int(remaining) + roundsPerDay - 1) / roundsPerDay |
| 218 | if days == 1 { |
| 219 | return `1 day` |
| 220 | } |
| 221 | return fmt.Sprintf(`%d days`, days) |
| 222 | } |
| 223 | |
| 224 | // endElection tallies votes, saves the winner, and broadcasts the result. |
| 225 | // adminUser may be nil for auto-end. |
no test coverage detected