Giter Site home page Giter Site logo

Comments (8)

kmizu avatar kmizu commented on July 21, 2024

Since it is thought that the problem cannot be avoided without changing API and conflicts of implicits are common in Scala, I recommend that either one is used without implicits. For example, the following code is right:

import com.github.nscala_time.time.RichInt
new RichInt(5).seconds

If you have a good idea to resolve this problem, I'd like to know about it.

from nscala-time.

newffy avatar newffy commented on July 21, 2024

Yes, I'm aware of use case without implicits, but it's not so user-friendly as the way with imlicits.
I suppose, there is only one possible way - is to define alternative API and alternative imports for those who wants to use both libs. I think because of merging akka libs to scala distrib such conflicts will be often...

from nscala-time.

kmizu avatar kmizu commented on July 21, 2024

OK. I understood your opinion. So, What kind of API do you want? A way to avoid conflicts I can think is as the followings:

import com.github.nscala_time.time.converters.Imports._  // Alternative imports
5.toTimeUnit.seconds // Explicit invocation of toTimeUnit to avoid conflicting

I borrowed the idea from scala.collection.JavaConverters instead of scala.collection.JavaConversions.
Is the API good enough for you?

from nscala-time.

newffy avatar newffy commented on July 21, 2024

I think, it's good idea. At least, I don't know what can be better.)

from nscala-time.

tototoshi avatar tototoshi commented on July 21, 2024

I think it's not so good idea.

I will use joda-time directly in this case.

Like this

scala> Period.seconds(3)
res0: org.joda.time.Period = PT3S

Just because it is shorter than 3.toTimeUnit.seconds.

from nscala-time.

kmizu avatar kmizu commented on July 21, 2024

@tototoshi Certainly.

@newffy If you don't have any other idea for this problem, I'd like to close this issue. Of course, I'll accept your pull request to solve this problem elegantly when you send it.

from nscala-time.

webgress avatar webgress commented on July 21, 2024

Here is what I did to solve this type of problem locally:
implicit def concurrentFiniteDurationFrom(d:com.github.nscala_time.time.DurationBuilder):scala.concurrent.duration.FiniteDuration = scala.concurrent.duration.Duration( d.millis, scala.concurrent.duration.MILLISECONDS)

My specific situation was that I needed to produce a scala.concurrent.FiniteDuration for akka unit test
as in "within(10 millis) { ..." and at the same time wanted to use this JodaTime wrapper.
That was the only reason for me to import scala.concurrent.....

I think adding my implicit function to DurationBuilder object would solve most use cases.

from nscala-time.

rafalsobota avatar rafalsobota commented on July 21, 2024

@webgress nice
Can it be added to com.github.nscala_time.time.Imports?

from nscala-time.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.