Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arithmetic and others methods to Duration, Interval, and Period #80

Merged
merged 2 commits into from
Dec 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/scala/com/github/nscala_time/time/RichDuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ import scala.concurrent.duration.{ Duration => SDuration, MILLISECONDS }

class RichDuration(val underlying: Duration) extends Super with PimpedType[Duration] {

def days: Long = underlying.getStandardDays

def hours: Long = underlying.getStandardHours

def millis: Long = underlying.getMillis

def minutes: Long = underlying.getStandardMinutes

def seconds: Long = underlying.getStandardSeconds

def unary_- : Duration = underlying.negated

def -(amount: Long): Duration = underlying.minus(amount)

def -(amount: ReadableDuration): Duration = underlying.minus(amount)
Expand All @@ -32,6 +42,10 @@ class RichDuration(val underlying: Duration) extends Super with PimpedType[Durat

def +(amount: ReadableDuration): Duration = underlying.plus(amount)

def /(divisor: Long): Duration = underlying.dividedBy(divisor)

def *(multiplicand: Long): Duration = underlying.multipliedBy(multiplicand)

def toScalaDuration: SDuration = SDuration(underlying.getMillis, MILLISECONDS)

}
3 changes: 3 additions & 0 deletions src/main/scala/com/github/nscala_time/time/RichInt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@ class RichInt(val underlying: Int) extends Super with PimpedType[Int] {
def week = Period.weeks(underlying)
def month = Period.months(underlying)
def year = Period.years(underlying)

def *(period: Period) = period.multipliedBy(underlying)

}
6 changes: 6 additions & 0 deletions src/main/scala/com/github/nscala_time/time/RichLong.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ class RichLong(val underlying: Long) extends Super with PimpedType[Long] {

def toDuration = new Duration(underlying)

def -(duration: Duration): Duration = toDuration.minus(duration)

def +(duration: Duration): Duration = duration.plus(underlying)

def *(duration: Duration): Duration = duration.multipliedBy(underlying)

}
4 changes: 4 additions & 0 deletions src/main/scala/com/github/nscala_time/time/RichPeriod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ class RichPeriod(val underlying: Period) extends Super with PimpedType[Period] {

def years: Int = underlying.getYears

def unary_- : Period = underlying.negated

def -(period: ReadablePeriod): Period = underlying.minus(period)

def +(period: ReadablePeriod): Period = underlying.plus(period)

def *(scalar: Int): Period = underlying.multipliedBy(scalar)

def ago: DateTime = StaticDateTime.now.minus(underlying)

def later: DateTime = StaticDateTime.now.plus(underlying)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ class RichReadableInterval(val underlying: ReadableInterval) extends Super

def end: DateTime = underlying.getEnd

def endMillis: Long = underlying.getEndMillis

def start: DateTime = underlying.getStart

def startMillis: Long = underlying.getStartMillis

def duration: Duration = underlying.toDuration

def millis: Long = underlying.toDuration.getMillis
Expand Down