Class CalendarCalculator
java.lang.Object
com.globalmentor.calendar.calculator.CalendarCalculator
Utilities for working with local dates.
- Author:
- Garret Wilson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetDayCounts(Set<com.globalmentor.model.Range<LocalDate>> ranges, boolean isRangeLowerInclusive) Calculates the counts of calendar days before that intersect a set of ranges.getDayTotals(LocalDate date, int windowSize, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date.getDayTotals(LocalDate date, LocalDate resetDate, int windowSize, int historyCount, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date, including the given number of days in the history.getDayTotals(LocalDate date, LocalDate resetDate, int windowSize, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date.
-
Constructor Details
-
CalendarCalculator
public CalendarCalculator()
-
-
Method Details
-
getDayCounts
public static SortedMap<LocalDate,com.globalmentor.model.Count> getDayCounts(Set<com.globalmentor.model.Range<LocalDate>> ranges, boolean isRangeLowerInclusive) Calculates the counts of calendar days before that intersect a set of ranges. If an exclusive range lower bound is requested, the lower bound date will nevertheless be provided at least a count of0for convenience, to indicate that the date has been considered but not included.- Parameters:
ranges- The ranges used for counting.isRangeLowerInclusive-trueif the date of the lower bound of each range should be included in the counts, orfalseif it should not be included.- Returns:
- A map of all calendar days and the corresponding total number of intersections for each with the ranges.
- Throws:
IllegalArgumentException- if the lower bound of one of the ranges is above its upper bound.
-
getDayTotals
public static SortedMap<LocalDate,Long> getDayTotals(LocalDate date, int windowSize, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date.For example, passing a calendar date of 2000-01-01 with a day count of 365, will return, for each day in the previous year, the number of days that intersect one of the ranges.
- Parameters:
date- The current date to use for calculations.windowSize- The number of days back to include in each total.dayCounts- A map of totals for individual dates.- Returns:
- A map of all calendar days and the total number of intersection with the ranges within that period.
-
getDayTotals
public static SortedMap<LocalDate,Long> getDayTotals(LocalDate date, LocalDate resetDate, int windowSize, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date.For example, passing a calendar date of 2000-01-01 with a day count of 365, will return, for each day in the previous year, the number of days that intersect one of the ranges.
- Parameters:
date- The current date to use for calculations.resetDate- The date used for reset calculations.windowSize- The number of days back to include in each total.dayCounts- A map of totals for individual dates.- Returns:
- A map of all calendar days and the total number of intersection with the ranges within that period.
-
getDayTotals
public static SortedMap<LocalDate,Long> getDayTotals(LocalDate date, LocalDate resetDate, int windowSize, int historyCount, Map<LocalDate, com.globalmentor.model.Count> dayCounts) Calculates the totals for a particular date and a number of calendar days before that date, including the given number of days in the history.For example, passing a calendar date of 2000-01-01 with a window size of 365 and a history count of 730, will return, for 730 days prior to the given date, the number of days that intersect one of the ranges within the window of 365 days before each date.
- Parameters:
date- The current date to use for calculations.resetDate- The date used for reset calculations.windowSize- The number of days back to include in each total.historyCount- The number of day totals to include.dayCounts- A map of totals for individual dates.- Returns:
- A map of all calendar days and the total number of intersection with the ranges within the indicated history period.
-