Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template nth_kday_of_month

boost::date_time::nth_kday_of_month — Useful generator functor for finding holidays.

Synopsis

// In header: <boost/date_time/date_generators.hpp>

template<typename date_type> 
class nth_kday_of_month : public  {
public:
  // types
  typedef         ;   
  typedef  ;
  typedef        ;      
  typedef         ;       
  typedef         ;   

  enum week_num { first = =1, second, third, fourth, fifth };

  // construct/copy/destruct
  (, , );

  // public member functions
   () ;
   () ;
   () ;
   () ;
  const char * () ;
   () ;
};

Description

Based on the idea in Cal. Calc. for finding holidays that are the 'first Monday of September'. When instantiated with 'fifth' kday of month, the result will be the last kday of month which can be the fourth or fifth depending on the structure of the month.

The algorithm here basically guesses for the first day of the month. Then finds the first day of the correct type. That is, if the first of the month is a Tuesday and it needs Wednesday then we simply increment by a day and then we can add the length of a week until we get to the 'nth kday'. There are probably more efficient algorithms based on using a mod 7, but this one works reasonably well for basic applications.

nth_kday_of_month public construct/copy/destruct

  1. ( week_no,  dow,  m);

nth_kday_of_month public member functions

  1.  ( y) ;
    Return a concrete date when provided with a year specific year.
  2.  () ;
  3.  () ;
  4.  () ;
  5. const char * () ;
  6.  () ;
    Returns string suitable for use in POSIX time zone string.

    Returns a string formatted as "M4.3.0" ==> 3rd Sunday in April.


PrevUpHomeNext