-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contributed patch from Barry Kaplan, for LocalTime and LocalDate
- Loading branch information
Jorge Ortiz
committed
May 7, 2009
1 parent
d7bfaa2
commit dad12e4
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |