Last active
August 29, 2015 14:07
-
-
Save yujiorama/519b5c8bf29b3af28619 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='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