Lamma I/O

Recurrence Patterns

All code used in this tutorial can be found here: Scala / Java

Recurrence pattern is about how to populate a list of dates. Lamma has 4 build-in patterns: Daily, Weekly, Monthly and Yearly. All build-in patterns are inclusive. You can also easily implement your own pattern.

When you are building your date range, Lamma will choose base on your frequency.
For example, Date(2015, 2, 1) to Date(2015, 10, 10) by (5 weeks) basically tells Lamma to use Weekly(5) recurrence pattern.
Now let's look at them one by one.

Daily recurrence pattern

As the name implies, daily pattern generate dates for every n days.

generates dates by number of days

Generate every 5 days from 2014-05-10 to 2014-05-27

Date(2015, 5, 10) to Date(2015, 5, 27) by (5 days)
Dates.from(2015, 5, 10).to(2015, 5, 27).byDays(5).build();

Result:

DateRange(Date(2015,5,10), Date(2015,5,15), Date(2015,5,20), Date(2015,5,25))


dates are generated inclusively

Generate every 5 days from 2014-05-10 to 2014-05-20

Date(2015, 5, 10) to Date(2015, 5, 20) by (5 days)
Dates.from(2015, 5, 10).to(2015, 5, 20).byDays(5).build();

Result:

DateRange(Date(2015,5,10), Date(2015,5,15), Date(2015,5,20))


days keyword can be omitted

Generate every 5 days from 2014-05-10 to 2014-05-20

Date(2015, 5, 10) to Date(2015, 5, 20) by 5
Dates.from(2015, 5, 10).to(2015, 5, 20).by(5).build();

Result:

DateRange(Date(2015,5,10), Date(2015,5,15), Date(2015,5,20))


By default, Lamma will use by (1 day) pattern if nothing is specified

Generate every day from 2014-05-10 to 2014-05-12

Date(2015, 5, 10) to Date(2015, 5, 12)
Dates.from(2015, 5, 10).to(2015, 5, 12).build();

Result:

DateRange(Date(2015,5,10), Date(2015,5,11), Date(2015,5,12))


Daily pattern support negative days. The result will be in reverse chronological

Generate every day from 2014-05-20 to 2014-05-10 by 5 days

Date(2015, 5, 20) to Date(2015, 5, 10) by -5
Dates.from(2015, 5, 20).to(2015, 5, 10).by(-5).build();

Result:

DateRange(Date(2015,5,20), Date(2015,5,15), Date(2015,5,10))


Rest part coming soon...