Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
Created June 13, 2011 06:39
Show Gist options
  • Save xnrghzjh/1022390 to your computer and use it in GitHub Desktop.
Save xnrghzjh/1022390 to your computer and use it in GitHub Desktop.
締め日を指定して会計月度を取得
Date.metaClass.getFiscalMonth = { p ->
cal = Calendar.getInstance();
cal.setTime(delegate)
if (cal.get(Calendar.DATE) > p) { cal.add(Calendar.MONTH, 1) }
cal.set(Calendar.DATE, 1)
cal.getTime()
}
Date.metaClass.toString = {
delegate.format('yyyy/MM/dd')
}
def toDate = { Date.parse('yyyy/MM/dd', it) }
// Test
println toDate('2011/06/20').getFiscalMonth(20).toString()
println toDate('2011/06/21').getFiscalMonth(20).toString()
println toDate('2011/06/30').getFiscalMonth(99).toString()
println toDate('2011/07/01').getFiscalMonth(99).toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment