Skip to content

Commit

Permalink
Changes for latest Scala
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed May 22, 2024
1 parent 00ddc43 commit ebd92d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/core/leapseconds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ object LeapSeconds:
private var december: Long = bin"11111111 00000001 01100001 00100000 01001000 00001000 00000000 00000000"

def addLeapSecond(year: Int, midYear: Boolean): Unit =
if midYear then june |= (Long.MinValue >> (year - 1972)) else december |= (Long.MinValue >> (year - 1972))
if midYear then june |= (Long.MinValue >> (year - 1972))
else december |= (Long.MinValue >> (year - 1972))

def before(year: Int, plusSixMonths: Boolean): Int =
before((year - 1972)*2 + (if plusSixMonths then 1 else 0))
Expand Down
20 changes: 12 additions & 8 deletions src/core/time.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ object Timing:

object TaiInstant:
erased given underlying: Underlying[TaiInstant, Long] = ###
given generic: GenericInstant[Timing.TaiInstant] with
given generic: GenericInstant with
type Self = Timing.TaiInstant
def instant(millisecondsSinceEpoch: Long): Timing.TaiInstant = millisecondsSinceEpoch
def millisecondsSinceEpoch(instant: Timing.TaiInstant): Long = instant

Expand All @@ -226,7 +227,8 @@ object Timing:
erased given underlying: Underlying[Instant, Long] = ###
def of(millis: Long): Instant = millis

given generic: GenericInstant[Timing.Instant] with
given generic: GenericInstant with
type Self = Timing.Instant
def instant(millisecondsSinceEpoch: Long): Timing.Instant = millisecondsSinceEpoch
def millisecondsSinceEpoch(instant: Timing.Instant): Long = instant

Expand All @@ -252,7 +254,8 @@ object Timing:

def of(millis: Long): Duration = Quantity(millis/1000.0)

given generic: GenericDuration[Timing.Duration] with SpecificDuration[Timing.Duration] with
given generic: GenericDuration with SpecificDuration with
type Self = Timing.Duration
def duration(milliseconds: Long): Timing.Duration = Quantity(milliseconds.toDouble)
def milliseconds(duration: Timing.Duration): Long = (duration.value*1000).toLong

Expand Down Expand Up @@ -331,7 +334,8 @@ trait FixedDuration:
this: Period =>

object Period:
given genericDuration: GenericDuration[Period & FixedDuration] with SpecificDuration[Period & FixedDuration] with
given genericDuration: GenericDuration with SpecificDuration with
type Self = Period & FixedDuration
def duration(milliseconds: Long): Period & FixedDuration =
val hours: Int = (milliseconds/3600000L).toInt
val minutes: Int = ((milliseconds%3600000L)/60000L).toInt
Expand Down Expand Up @@ -542,14 +546,13 @@ object Aviation:
if hour < 0 then fail(msg"a time cannot be negative", lit.pos)
if hour > 12 then fail(msg"a time cannot have an hour value above 12", lit.pos)

val h: Base24 = (hour + (if pm then 12 else 0)).asInstanceOf[Base24]
val hour24: Int = hour + (if pm then 12 else 0)
val length = lit.pos.endColumn - lit.pos.startColumn

if (hour < 10 && length != 4) || (hour >= 10 && length != 5)
then fail(msg"the time should have exactly two minutes digits", lit.pos)

val m: Base60 = minutes.asInstanceOf[Base60]
'{Time(${Expr(h)}, ${Expr(m)}, 0)}
'{Time(${Expr(hour24)}.asInstanceOf[Base24], ${Expr(minutes)}.asInstanceOf[Base60], 0)}

case _ =>
fail(msg"expected a literal double value")
Expand All @@ -561,7 +564,8 @@ case class TimezoneError(name: Text)
extends Error(msg"the name $name does not refer to a known timezone")

object LocalTime:
given generic(using RomanCalendar): GenericInstant[LocalTime] = _.instant.millisecondsSinceEpoch
given generic(using RomanCalendar): (GenericInstant { type Self = LocalTime }) =
_.instant.millisecondsSinceEpoch

case class LocalTime(date: Date, time: Time, timezone: Timezone):
def instant(using RomanCalendar): Instant =
Expand Down
14 changes: 7 additions & 7 deletions src/core/timeapi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import aviation.*

//import language.experimental.captureChecking

package timeInterfaces:
given aviationApi: (GenericInstant[Timing.Instant] & GenericDuration[Timing.Duration] &
SpecificInstant[Timing.Instant] & SpecificDuration[Timing.Duration]) =
new GenericInstant[Timing.Instant] with GenericDuration[Timing.Duration]
with SpecificInstant[Timing.Instant] with SpecificDuration[Timing.Duration]:
export Timing.Instant.generic.{instant, millisecondsSinceEpoch}
export Timing.Duration.generic.{duration, milliseconds}
// package timeInterfaces:
// given aviationApi: (GenericInstant[Timing.Instant] & GenericDuration[Timing.Duration] &
// SpecificInstant[Timing.Instant] & SpecificDuration[Timing.Duration]) =
// new GenericInstant[Timing.Instant] with GenericDuration[Timing.Duration]
// with SpecificInstant[Timing.Instant] with SpecificDuration[Timing.Duration]:
// export Timing.Instant.generic.{instant, millisecondsSinceEpoch}
// export Timing.Duration.generic.{duration, milliseconds}

2 changes: 1 addition & 1 deletion src/core/timezone.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import scala.io.*
//import language.experimental.captureChecking

object TzdbError:
given Communicable[Reason] =
given (Communicable { type Self = Reason }) =
case Reason.CouldNotParseTime(time) => msg"could not parse time $time"
case Reason.UnexpectedRule => msg"unexpected rule"
case Reason.UnexpectedLink => msg"unexpected link"
Expand Down

0 comments on commit ebd92d8

Please sign in to comment.