Created
June 17, 2011 09:26
-
-
Save xnrghzjh/1031123 to your computer and use it in GitHub Desktop.
決算開始月から1年間のデータを作成
This file contains hidden or 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 = { Date.parse('yyyy/MM/dd', it) } | |
Date.metaClass.createMonthRange = { | |
cal = Calendar.getInstance() | |
range = [] | |
(delegate..it).each() { | |
cal.setTime(it) | |
if (cal.get(Calendar.DATE) == 1) range << it | |
} | |
range | |
} | |
toDate('2011/04/01').createMonthRange(toDate('2012/03/01')).each() { println it } | |
// こうしたい | |
toDate('2011/04/01').stepMonthTo('2012/03/01') {print it} | |
toDate('2011/04/01').stepMonthTo('2012/03/01', 2) {print it} | |
toDate('2011/04/01').stepYearTo('2012/03/01') {print it} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment