Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
範囲を与えると順番に次の日を返す
@Grab(group='joda-time', module='joda-time', version='2.4')
import org.joda.time.*
import org.joda.time.format.*
class DateIterator {
def v
def last
def DateIterator(from, to) {
v = from
last = to
}
Iterator iterator() {
return [
hasNext : {
last.isAfter(v)
},
next: {
def result = v
v = v.plusDays(1)
result
}
] as Iterator
}
}
def d = DateTimeFormat.forPattern("yyyy/MM/dd").parseDateTime("2014/09/01")
new DateIterator(d, d.plusMonths(1)).each { d ->
println d.toString("yyyy/MM/dd")
}
//
// 2014/09/01
// 2014/09/02
// 2014/09/03
// ...
// 2014/09/30
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment