0

I am writing my first Scala application and I am having a bit of a problem with nscala-time wrapper for joda-time library.

I have a class like this:

package domain

import org.joda.time.{Period => JodaPeriod}

case class GroundTime(val minimum: JodaPeriod, standard: JodaPeriod)

(I renamed Period class because I already have Period class in my domain)

Now, in my specs2 test I wanted to write something like:

"check standard ground time constraint" in {
  import com.github.nscala_time.time.Imports._

  val groundTime = GroundTime(minimum=10 minutes, standard=15 minutes)

but I am getting an error cannot resolve symbol minutes.

I wanted to do something like snippet that is on github page of nscala-time library:

2.hours + 45.minutes + 10.seconds
// returns com.github.nscala_time.time.DurationBuilder
// (can be used as a Duration or as a Period)
Andna
  • 6,539
  • 13
  • 71
  • 120

1 Answers1

2

I digged into specs2 code a little bit and I discovered that by extending Specification you also import something like TimeConversions from specs2 and there was minutes that "shadowed" minutes function from nscala-time (I am saying shadows but it was probably a problem with implicit conversions).

But also I discovered trait called NoTimeConversions from specs2 so now when I write

MySpec extends Specification with NoTimeConversions

I can write 10.minutes and it produces DurationBuilder which I wanted in the first place.

Andna
  • 6,539
  • 13
  • 71
  • 120
  • 1
    You should also import `scala.language.postfixOps` **due to [Scala's feature modularization](http://docs.scala-lang.org/sips/completed/modularizing-language-features.html)** - in future versions, you will have to specifically enable postfix operators like `10 minutes`, otherwise the compiler will report an error (instead of a warning). Related info [here](http://stackoverflow.com/questions/13011204/scalas-postfix-ops). (Readding the contents of the withdrawn answer as a comment.) – mikołak Feb 23 '14 at 11:19