Created
October 25, 2010 16:44
-
-
Save alinpopa/645277 to your computer and use it in GitHub Desktop.
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
case class Second(value: Long) | |
case class Minute(value: Long){ | |
def seconds = Second(value * 60) | |
} | |
case class Hour(value: Long) { | |
def minutes = Minute(value * 60) | |
} | |
case class Day(value: Long){ | |
def hours = Hour(value * 24) | |
def minutes = hours.minutes | |
def seconds = minutes.seconds | |
} | |
case class Week(value: Long){ | |
def days = Day(value * 7) | |
def hours = days.hours | |
def minutes = hours.minutes | |
def seconds = minutes.seconds | |
} | |
object Wrappers { | |
class LongToPeriod(value: Long) { | |
def days = Day(value) | |
def minutes = Minute(value) | |
def seconds = Second(value) | |
def hours = Hour(value) | |
def weeks = Week(value) | |
} | |
implicit def intToWrapper(value: Long): LongToPeriod = new LongToPeriod(value) | |
} | |
object TestPeriod { | |
import Wrappers._ | |
def main(args: Array[String]): Unit = { | |
println(Day(2).hours) | |
println(6.hours.minutes) | |
println(8.weeks.seconds) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment