Skip to content

Make DurationBuilder public #52

@memelet

Description

@memelet

DurationBuilder is a leaky abstraction. Many methods will return a DurationBuilder, yet it is private. This makes adding any sugar on Duration and Period difficult (impossible?).

For example:

  private val adapt = ((_:Any) match {
    case interval: Interval => interval.toDuration
    case period: Period => period.toStandardDuration
    case other => other
  })
  def haveTheSameDurationAs(expected: Duration) = be_==(expected) ^^ adapt
  def haveTheSameDurationAs(expected: Period) = be_==(expected.toStandardDuration) ^^ adapt

  abutting.period must haveTheSameDurationAs(15.hours + 30.minutes) // compile error

Because 15.hours + 30.minutes is a DuratonBuilder. What I need to define is:

  def haveTheSameDurationAs(expected: DurationBuilder) = be_==(expected: Duration) ^^ adapt

But I cannot because DurationBuilder is private.

Another example of leaking:

  val x = 10.hours + 5.hours
  // What type is x? If we let IDEA tell us, we get
  val x: DurationBuilder = 10.hours + 5.hours
  // Which of course will not compile

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions