Review maxTime: by convention to 0 if none

This commit is contained in:
Claude Brisson
2024-03-10 20:25:46 +01:00
parent 8d577f32ab
commit e5c95893ba
3 changed files with 5 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ data class TimeSystem(
val type: TimeSystemType,
val mainTime: Int,
val increment: Int,
val maxTime: Int = -1,
val maxTime: Int = 0,
val byoyomi: Int,
val periods: Int,
val stones: Int
@@ -37,7 +37,7 @@ fun StandardByoyomi(mainTime: Int, byoyomi: Int, periods: Int) =
stones = 1
)
fun FischerTime(mainTime: Int, increment: Int, maxTime: Int = -1) =
fun FischerTime(mainTime: Int, increment: Int, maxTime: Int = 0) =
TimeSystem(
type = FISCHER,
mainTime = mainTime,
@@ -75,7 +75,7 @@ fun TimeSystem.Companion.fromJson(json: Json.Object) =
"FISCHER" -> FischerTime(
mainTime = json.getInt("mainTime") ?: badRequest("missing timeSystem mainTime"),
increment = json.getInt("increment") ?: badRequest("missing timeSystem increment"),
maxTime = json.getInt("maxTime")?.let { if (it == Int.MAX_VALUE) -1 else it } ?: -1
maxTime = json.getInt("maxTime")?.let { if (it == Int.MAX_VALUE || it == -1) 0 else it } ?: 0
)
"SUDDEN_DEATH" -> SuddenDeath(
mainTime = json.getInt("mainTime") ?: badRequest("missing timeSystem mainTime"),
@@ -87,7 +87,7 @@ fun TimeSystem.toJson() = when (type) {
TimeSystem.TimeSystemType.CANADIAN -> Json.Object("type" to type.name, "mainTime" to mainTime, "byoyomi" to byoyomi, "stones" to stones)
TimeSystem.TimeSystemType.JAPANESE -> Json.Object("type" to type.name, "mainTime" to mainTime, "byoyomi" to byoyomi, "periods" to periods)
TimeSystem.TimeSystemType.FISCHER ->
if (maxTime == Int.MAX_VALUE || maxTime == -1) Json.Object("type" to type.name, "mainTime" to mainTime, "increment" to increment)
if (maxTime == Int.MAX_VALUE || maxTime == -1 || maxTime == 0) Json.Object("type" to type.name, "mainTime" to mainTime, "increment" to increment)
else Json.Object("type" to type.name, "mainTime" to mainTime, "increment" to increment, "maxTime" to maxTime)
TimeSystem.TimeSystemType.SUDDEN_DEATH -> Json.Object("type" to type.name, "mainTime" to mainTime)
}

View File

@@ -189,7 +189,7 @@
<div id="maxTime" class="three wide field #if($tour && $tour.timeSystem.type != 'FISCHER')hidden#end">
<label>Max time</label>
<span class="info"></span>
<input name="maxTime" type="text" class="duration" value="#if($tour && "$!tour.timeSystem.maxTime" != '' && "$!tour.timeSystem.maxTime" != '-1')#toHMS($tour.timeSystem.maxTime)#end"/>
<input name="maxTime" type="text" class="duration" value="#if($tour && "$!tour.timeSystem.maxTime" != '' && "$!tour.timeSystem.maxTime" != '-1' && "$!tour.timeSystem.maxTime" != '0')#toHMS($tour.timeSystem.maxTime)#end"/>
</div>
<div id="byoyomi" class="three wide field #if(!$tour || $tour.timeSystem.type != 'CANADIAN' && $tour.timeSystem.type != 'STANDARD')hidden#end">
<label>Byo-yomi time</label>

View File

@@ -73,10 +73,8 @@
if (value && /\d+:\d+:\d+/.test(value)) {
let parts = value.split(':');
let seconds = parts[0] * 3600 + parts[1] * 60 + parts[2] * 1;
console.log(`${value} => ${seconds}`);
return seconds;
}
console.log(`invalid hh:mm:ss value: ${value}`);
return 0;
}
function chooseStep(step) {