Skip to content

Instantly share code, notes, and snippets.

@kyonmm
Forked from xnrghzjh/rand_date.groovy
Created June 9, 2011 06:15
Show Gist options
  • Save kyonmm/1016168 to your computer and use it in GitHub Desktop.
Save kyonmm/1016168 to your computer and use it in GitHub Desktop.
指定範囲内の日付をランダムに取得
@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")
}
5.times{
println new DateTime("1978-09-30").random("2011-10-10")
}
@kyonmm
Copy link
Author

kyonmm commented Jun 9, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment