Created
January 24, 2013 10:36
-
-
Save rirakkumya/4619788 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
def toDate[A:DateMagnet](x:A) = implicitly[DateMagnet[A]].convert(x) | |
trait DateMagnet[A]{ | |
type Result | |
def convert(x:A):Result | |
} | |
object DateMagnet { | |
implicit def fromInt = new DateMagnet[(Int, Int, Int)] { | |
type Result = java.util.Calendar | |
def convert(tuple:(Int, Int, Int)):Result = { | |
val (year, month, date) = tuple | |
val c = java.util.Calendar.getInstance | |
c.set(year, month - 1, date, 0, 0, 0) | |
c | |
} | |
} | |
implicit def fromString = new DateMagnet[String] { | |
type Result = java.util.Date | |
def convert(s:String):Result = | |
(new java.text.SimpleDateFormat("yyyy/MM/dd")).parse(s) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment