Comments (8)
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.
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.
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.
I think, it's good idea. At least, I don't know what can be better.)
from nscala-time.
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.
@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.
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.
@webgress nice
Can it be added to com.github.nscala_time.time.Imports?
from nscala-time.
Related Issues (20)
- Latest Version publish HOT 1
- Drop Scala 2.9.3 support in newer version HOT 1
- Conversion from Interval to FiniteDuration HOT 4
- max min to DateTime HOT 3
- Add support for multiplication of constant with duration HOT 1
- Check if date is within time range
- RichLong is missing timezone-aware helpers
- Release for Scala 2.12.0 HOT 1
- Possible improvement: DateTime + FiniteDuration syntax
- Get weird result when I want to find period between two dates and subtract some date by it HOT 1
- Release with the latest joda HOT 1
- API changes report for Nscala Time
- Unexpected behaviour with setting DateTime to Midnight HOT 2
- Possible improvement: add the ability to exclude the end of the interval when splitting by period
- Where can I find current release notes?
- Reasons behind now() change? HOT 1
- What do you think about implicit toDateTime over long HOT 1
- New released needed for JDK 1.8u60 HOT 2
- Migrate to java.time HOT 1
- support for min / max operations HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nscala-time.