Producing streams in java.time?

Peter Levart peter.levart at gmail.com
Thu Dec 24 09:52:13 UTC 2015


Hi,

What would really be nice to have is a Stream<ZonedDateTime> produced 
from Recurrence Rule specified as a String:

http://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html

Think of it as a built-in DSL like regex Pattern, but for generating 
arbitrary recurrences.

But this deserves an entire new class I think.

Regards, Peter

On 12/10/2015 05:31 PM, Tagir F. Valeev wrote:
> Hello!
>
> Currently it seems that java.time package does not use Stream API in
> any way. I think it would be nice to add some methods which produce
> the streams. For example:
>
> - in class Year:
>
> // Returns sequential ordered stream of all months within this Year:
> Stream<YearMonth> months();
> // Returns sequential ordered stream of all days within this Year:
> Stream<LocalDate> days();
> // Returns sequential ordered stream of all years starting from this
> // Year until the supplied year, exclusive
> Stream<Year> yearsUntil(Temporal endExclusive);
>
> - in class YearMonth:
>
> // Returns sequential ordered stream of all days within this YearMonth:
> Stream<LocalDate> days();
> // Returns sequential ordered stream of all months starting from this
> // YearMonth until the supplied YearMonth, exclusive
> Stream<YearMonth> monthsUntil(Temporal endExclusive);
>
> - in class LocalDate:
>
> // Returns sequential ordered stream of all months starting from this
> // LocalDate until the supplied LocalDate, exclusive
> Stream<LocalDate> daysUntil(Temporal endExclusive);
>
> The implementation of these methods could be quite simple. For example:
>
> class Year {
>    public Stream<LocalDate> days() {
>      return IntStream.rangeClosed(1, length()).mapToObj(this::atDay);
>    }
> }
>
> What do you think?
>
> With best regards,
> Tagir Valeev.
>




More information about the core-libs-dev mailing list