diff --git a/build.sbt b/build.sbt index e7a548f4..24b41c60 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ inThisBuild( Seq( scalaVersion := "3.6.2", - version := "16.5.1", + version := "16.5.2", organization := "org.lichess", licenses += ("MIT" -> url("https://opensource.org/licenses/MIT")), publishTo := Option(Resolver.file("file", new File(sys.props.getOrElse("publishTo", "")))), diff --git a/core/src/main/scala/format/pgn/Tag.scala b/core/src/main/scala/format/pgn/Tag.scala index d9c8d4dd..a7fbc370 100644 --- a/core/src/main/scala/format/pgn/Tag.scala +++ b/core/src/main/scala/format/pgn/Tag.scala @@ -94,8 +94,24 @@ case class Tags(value: List[Tag]) extends AnyVal: ByColor(apply(_.WhiteTitle), apply(_.BlackTitle)).map(_.flatMap(PlayerTitle.get)) def fideIds: ByColor[Option[FideId]] = ByColor(apply(_.WhiteFideId), apply(_.BlackFideId)).map: id => FideId.from(id.flatMap(_.toIntOption)) - def teams = ByColor(apply(_.WhiteTeam), apply(_.BlackTeam)) - def clocks = ByColor(apply(_.WhiteClock), apply(_.BlackClock)) + def teams = ByColor(apply(_.WhiteTeam), apply(_.BlackTeam)) + + def clocks: ByColor[Option[Centis]] = ByColor(apply(_.WhiteClock), apply(_.BlackClock)).map: + _.flatMap: s => + val seconds = s.split(':').toList match + case List(h, m, s) => + for + hours <- h.toIntOption + minutes <- m.toIntOption + seconds <- s.toIntOption + yield hours * 3600 + minutes * 60 + seconds + case List(m, s) => + for + minutes <- m.toIntOption + seconds <- s.toIntOption + yield minutes * 60 + seconds + case _ => None + seconds.map(Centis.ofSeconds) override def toString = sorted.value.mkString("\n")