Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.
C++ Boost

gregorian::date_duration


Overall Index -- Gregorian Index -- Posix Time Index

Date Documentation

Header -- Construction -- Accessors -- Operators

Introduction

The class boost::gregorian::date_duration is a simple day count used for arithmetic with gregorian::date. A duration can be either positive or negative. In addition, date_durations can take on special values such as not_a_date_time. More information on how these special values impact calculation can be found in Calculations.

Header

#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
or
#include "boost/date_time/gregorian/gregorian_types.hpp" //no i/o just types

Construction

SyntaxDescriptionExample
date_duration(long) Create a duration count. date_duration dd(3); //3 days
date_duration(const date_duration& dd) Copy constructor.
date_duration(special_values) Create a duration with a special value such as neg_infin, pos_infin or not_a_date_time date_duration dd(note_a_date_time); //invalid value

Accessors

SyntaxDescriptionExample
long days() const Get the day count. date_duration dd(3); dd.days() --> 3
bool is_negative() const True if number of days is less than zero.. date_duration dd(-1); dd.is_negative() --> true
static date_duration unit() Return smallest possible unit of duration type. date_duration::unit() --> date_duration(1)

Operators

SyntaxDescriptionExample
operator==, operator!=,
operator>, operator<
operator>=, operator<=
A full complement of comparison operators dd1 == dd2, etc
date_duration operator+(date_duration) const Add date durations. date_duration dd1(3);
date_duration dd2(5);
date_duration dd3 = dd1 + dd2;
date_duration operator-(date_duration) const Subtract durations. date_duration dd1(3);
date_duration dd2(5);
date_duration dd3 = dd1 - dd2;
date_duration operator-() const Invert sign date_duration dd1(3);
-dd1; // dd1 == -3 days


Last modified: Sun Jan 18 15:15:35 MST 2004 by Jeff Garland © 2000-2002