BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bblb_schedulegenerationutil.h
Go to the documentation of this file.
1/// @file bblb_schedulegenerationutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bblb_schedulegenerationutil.h -*-C++-*-
8#ifndef INCLUDED_BBLB_SCHEDULEGENERATIONUTIL
9#define INCLUDED_BBLB_SCHEDULEGENERATIONUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bblb_schedulegenerationutil bblb_schedulegenerationutil
15/// @brief Provide functions for generating schedules of dates.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bblb
19/// @{
20/// @addtogroup bblb_schedulegenerationutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bblb_schedulegenerationutil-purpose"> Purpose</a>
25/// * <a href="#bblb_schedulegenerationutil-classes"> Classes </a>
26/// * <a href="#bblb_schedulegenerationutil-description"> Description </a>
27/// * <a href="#bblb_schedulegenerationutil-usage"> Usage </a>
28/// * <a href="#bblb_schedulegenerationutil-example-1-generating-a-schedule"> Example 1: Generating a Schedule </a>
29///
30/// # Purpose {#bblb_schedulegenerationutil-purpose}
31/// Provide functions for generating schedules of dates.
32///
33/// # Classes {#bblb_schedulegenerationutil-classes}
34///
35/// - bblb::ScheduleGenerationUtil: namespace for schedule generation functions
36///
37/// @see
38///
39/// # Description {#bblb_schedulegenerationutil-description}
40/// This component provides a `struct`,
41/// `bblb::ScheduleGenerationUtil`, that serves as a namespace for functions
42/// that generate a schedule; a set of dates limited to within a closed-interval
43/// date-range, represented by the specified `earliest` and `latest` dates.
44/// Typically, a schedule generation method can be defined by an algorithm
45/// specific to the method, an `example` date, a closed-interval represented by
46/// an `earliest` and a `latest` date, and any other information required to
47/// determine the interval between successive dates in a schedule (for example,
48/// the number of days or months between successive dates). The process of
49/// computing the dates within a schedule is exemplified using the following
50/// diagram:
51/// @code
52/// ___________|__________________|___________________|________
53/// 'example' 'earliest' 'latest'
54/// .___.___.___.___.___|___|___|___|___|___.
55/// ^ ^ ^ ^ ^
56/// 'interval':.___. | | | | |
57/// 'schedule': [d0, d1, d2, d3, d4]
58/// @endcode
59/// The schedule generated in the above diagram is `[d0, d1, d2, d3, d4]`.
60/// Notice that the `example` date does not have to reside within the closed
61/// interval (the `example` date is before the `earliest` date in this diagram).
62///
63/// More formally, the resulting `schedule` is the subset of the infinite series
64/// of dates, defined by all dates separated by an integral multiple of
65/// intervals from the `example` date, that reside within the closed-interval
66/// specified by `earliest` and `latest`.
67///
68/// The following section provides a synopsis of the main functions provided in
69/// this component:
70/// @code
71/// 'generateFromDayInterval' Generate a schedule having an
72/// interval of a fixed number of days.
73///
74/// 'generateFromDayOfMonth' Generate a schedule having an
75/// interval of a fixed number of
76/// months, with each date in the
77/// schedule occuring on a specific day
78/// of the month.
79///
80/// 'generateFromBusinessDayOfMonth' Generate a schedule having an
81/// interval of a fixed number of
82/// months, with each date in the
83/// schedule occuring on a specific
84/// business day of the month.
85///
86/// 'generateFromDayOfWeekAfterDayOfMonth' Generate a schedule having an
87/// interval of a fixed number of
88/// months, with each date in the
89/// schedule occuring on a specific day
90/// of the week on or after a specific
91/// day of the month.
92///
93/// 'generateFromDayOfWeekInMonth' Generate a schedule having an
94/// interval of a fixed number of
95/// months, with each date in the
96/// schedule occuring on a specific day
97/// of the week in a specific week of
98/// the month.
99/// @endcode
100///
101/// ## Usage {#bblb_schedulegenerationutil-usage}
102///
103///
104/// This section illustrates intended use of this component.
105///
106/// ### Example 1: Generating a Schedule {#bblb_schedulegenerationutil-example-1-generating-a-schedule}
107///
108///
109/// Suppose that we want to determine the sequence of dates that are:
110/// * integral multiples of 9 months away from July 2007,
111/// * on the 23rd day of the month,
112/// * and within the closed interval `[02/01/2012, 02/28/2015]`.
113///
114/// First, we define the inputs and output to the schedule generation function:
115/// @code
116/// bdlt::Date earliest(2012, 2, 1);
117/// bdlt::Date latest(2015, 2, 28);
118/// bdlt::Date example(2007, 7, 23);
119///
120/// bsl::vector<bdlt::Date> schedule;
121/// @endcode
122/// Now, we invoke the `generateFromDayOfMonth` routine to obtain the subset of
123/// dates:
124/// @code
125/// bblb::ScheduleGenerationUtil::generateFromDayOfMonth(
126/// &schedule,
127/// earliest,
128/// latest,
129/// example.year(),
130/// example.month(),
131/// 9, // 'intervalInMonths'
132/// 23); // 'targetDayOfMonth'
133/// @endcode
134/// Finally, we assert that the generated schedule is what we expect:
135/// @code
136/// assert(4 == schedule.size());
137/// assert(bdlt::Date(2012, 10, 23) == schedule[0]);
138/// assert(bdlt::Date(2013, 7, 23) == schedule[1]);
139/// assert(bdlt::Date(2014, 4, 23) == schedule[2]);
140/// assert(bdlt::Date(2015, 1, 23) == schedule[3]);
141/// @endcode
142/// @}
143/** @} */
144/** @} */
145
146/** @addtogroup bbl
147 * @{
148 */
149/** @addtogroup bblb
150 * @{
151 */
152/** @addtogroup bblb_schedulegenerationutil
153 * @{
154 */
155
156#include <bblscm_version.h>
157
158#include <bdlt_calendar.h>
159#include <bdlt_date.h>
160#include <bdlt_dayofweek.h>
161
162#include <bsls_libraryfeatures.h>
163
164#include <bsl_vector.h>
165
166#include <vector> // 'std::vector', 'std::pmr::vector'
167
168
169namespace bblb {
170
171 // =============================
172 // struct ScheduleGenerationUtil
173 // =============================
174
175/// This `struct` provides a namespace for utility functions that generate
176/// schedules.
178
179 // CLASS METHODS
181 bsl::vector<bdlt::Date> *schedule,
182 const bdlt::Date& earliest,
183 const bdlt::Date& latest,
184 const bdlt::Date& example,
185 int intervalInDays);
187 std::vector<bdlt::Date> *schedule,
188 const bdlt::Date& earliest,
189 const bdlt::Date& latest,
190 const bdlt::Date& example,
191 int intervalInDays);
192#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
193 static void generateFromDayInterval(
194 std::pmr::vector<bdlt::Date> *schedule,
195 const bdlt::Date& earliest,
196 const bdlt::Date& latest,
197 const bdlt::Date& example,
198 int intervalInDays);
199#endif
200 // Load, into the specified 'schedule', the chronologically increasing
201 // sequence of unique dates that are integral multiples of the
202 // specified 'intervalInDays' away from the specified 'example' date,
203 // and within the specified closed-interval '[earliest, latest]'. The
204 // behavior is undefined unless 'earliest <= latest' and
205 // '1 <= intervalInDays'.
206
208 bsl::vector<bdlt::Date> *schedule,
209 const bdlt::Date& earliest,
210 const bdlt::Date& latest,
211 int exampleYear,
212 int exampleMonth,
213 int intervalInMonths,
214 int targetDayOfMonth,
215 int targetDayOfFeb = 0);
217 std::vector<bdlt::Date> *schedule,
218 const bdlt::Date& earliest,
219 const bdlt::Date& latest,
220 int exampleYear,
221 int exampleMonth,
222 int intervalInMonths,
223 int targetDayOfMonth,
224 int targetDayOfFeb = 0);
225#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
226 static void generateFromDayOfMonth(
227 std::pmr::vector<bdlt::Date> *schedule,
228 const bdlt::Date& earliest,
229 const bdlt::Date& latest,
230 int exampleYear,
231 int exampleMonth,
232 int intervalInMonths,
233 int targetDayOfMonth,
234 int targetDayOfFeb = 0);
235#endif
236 // Load, into the specified 'schedule', the chronologically increasing
237 // sequence of unique dates that are on the specified
238 // 'targetDayOfMonth' (or the last day of the month if
239 // 'targetDayOfMonth' would be past the end of the month), integral
240 // multiples of the specified 'intervalInMonths' away from the
241 // specified 'exampleYear' and 'exampleMonth', and within the specified
242 // closed-interval '[earliest, latest]'. Optionally specify
243 // 'targetDayOfFeb' to replace 'targetDayOfMonth' whenever the month of
244 // a 'schedule' entry is February. The behavior is undefined unless
245 // 'earliest <= latest', '1 <= exampleYear <= 9999',
246 // '1 <= exampleMonth <= 12', '1 <= intervalInMonths',
247 // '1 <= targetDayOfMonth <= 31', and '0 <= targetDayOfFeb <= 29'.
248
250 bsl::vector<bdlt::Date> *schedule,
251 const bdlt::Date& earliest,
252 const bdlt::Date& latest,
253 int exampleYear,
254 int exampleMonth,
255 int intervalInMonths,
256 const bdlt::Calendar& calendar,
257 int targetBusinessDayOfMonth);
259 std::vector<bdlt::Date> *schedule,
260 const bdlt::Date& earliest,
261 const bdlt::Date& latest,
262 int exampleYear,
263 int exampleMonth,
264 int intervalInMonths,
265 const bdlt::Calendar& calendar,
266 int targetBusinessDayOfMonth);
267#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
269 std::pmr::vector<bdlt::Date> *schedule,
270 const bdlt::Date& earliest,
271 const bdlt::Date& latest,
272 int exampleYear,
273 int exampleMonth,
274 int intervalInMonths,
275 const bdlt::Calendar& calendar,
276 int targetBusinessDayOfMonth);
277#endif
278 // Load, into the specified 'schedule', the chronologically increasing
279 // sequence of unique dates that are on the specified
280 // 'targetBusinessDayOfMonth' (or the highest count possible in the
281 // resulting month), integral multiples of the specified
282 // 'intervalInMonths' away from the specified 'exampleYear' and
283 // 'exampleMonth', and within the specified closed-interval
284 // '[earliest, latest]'. Business days, as per the specified
285 // 'calendar', are counted, if 'targetBusinessDayOfMonth' is positive,
286 // from and including the chronologically earliest business day to
287 // chronologically later business days, and if
288 // 'targetBusinessDayOfMonth' is negative, from and including the
289 // chronologically latest business day to chronologically earlier
290 // business days. If any of the months required for the schedule do
291 // not have a business day, return an empty 'schedule'. The behavior
292 // is undefined unless 'earliest <= latest',
293 // '1 <= exampleYear <= 9999', '1 <= exampleMonth <= 12',
294 // '1 <= intervalInMonths', and
295 // '1 <= abs(targetBusinessDayOfMonth) <= 31'.
296
298 bsl::vector<bdlt::Date> *schedule,
299 const bdlt::Date& earliest,
300 const bdlt::Date& latest,
301 int exampleYear,
302 int exampleMonth,
303 int intervalInMonths,
304 bdlt::DayOfWeek::Enum dayOfWeek,
305 int dayOfMonth);
307 std::vector<bdlt::Date> *schedule,
308 const bdlt::Date& earliest,
309 const bdlt::Date& latest,
310 int exampleYear,
311 int exampleMonth,
312 int intervalInMonths,
313 bdlt::DayOfWeek::Enum dayOfWeek,
314 int dayOfMonth);
315#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
317 std::pmr::vector<bdlt::Date> *schedule,
318 const bdlt::Date& earliest,
319 const bdlt::Date& latest,
320 int exampleYear,
321 int exampleMonth,
322 int intervalInMonths,
323 bdlt::DayOfWeek::Enum dayOfWeek,
324 int dayOfMonth);
325#endif
326 // Load, into the specified 'schedule', the chronologically increasing
327 // sequence of unique dates that are on the specified 'dayOfWeek' on or
328 // after the specified 'dayOfMonth', integral multiples of the
329 // specified 'intervalInMonths' away from the specified 'exampleYear'
330 // and 'exampleMonth', and within the specified closed-interval
331 // '[earliest, latest]'. If any of the months required for the
332 // schedule have fewer than 'dayOfMonth' days, return an empty
333 // 'schedule'. The behavior is undefined unless 'earliest <= latest',
334 // '1 <= exampleYear <= 9999', '1 <= exampleMonth <= 12',
335 // '1 <= intervalInMonths', and '1 <= dayOfMonth <= 31'.
336
338 bsl::vector<bdlt::Date> *schedule,
339 const bdlt::Date& earliest,
340 const bdlt::Date& latest,
341 int exampleYear,
342 int exampleMonth,
343 int intervalInMonths,
344 bdlt::DayOfWeek::Enum dayOfWeek,
345 int occurrenceWeek);
347 std::vector<bdlt::Date> *schedule,
348 const bdlt::Date& earliest,
349 const bdlt::Date& latest,
350 int exampleYear,
351 int exampleMonth,
352 int intervalInMonths,
353 bdlt::DayOfWeek::Enum dayOfWeek,
354 int occurrenceWeek);
355#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR
357 std::pmr::vector<bdlt::Date> *schedule,
358 const bdlt::Date& earliest,
359 const bdlt::Date& latest,
360 int exampleYear,
361 int exampleMonth,
362 int intervalInMonths,
363 bdlt::DayOfWeek::Enum dayOfWeek,
364 int occurrenceWeek);
365#endif
366 // Load, into the specified 'schedule', the chronologically increasing
367 // sequence of unique dates that are on the specified 'dayOfWeek' of
368 // the specified 'occurrenceWeek' of the month, integral multiples of
369 // the specified 'intervalInMonths' away from the specified
370 // 'exampleYear' and 'exampleMonth', and within the specified
371 // closed-interval '[earliest, latest]'. The behavior is undefined
372 // unless 'earliest <= latest', '1 <= exampleYear <= 9999',
373 // '1 <= exampleMonth <= 12', '1 <= intervalInMonths', and
374 // '1 <= occurrenceWeek <= 4'.
375};
376
377} // close package namespace
378
379
380#endif
381
382// ----------------------------------------------------------------------------
383// Copyright 2016 Bloomberg Finance L.P.
384//
385// Licensed under the Apache License, Version 2.0 (the "License");
386// you may not use this file except in compliance with the License.
387// You may obtain a copy of the License at
388//
389// http://www.apache.org/licenses/LICENSE-2.0
390//
391// Unless required by applicable law or agreed to in writing, software
392// distributed under the License is distributed on an "AS IS" BASIS,
393// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
394// See the License for the specific language governing permissions and
395// limitations under the License.
396// ----------------------------- END-OF-FILE ----------------------------------
397
398/** @} */
399/** @} */
400/** @} */
Definition bdlt_calendar.h:569
Definition bdlt_date.h:294
Definition bslstl_vector.h:1025
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bblb_schedulegenerationutil.h:169
Definition bblb_schedulegenerationutil.h:177
static void generateFromDayOfMonth(std::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, int targetDayOfMonth, int targetDayOfFeb=0)
static void generateFromDayInterval(std::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, const bdlt::Date &example, int intervalInDays)
static void generateFromDayOfMonth(bsl::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, int targetDayOfMonth, int targetDayOfFeb=0)
static void generateFromDayOfWeekInMonth(bsl::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, bdlt::DayOfWeek::Enum dayOfWeek, int occurrenceWeek)
static void generateFromDayOfWeekAfterDayOfMonth(std::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, bdlt::DayOfWeek::Enum dayOfWeek, int dayOfMonth)
static void generateFromBusinessDayOfMonth(std::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, const bdlt::Calendar &calendar, int targetBusinessDayOfMonth)
static void generateFromBusinessDayOfMonth(bsl::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, const bdlt::Calendar &calendar, int targetBusinessDayOfMonth)
static void generateFromDayOfWeekInMonth(std::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, bdlt::DayOfWeek::Enum dayOfWeek, int occurrenceWeek)
static void generateFromDayOfWeekAfterDayOfMonth(bsl::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, int exampleYear, int exampleMonth, int intervalInMonths, bdlt::DayOfWeek::Enum dayOfWeek, int dayOfMonth)
static void generateFromDayInterval(bsl::vector< bdlt::Date > *schedule, const bdlt::Date &earliest, const bdlt::Date &latest, const bdlt::Date &example, int intervalInDays)
Enum
Enumerated day-of-week values.
Definition bdlt_dayofweek.h:123