Created
July 16, 2014 04:43
-
-
Save arturotena/337ba7080d3c7c20f6a2 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
class Fechas implements Iterable<Timestamp> { | |
FechasIter iter; | |
Fechas(int field, int amount) { | |
this.iter = new FechasIter(field, amount); | |
} | |
public Iterator<Timestamp> iterator() { | |
return iter; | |
} | |
GregorianCalendar getCalendar() { | |
return iter.actual; | |
} | |
class FechasIter implements Iterator<Timestamp> { | |
// En particular, prueba el año 2000, que es bisiesto no por ser | |
// divisible entre 4 sino porque es divisible entre 400. | |
// (Ver http://es.wikipedia.org/wiki/A%C3%B1o_bisiesto) | |
GregorianCalendar actual = new GregorianCalendar(1970, Calendar.JANUARY, 1); | |
GregorianCalendar fin = new GregorianCalendar(2041, Calendar.JANUARY, 1); | |
int field; | |
int amount; | |
FechasIter(int field, int amount) { | |
this.field = field; | |
this.amount = amount; | |
} | |
public boolean hasNext() { | |
return actual.before(fin); | |
} | |
public Timestamp next() { | |
Timestamp next = new Timestamp(actual.getTimeInMillis()); | |
actual.add(field, amount); | |
return next; | |
} | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment