Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
xnrghzjh / rand_date.groovy
Created June 9, 2011 09:06 — forked from kyonmm/rand_date.groovy
指定範囲内の日付をランダムに取得
@Grab(group='joda-time', module='joda-time', version='*')
import org.joda.time.*
DateTime.metaClass.random ={t->
def range = Days.daysBetween(delegate, new DateTime(t)).getDays() + 1
delegate.plusDays(Math.floor(Math.random() * range) as int).toString("yyyy-MM-dd")
}
rand_date ={f,t ->
new DateTime(f).random(t)