fork download
  1. import java.util.concurrent._
  2.  
  3. class Duration(amount: Int, unit: TimeUnit) {
  4. override def toString = "Duration(" + amount + ", " + unit + ")"
  5. }
  6.  
  7. object Duration {
  8. class DurationConv(amount: Int) {
  9. def seconds = Duration(amount, TimeUnit.SECONDS)
  10. def second = seconds
  11. def minutes = Duration(amount, TimeUnit.MINUTES)
  12. def minute = minutes
  13. }
  14. implicit def amountToConv(amount: Int) = new DurationConv(amount)
  15. def apply(amount: Int, unit: TimeUnit) = new Duration(amount, unit)
  16. }
  17.  
  18. object Main extends App {
  19. import Duration._
  20.  
  21. val duration = 5 seconds
  22. val another = 5 minutes
  23.  
  24. println(duration)
  25. println(another)
  26.  
  27. println(1 minute)
  28. println(101 second)
  29. }
Success #stdin #stdout 0.3s 247488KB
stdin
Standard input is empty
stdout
Duration(5, SECONDS)
Duration(5, MINUTES)
Duration(1, MINUTES)
Duration(101, SECONDS)