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 System Documentation

 


Overall Index

Introduction -- Usage Examples

Temporal Types

Class date -- Class date_duration -- Class date_period

Other Topics

Date Iterators -- Date Generators / Algorithms -- Class gregorian_calendar -- Class day_clock

Introduction

The gregorian date system provides a date programming system based the Gregorian Calendar. The first introduction of the Gregorian calendar was in 1582 to fix an error in the Julian Calendar. However, many local jurisdictions did not adopt this change until much later. Thus there is potential confusion with historical dates.

The implemented calendar is a "propleptic Gregorian calendar" which extends dates back prior to the Gregorian Calendar's first adoption in 1582. The current implementation supports dates in the range 1400-Jan-01 to 10000-Jan-01. Many references will represent dates prior to 1582 using the Julian Calendar, so caution is in order if accurate calculations are required on historic dates. See Calendrical Calculations by Reingold & Dershowitz for more details. Date information from Calendrical Calculations has been used to cross-test the correctness of the Gregorian calendar implementation.

All types for the gregorian system are found in namespace boost::gregorian. The library supports a convenience header boost/date_time/gregorian/gregorian_types.hpp that will include all the classes of the library with no input/output dependency. Another header boost/date_time/gregorian/gregorian.hpp will include the types and the input/output code.

The class boost::gregorian::date is the primary temporal type for users. If you are interested in learning about writing programs do specialized date calculations such as finding the "first sunday in april" see the date generators and algorithms page.

Usage Examples

ExampleDescription
Days Alive Days Till New YearSimple date arithmetic. Retrieve current day from clock.
Dates as stringsSimple parsing and formatting of dates from/to strings
Date Period CalculationsSee if a date is in a set of date periods (eg: is it a holiday/weekend)
Print a monthSmall utility program which prints out all the days in a month from command line. Need to know if 1999-Jan-1 was a Friday or a Saturday? This program shows how to do it.
Print HolidaysUses date generators to convert abstract specification into concrete set of dates.


Last modified: Sun Feb 9 06:52:31 MST 2003 by Jeff Garland © 2000-2002