次のようなものが必要になる場合があります。
def lastWeek
use(org.codehaus.groovy.runtime.TimeCategory) {
lastWeek = new Date() - 1.week
}
render(view:'list', model: [incidentInstanceList: Incident.findAllByStatusIlikeAndOpenOnGreaterThan( "closed", lastWeek, [sort:"id", order: "desc"])] )
アップデート:
import java.util.Calendar
import groovy.time.TimeCategory
def roundToLastMonday(date) {
Calendar cal=Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) - cal.get(Calendar.DAY_OF_WEEK) + Calendar.MONDAY)
cal.getTime()
}
def getLastWeekRange() {
def startDate, endDate
use(TimeCategory) {
startDate = roundToLastMonday(1.week.ago)
endDate = startDate + 1.week - 1.second
}
[startDate, endDate]
}
def range = getLastWeekRange()
def result = Incident.withCriteria {
like ("status", "closed")
between ("open", range[0], range[1])
}
render(view:'list', model: [incidentInstanceList: result]