Created
June 14, 2011 03:11
-
-
Save xnrghzjh/1024234 to your computer and use it in GitHub Desktop.
会計年情報の取得
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
class FiscalInfoHolder { | |
def month | |
def date | |
def cal = Calendar.getInstance() | |
// 会計年月度の取得 | |
def getFiscalYearMonth = { | |
cal.setTime(it) | |
if (cal.get(Calendar.DATE) > date) { cal.add(Calendar.MONTH, 1) } | |
cal.getTime() | |
} | |
// 会計年度の取得 | |
def getFiscalYear = { | |
cal.setTime(getFiscalYearMonth(it)) | |
if (cal.get(Calendar.MONTH) < month) { cal.add(Calendar.YEAR, -1) } | |
cal.get(Calendar.YEAR) | |
} | |
// 会計月度の取得 | |
def getFiscalMonth = { | |
cal.setTime(getFiscalYearMonth(it)) | |
cal.get(Calendar.MONTH) | |
} | |
} | |
// テスト用メソッド | |
def toDate = { Date.parse('yyyy/MM/dd', it) } | |
Date.metaClass.toString = { delegate.format('yyyy/MM') } | |
String.metaClass.testFiscalYearMonth = { "$delegate -> ${it.getFiscalYearMonth(toDate(delegate)).toString()}" } | |
String.metaClass.testFiscalYear = { "$delegate -> ${it.getFiscalYear(toDate(delegate))}" } | |
String.metaClass.testFiscalMonth = { "$delegate -> ${it.getFiscalMonth(toDate(delegate))}" } | |
// テスト | |
holder = new FiscalInfoHolder(month:3, date:20) | |
println "■ 決算日: $holder.month/$holder.date" | |
println '会計年月度' | |
println '2011/06/20'.testFiscalYearMonth(holder) | |
println '2011/06/21'.testFiscalYearMonth(holder) | |
println '会計年度' | |
println '2011/03/20'.testFiscalYear(holder) | |
println '2011/03/21'.testFiscalYear(holder) | |
println '会計月度' | |
println '2011/06/20'.testFiscalMonth(holder) | |
println '2011/06/21'.testFiscalMonth(holder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment