PrevUpHomeNext

Class month_day_iterator

fd::gregorian::month_day_iterator — Day-of-month iterator, which stays at the date of month specified at construction time, with the ability to add an optional number of days to the resulting date.

Synopsis

// In header: <fd/date_iterators.h>


class month_day_iterator : public fd::gregorian::date_iterator_interface {
public:

  // public member functions
  month_day_iterator(date_type, int, short);
  constexpr duration_type get_offset(const date_type &) const;
  constexpr duration_type get_neg_offset(const date_type &) const;
  constexpr short origin_day_spec() const;

  // private member functions
  constexpr duration_type 
  offset(const date_type &, 
         int(boost::date_time::wrapping_int2< short, 1, 12 >::*)(int)) const;
};

Description

It's called 'month_day_iterator' to disambiguate it from boost date/time's month iterator. The latter has the problem that it is dependent on the date it is constructed from: If the date is the last day of the date's month then it automatically snaps to the last day, otherwise not. This is usually wrong for month-based iteration as the programmer needs to have control over the origin day of month.

month_day_iterator public member functions

  1. month_day_iterator(date_type d, int f, short originDayOfMonthSpec);

    Parameters:

    d

    Current date (year, month) where to set up the iterator.

    f

    Factor, i.e. how many month to forward on each iteration.

    originDayOfMonthSpec

    The day of month [1..31] to set up the iterator. Special values:

    • 0: Take origin day of month from specified date.

    • [-n..-1, 31..m]: Snap to last day of each month.

  2. constexpr duration_type get_offset(const date_type & current) const;
  3. constexpr duration_type get_neg_offset(const date_type & current) const;
  4. constexpr short origin_day_spec() const;

month_day_iterator private member functions

  1. constexpr duration_type 
    offset(const date_type & current, 
           int(boost::date_time::wrapping_int2< short, 1, 12 >::*)(int) add_or_sub) const;

PrevUpHomeNext