From 7b4696ed9a9e8d89a850b0dfaf0611841c3039e1 Mon Sep 17 00:00:00 2001 From: "kohsaku.onozawa@bizreach.co.jp" Date: Wed, 4 Mar 2015 19:35:03 +0900 Subject: [PATCH] =?UTF-8?q?3/4=E8=AA=B2=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tanacasino/study/onozawa/Inplicit.scala | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 simple/src/main/scala/com/github/tanacasino/study/onozawa/Inplicit.scala diff --git a/simple/src/main/scala/com/github/tanacasino/study/onozawa/Inplicit.scala b/simple/src/main/scala/com/github/tanacasino/study/onozawa/Inplicit.scala new file mode 100644 index 0000000..bdb0ef2 --- /dev/null +++ b/simple/src/main/scala/com/github/tanacasino/study/onozawa/Inplicit.scala @@ -0,0 +1,28 @@ +package com.github.tanacasino.study.onozawa + +import org.joda.time.DateTime + +/** + * Created by kohsaku.onozawa on 15/03/04. + */ +object Inplicit { + def main(args: Array[String]) { + implicit class RichInt(val value: Int) { + def day: String = { + "d" + value.toString + } + } + implicit class RichDateTime(val value: DateTime) { + def +(t: String): DateTime = { + t match { + case s if s.startsWith("d") => value.plusDays(t.substring(1).toInt) + case s => new DateTime + } + } + } + val now = new DateTime + println(now) + val tomorrow = now + 1.day + println(tomorrow) + } +} \ No newline at end of file