Skip to content

Instantly share code, notes, and snippets.

@yujiorama
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yujiorama/519b5c8bf29b3af28619 to your computer and use it in GitHub Desktop.
Save yujiorama/519b5c8bf29b3af28619 to your computer and use it in GitHub Desktop.
範囲を与えると順番に次の日を返す
@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