Skip to content

Commit

Permalink
Use Decodable instead of Decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Feb 10, 2025
1 parent e35e511 commit af52387
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/aviation.Aviation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ object Aviation:
given RomanCalendar = calendars.gregorian
t"${d.day.toString.show}-${d.month.show}-${d.year.toString.show}"

given decoder: Tactic[DateError] => Decoder[Date] = parse(_)
given decoder: Tactic[DateError] => Date is Decodable in Text = parse(_)

given encodable: RomanCalendar => Date is Encodable in Text = date =>
import hieroglyph.textMetrics.uniform
Expand Down
5 changes: 4 additions & 1 deletion src/core/aviation.Timestamp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@

package aviation

import anticipation.*
import contingency.*
import fulminate.*
import kaleidoscope.*
import prepositional.*
import spectacular.*

import errorDiagnostics.stackTraces

object Timestamp:
import calendars.gregorian

given Tactic[TimestampError] => Decoder[Timestamp] = text =>
given Tactic[TimestampError] => Timestamp is Decodable in Text = text =>
text match
case r"$year(\d{4})-$month(\d{2})-$day(\d{2})T$hour(\d{2}):$minute(\d{2}):$second(\d{2})" =>
import Decoder.int
tend:
case NumberError(_, _) => TimestampError(text)
case DateError(_) => TimestampError(text)
Expand Down
2 changes: 2 additions & 0 deletions src/core/aviation.Tzdb.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ object Tzdb:
abort(TzdbError(TzdbError.Reason.CouldNotParseTime(other.show), lineNo))

def parseDay(lineNo: Int, month: MonthName, str: Text): MonthDate =
import Decoder.int
try throwErrors:
if str.starts(t"last") then MonthDate.Last(month, Weekday.valueOf(str.skip(4).s))
else if str.skip(3).keep(2) == t">="
Expand Down Expand Up @@ -133,6 +134,7 @@ object Tzdb:

def parseRule(lineNo: Int, args: List[Text]): Tzdb.Entry.Rule = args match
case name :: from :: to :: _ :: month :: day :: time :: save :: letters :: _ =>
import Decoder.int
try unsafely:
val end = to match
case t"max" => Int.MaxValue
Expand Down

0 comments on commit af52387

Please sign in to comment.