Created
February 25, 2014 22:46
-
-
Save bdkosher/9219616 to your computer and use it in GitHub Desktop.
Extends groovy.time.TimeCategory with the ability to cast Strings into Dates.
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
class EasyDateCategory extends groovy.time.TimeCategory { | |
static asType(String str, Class clazz) { | |
if (clazz == Date) { | |
new java.text.SimpleDateFormat('yyyy-MM-dd').parse(str) | |
} else { | |
str.asType(clazz) | |
} | |
} | |
} | |
use(EasyDateCategory) { | |
println(('2014-02-25' as Date) + 3.months) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment