-
-
Save xnrghzjh/1016388 to your computer and use it in GitHub Desktop.
指定範囲内の日付をランダムに取得
This file contains 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
@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) | |
} | |
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