Comments (13)
Hmm, here's another problem with DurationBuilder (but maybe not related to the protection?)
val dur = 10.minutes
val exp = new Interval((iHour.start + 20.minutes), dur.toDuration)
Yields Error:(34, 9) Result type in structural refinement may not refer to a user-defined value class
val dur = 10.minutes
^
This is because of "structural types cannot use value classes in method parameter or return types" from http://docs.scala-lang.org/overviews/core/value-classes.html
I'm guessing this is because DurationBuilder now extends AnyVal?
from nscala-time.
Another example from our code
implicit class DurationBuilderW(db1: DurationBuilder) {
def to(db2: DurationBuilder): (Duration, Duration) = (db1, db2)
def to(db2: Duration): (Duration, Duration) = (db1, db2)
def or_greater: (Duration, Duration) = (db1, 1000.hours.toStandardDuration)
}
...
classify((0.seconds to 5.minutes, as (Shutdown)),
(5.minutes to 10.minutes, as (Shutdown)),
(10.seconds or_greater, as (Shutdown)))
(I am trying to upgrade from scala-time to nscala-time, but we were using a local fork with DurationBuilder public. I'm trying to not need a local fork...)
from nscala-time.
I think that DurationBuilder
is Intermediate representation, so It should not be public.
We use Period
or Duration
usually.
However, It is inexpediency that 15.hours + 30.minutes
can not assign to Duration
or Period
parameter.
Should we make DurationBuilder#toPeriod
implicit?
from nscala-time.
Oh, These has been defined.
https://github.com/nscala-time/nscala-time/blob/releases/0.8.0/src/main/scala/com/github/nscala_time/time/Implicits.scala#L36-L39
haveTheSameDurationAs
has two parameter type.
so compiler can not decide using witch of them.
def haveTheSameDurationAs(expected: Period)
seems a bit danger.
Whould you use only haveTheSameDurationAs(expected: Duration)
?
from nscala-time.
As for the haveTheSameDurationAs I just got rid of the overloading (a good idea in a any case). That forces the compiler to convert the DurationBuilder.
But we have tried nearly every permutation of implicit conversions in our fork of scala-time, and all gave problem of some kind or another.
We have other extension classes like:
implicit class IntervalW(interval: Interval) {
def |<< (duration: Duration) = interval.withStart(interval.start.minus(duration))
def |>> (duration: Duration) = interval.withStart(interval.start.plus(duration))
..
}
implicit class DurationBuilderW(db: DurationBuilder) extends DurationOpsW {
def |<< (interval: Interval) = interval.withStart(interval.start.minus(duration))
def |>> (interval: Interval) = interval.withStart(interval.start.plus(duration))
..
}
Which allows us to do things like:
(1.hour |<< interval_2 >>| 1.hour) must_== (interval_1 ++ interval_3)
(1.hour |>> interval_24 <<| 1.day) must_== ...
This is not possible (as far as I can tell) without being able to define DurationBuidlerW.
I understand if you don't want to make DurationBuilder public. If so we will just maintain our fork and work on pulling out just the bits of scala-time we use.
from nscala-time.
Here's something else that fails
val classifyCurrentMaxDuration = 10.seconds
val x = classifyCurrentMaxDuration - 1.second
Error:(122, 45) ambiguous reference to overloaded definition,
both method - in class DurationBuilder of type (amount: org.joda.time.ReadableDuration)org.joda.time.Duration
and method - in class DurationBuilder of type (period: org.joda.time.ReadablePeriod)org.joda.time.Period
match argument types (com.github.nscala_time.time.DurationBuilder)
val x = (classifyCurrentMaxDuration - 1.second)
^
I have to say that DurationBuilder has been a pain for years...
from nscala-time.
Wow, It's a so embarrassing that 10.seconds - 1.second
can not compile.
It seems absent
def - (DurationBuilder)
@kmizu @xuwei-k
Do you konw the reason why def - (DurationBuilder)
is absent in DurationBuilder
?
I agree that DurationBuilder
pains us.
Still, I think that make DurationBuilder
public is bad idea.
Instead, we might remove DurationBuilder
and provide another way that build Duration
.
What do you think? > all
from nscala-time.
It's a so embarrassing that 10.seconds - 1.second can not compile.
I'm going to send pull request soon.
from nscala-time.
from nscala-time.
If the methods on duration builder were on both Duration and Period that would be big improvement, for us at least. But then our system rarely does things like 10.days + 2.hours.
from nscala-time.
I have merged it.
from nscala-time.
@memelet I'll try to implement your request as my PR (as long as I don't make DurationBuilder
public). Wait a while.
from nscala-time.
Fixed via #64
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.