Skip to content

Commit

Permalink
Contributed patch from Barry Kaplan, for LocalTime and LocalDate
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Ortiz committed May 7, 2009
1 parent d7bfaa2 commit dad12e4
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/scala/org/scala_tools/time/Implicits.scala
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright 2009 Jorge Ortiz
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,6 +46,8 @@ trait JodaImplicits {
new RichAbstractReadableInstantFieldProperty(pty)
implicit def RichChronology(ch: Chronology): RichChronology = new RichChronology(ch)
implicit def RichDateMidnight(dm: DateMidnight): RichDateMidnight = new RichDateMidnight(dm)
implicit def RichLocalDate(ld: LocalDate): RichLocalDate = new RichLocalDate(ld)
implicit def RichLocalTime(lt: LocalTime): RichLocalTime = new RichLocalTime(lt)
implicit def RichDateTime(dt: DateTime): RichDateTime = new RichDateTime(dt)
implicit def RichDateTimeFormatter(fmt: DateTimeFormatter): RichDateTimeFormatter = new RichDateTimeFormatter(fmt)
implicit def RichDateTimeProperty(pty: DateTime.Property): RichDateTimeProperty = new RichDateTimeProperty(pty)
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/org/scala_tools/time/Imports.scala
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright 2009 Jorge Ortiz
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +25,8 @@ trait Imports extends TypeImports with StaticForwarderImports with Implicits

trait TypeImports {
type DateTime = org.joda.time.DateTime
type LocalDate = org.joda.time.LocalDate
type LocalTime = org.joda.time.LocalTime
type Interval = org.joda.time.Interval
type Duration = org.joda.time.Duration
type Period = org.joda.time.Period
Expand All @@ -34,6 +37,8 @@ trait TypeImports {

trait StaticForwarderImports {
val DateTime = org.scala_tools.time.StaticDateTime
val LocalDate = org.scala_tools.time.StaticLocalDate
val LocalTime = org.scala_tools.time.StaticLocalTime
val Interval = org.scala_tools.time.StaticInterval
val Duration = org.scala_tools.time.StaticDuration
val Period = org.scala_tools.time.StaticPeriod
Expand Down
44 changes: 44 additions & 0 deletions src/main/scala/org/scala_tools/time/RichLocalDate.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.scala_tools.time

import org.joda.time._

class RichLocalDate(underlying: LocalDate) {
def -(period: ReadablePeriod): LocalDate =
underlying.minus(period)
def -(builder: DurationBuilder): LocalDate =
underlying.minus(builder.underlying)
def +(period: ReadablePeriod): LocalDate =
underlying.plus(period)
def +(builder: DurationBuilder): LocalDate =
underlying.plus(builder.underlying)

def day: LocalDate.Property = underlying.dayOfMonth
def week: LocalDate.Property = underlying.weekOfWeekyear
def month: LocalDate.Property = underlying.monthOfYear
def year: LocalDate.Property = underlying.year
def century: LocalDate.Property = underlying.centuryOfEra
def era: LocalDate.Property = underlying.era

def withDay(day: Int) = underlying.withDayOfMonth(day)
def withWeek(week: Int) = underlying.withWeekOfWeekyear(week)
def withMonth(month: Int) = underlying.withMonthOfYear(month)
def withYear(year: Int) = underlying.withYear(year)
def withCentury(century: Int) = underlying.withCenturyOfEra(century)
def withEra(era: Int) = underlying.withEra(era)
}
38 changes: 38 additions & 0 deletions src/main/scala/org/scala_tools/time/RichLocalTime.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.scala_tools.time

import org.joda.time._

class RichLocalTime(underlying: LocalTime) {
def -(period: ReadablePeriod): LocalTime =
underlying.minus(period)
def -(builder: DurationBuilder): LocalTime =
underlying.minus(builder.underlying)
def +(period: ReadablePeriod): LocalTime =
underlying.plus(period)
def +(builder: DurationBuilder): LocalTime =
underlying.plus(builder.underlying)

def second: LocalTime.Property = underlying.secondOfMinute
def minute: LocalTime.Property = underlying.minuteOfHour
def hour: LocalTime.Property = underlying.hourOfDay

def withSecond(second: Int) = underlying.withSecondOfMinute(second)
def withMinute(minute: Int) = underlying.withMinuteOfHour(minute)
def withHour(hour: Int) = underlying.withHourOfDay(hour)
}
35 changes: 35 additions & 0 deletions src/main/scala/org/scala_tools/time/StaticLocalDate.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.scala_tools.time

import org.joda.time._
import org.scala_tools.time.Implicits._

object StaticLocalDate extends StaticLocalDate

trait StaticLocalDate {
def now = new LocalDate

def nextSecond = now + 1.second
def nextMinute = now + 1.minute
def nextHour = now + 1.hour
def nextDay = now + 1.day
def tomorrow = now + 1.day
def nextWeek = now + 1.week
def nextMonth = now + 1.month
def nextYear = now + 1.year
}
35 changes: 35 additions & 0 deletions src/main/scala/org/scala_tools/time/StaticLocalTime.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright 2009 Barry Kaplan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.scala_tools.time

import org.joda.time._
import org.scala_tools.time.Implicits._

object StaticLocalTime extends StaticLocalTime

trait StaticLocalTime {
def now = new LocalTime

def lastSecond = now - 1.second
def lastMinute = now - 1.minute
def lastHour = now - 1.hour
def lastDay = now - 1.day
def yesterday = now - 1.day
def lastWeek = now - 1.week
def lastMonth = now - 1.month
def lastYear = now - 1.year
}

0 comments on commit dad12e4

Please sign in to comment.