Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
Created June 17, 2011 09:26
Show Gist options
  • Save xnrghzjh/1031123 to your computer and use it in GitHub Desktop.
Save xnrghzjh/1031123 to your computer and use it in GitHub Desktop.
決算開始月から1年間のデータを作成
/**
課題:ループが多い、なんか違う
*/
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