Skip to content

Commit

Permalink
parse pgn clock tags into Centis, 16.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 20, 2024
1 parent 168d650 commit 17149be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -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", "")))),
Expand Down
20 changes: 18 additions & 2 deletions core/src/main/scala/format/pgn/Tag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 17149be

Please sign in to comment.