Skip to content

Instantly share code, notes, and snippets.

@kimukou
Forked from kyonmm/rand_date.groovy
Created June 9, 2011 06:40
Show Gist options
  • Save kimukou/1016191 to your computer and use it in GitHub Desktop.
Save kimukou/1016191 to your computer and use it in GitHub Desktop.
指定範囲内の日付をランダムに取得
//
// http://twitter.com/#!/xnrghzjh/status/78660855528554496
// お題
//
@Grab(group='joda-time', module='joda-time', version='*')
import org.joda.time.*
rand_date = {fr,to->
d = new DateTime(fr)
range = Days.daysBetween(d, new DateTime(to)).days + 1
d.plusDays(Math.floor(Math.random() * range) as int).toString("yyyy-MM-dd")
}
5.times {
println rand_date("1978-09-30","2011-10-10")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment