-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix duration formatter rounding
- Loading branch information
Showing
7 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
class DurationFormatter { | ||
static String format(Duration duration) { | ||
final minutesStr = duration.inMinutes.toString(); | ||
final roundedDuration = _roundDuration(duration); | ||
final minutesStr = roundedDuration.inMinutes.toString(); | ||
final secondsStr = | ||
duration.inSeconds.remainder(60).toString().padLeft(2, '0'); | ||
final millisecondsStr = (duration.inMilliseconds.remainder(1000) / 10) | ||
.round() | ||
.toString() | ||
.padLeft(2, '0'); | ||
roundedDuration.inSeconds.remainder(60).toString().padLeft(2, '0'); | ||
final millisecondsStr = | ||
(roundedDuration.inMilliseconds.remainder(1000) / 10) | ||
.round() | ||
.toString() | ||
.padLeft(2, '0'); | ||
var textStr = '$secondsStr.$millisecondsStr'; | ||
if (duration >= const Duration(minutes: 1)) { | ||
textStr = '$minutesStr:$textStr'; | ||
} | ||
return textStr; | ||
} | ||
|
||
static Duration _roundDuration(Duration duration) { | ||
final milliseconds = duration.inMilliseconds; | ||
final roundedMilliseconds = (milliseconds / 10).round() * 10; | ||
return Duration(milliseconds: roundedMilliseconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:kubrs_app/stats/model/average_stat.dart'; | ||
|
||
void main() { | ||
group('AverageStat', () { | ||
test('displays empty average value correctly', () { | ||
final emptyAverage = AverageStat.empty(5); | ||
expect(emptyAverage.displayedValue, '-'); | ||
}); | ||
|
||
test('displays DNF average value correctly', () { | ||
final dnfAverage = AverageStat.dnf(5); | ||
expect(dnfAverage.displayedValue, 'DNF'); | ||
}); | ||
|
||
test('displays average value rounded down correctly', () { | ||
final average = AverageStat(10004, 5); | ||
expect(average.displayedValue, '10.00'); | ||
}); | ||
|
||
test('displays average value rounded up correctly', () { | ||
final average = AverageStat(9995, 5); | ||
expect(average.displayedValue, '10.00'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:kubrs_app/stats/model/best_stat.dart'; | ||
|
||
void main() { | ||
group('BestStat', () { | ||
test('displays empty best value correctly', () { | ||
final emptyBest = BestStat.empty(); | ||
expect(emptyBest.displayedValue, '-'); | ||
}); | ||
|
||
test('displays DNF best value correctly', () { | ||
final dnfBest = BestStat.dnf(); | ||
expect(dnfBest.displayedValue, 'DNF'); | ||
}); | ||
|
||
test('displays best value rounded down correctly', () { | ||
final best = BestStat(10004); | ||
expect(best.displayedValue, '10.00'); | ||
}); | ||
|
||
test('displays best value rounded up correctly', () { | ||
final best = BestStat(9995); | ||
expect(best.displayedValue, '10.00'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:kubrs_app/stats/model/mean_stat.dart'; | ||
|
||
void main() { | ||
group('MeanStat', () { | ||
test('displays empty mean value correctly', () { | ||
final emptyMean = MeanStat.empty(5); | ||
expect(emptyMean.displayedValue, '-'); | ||
}); | ||
|
||
test('displays DNF mean value correctly', () { | ||
final dnfMean = MeanStat.dnf(5); | ||
expect(dnfMean.displayedValue, 'DNF'); | ||
}); | ||
|
||
test('displays mean value rounded down correctly', () { | ||
final mean = MeanStat(10004, 5); | ||
expect(mean.displayedValue, '10.00'); | ||
}); | ||
|
||
test('displays mean value rounded up correctly', () { | ||
final mean = MeanStat(9995, 5); | ||
expect(mean.displayedValue, '10.00'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:kubrs_app/stats/model/worst_stat.dart'; | ||
|
||
void main() { | ||
group('WorstStat', () { | ||
test('displays empty worst value correctly', () { | ||
final emptyWorst = WorstStat.empty(); | ||
expect(emptyWorst.displayedValue, '-'); | ||
}); | ||
|
||
test('displays DNF worst value correctly', () { | ||
final dnfWorst = WorstStat.dnf(); | ||
expect(dnfWorst.displayedValue, 'DNF'); | ||
}); | ||
|
||
test('displays worst value rounded down correctly', () { | ||
final worst = WorstStat(10004); | ||
expect(worst.displayedValue, '10.00'); | ||
}); | ||
|
||
test('displays worst value rounded up correctly', () { | ||
final worst = WorstStat(9995); | ||
expect(worst.displayedValue, '10.00'); | ||
}); | ||
}); | ||
} |