mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-28 07:02:19 +00:00
253 lines
10 KiB
HTML
253 lines
10 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>gregorian::date Documentation</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head>
|
|
|
|
<body>
|
|
<a href="../../../index.htm">
|
|
<img align="left" src="../../../c++boost.gif" alt="C++ Boost">
|
|
</a>
|
|
|
|
<h1>gregorian::date</h1>
|
|
<p> <p>
|
|
<hr>
|
|
<p>
|
|
<a href="index.html">Overall Index</a> --
|
|
<a href="gregorian.html">Gregorian Index</a> --
|
|
<a href="posix_time.html">Posix Time Index</a>
|
|
<p>
|
|
<font class="bold">Date Documentation</font>
|
|
<p>
|
|
<a href="class_date.html#header">Header</a> --
|
|
<a href="class_date.html#construct">Construction</a> --
|
|
<a href="class_date.html#constructfromstring">Construct from String</a> --
|
|
<a href="class_date.html#constructfromclock"> Construct from Clock</a> --
|
|
<a href="class_date.html#accessors">Accessors</a> --
|
|
<a href="class_date.html#conversiontostring">Conversion To String</a> --
|
|
<a href="class_date.html#operators">Operators</a>
|
|
<p>
|
|
<h2><a name="intro">Introduction</a></h2>
|
|
|
|
<p>
|
|
The class boost::gregorian::date is the primary interface for date programming. In general, the date class is immutable once constructed although it does allow assignment.
|
|
|
|
<p>
|
|
Other techniques for creating dates include <a href="date_iterators.html">date iterators</a> and <a href="date_algorithms.html">date algorithms or generators</a>.
|
|
|
|
<p>
|
|
|
|
<p>
|
|
<h2><a name="header">Header</a></h2>
|
|
<pre>
|
|
#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
|
|
</pre>
|
|
<h2><a name="construct">Construction</a></h2>
|
|
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td class="nowrap">date(greg_year year, greg_month month, greg_day day)</td>
|
|
<td>Construct from parts of date. <b>Throws</b> bad_year,
|
|
bad_day_of_month, or bad_month (derivatives
|
|
of std::out_of_range) if
|
|
the year, month or day are out of range.
|
|
</td>
|
|
<td class="nowrap">date d(2002,Jan,10)</td></tr>
|
|
<tr><td>date(date d)</td>
|
|
<td>Copy constructor</td>
|
|
<td>date d1(d)</td></tr>
|
|
<tr><td class="nowrap">date(special_values sv)</td>
|
|
<td>Constructor for infinities, not-a-date-time, max_date, and min_date</td>
|
|
<td class="nowrap">date d1(neg_infin);<br>
|
|
date d2(pos_infin);<br>
|
|
date d3(not_a_date_time);<br>
|
|
date d4(max_date);<br>
|
|
date d5(min_date);
|
|
</td></tr>
|
|
|
|
</table>
|
|
|
|
<p>
|
|
<h2><a name="constructfromstring">Construction From String</a></h2>
|
|
|
|
The various delimited string parsers will parse dates with various types of delimiters
|
|
such as '-', '/', or spaces. In addition, the delimited parsers accept months as either
|
|
a numeric value or as a short or long case-insensitive string. For example, the
|
|
from_string function will accept all the following strings for the date Jan 25, 2002.
|
|
<ul>
|
|
<li>2002-1-25
|
|
<li>2002-Jan-25
|
|
<li>2002-January-25
|
|
<li>2002 January 25
|
|
<li>2002 jan 25
|
|
<li>2002/1/25
|
|
<li>2002/Jan/25
|
|
<li>...
|
|
</ul>
|
|
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>date <font class="func">from_string</font>(const std::string&)</td>
|
|
<td>From delimited date string where with order iso standard
|
|
ordering: year-month-day (eg: 2002-1-25)</td>
|
|
<td>std::string ds("2002/1/25"); //or 2002-Jan-25, etc<br>
|
|
date d(from_string(ds))</td></tr>
|
|
<tr><td class="nowrap">date <font class="func">from_us_string</font>(const std::string&)</td>
|
|
<td>A delimited date string where with order month-day-year eg: 1-25-2002</td>
|
|
<td class="nowrap">std::string ds("1/25/2002");<br>
|
|
date d(from_us_string(ds))</td></tr>
|
|
<tr><td class="nowrap">date <font class="func">from_uk_string</font>(const std::string&)</td>
|
|
<td>A delimited date string where with order day-month-year eg: 25-1-2002</td>
|
|
<td class="nowrap">std::string ds("25/1/2002");<br>
|
|
date d(from_us_string(ds))</td></tr>
|
|
<tr><td class="nowrap">date <font class="func">from_undelimited_string</font>(const std::string&)</td>
|
|
<td>From iso type date string where with order year-month-day eg: 20020125</td>
|
|
<td class="nowrap">std::string ds("20020125");<br>
|
|
date d(from_undelimited_string(ds))</td></tr>
|
|
|
|
</table>
|
|
<p>
|
|
|
|
<h2><a name="constructfromclock">Construction From Clock</a></h2>
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>day_clock::local_day()</td>
|
|
<td>Get the local day based on the time zone settings of the computer.</td>
|
|
<td>date d(day_clock::local_day())</td></tr>
|
|
<tr><td class="nowrap">day_clock::universal_day()</td>
|
|
<td>Get the UTC (Universal Time Coordinated) day based on the time zone settings of
|
|
the local computer.</td>
|
|
<td class="nowrap">date d(day_clock::universal_day())</td></tr>
|
|
</table>
|
|
|
|
<p>
|
|
|
|
<h2><a name="accessors">Accessors</a></h2>
|
|
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td class="nowrap">greg_year <font class="func">year</font>() const</td>
|
|
<td>Get the year part of the date.</td>
|
|
<td class="nowrap">date d(2002,Jan,10); d.year() --> 2002;</td></tr>
|
|
<tr><td>greg_month <font class="func">month</font>() const</td>
|
|
<td>Get the month part of the date.</td>
|
|
<td class="nowrap">date d(2002,Jan,10); d.month() --> 1;</td></tr>
|
|
<tr><td class="nowrap">greg_day <font class="func">day</font>() const</td>
|
|
<td>Get the day part of the date.</td>
|
|
<td class="nowrap">date d(2002,Jan,10); d.day() --> 10;</td></tr>
|
|
<tr><td>greg_ymd <font class="func">year_month_day</font>() const</td>
|
|
<td>Return a year_month_day struct. More efficient when all 3 parts of the date are needed.</td>
|
|
<td>date d(2002,Jan,10);
|
|
<br>date::ymd_type ymd = d.year_month_day();
|
|
<br>ymd.year --> 2002, ymd.month --> 1, ymd.day --> 10</td></tr>
|
|
<tr><td class="nowrap">greg_day_of_week <font class="func">day_of_week</font>() const</td>
|
|
<td>Get the day of the week (eg: Sunday, Monday, etc.</td>
|
|
<td class="nowrap">date d(2002,Jan,10); d.day() --> Thursday;</td></tr>
|
|
<tr><td class="nowrap">bool <font class="func">is_infinity</font>() const</td>
|
|
<td>Returns true if date is either positive or negative infinity</td>
|
|
<td class="nowrap">date d(pos_infin); d.is_infinity() --> true;</td></tr>
|
|
<tr><td class="nowrap">bool <font class="func">is_neg_infinity</font>() const</td>
|
|
<td>Returns true if date is negative infinity</td>
|
|
<td class="nowrap">date d(neg_infin); d.is_neg_infinity() --> true;</td></tr>
|
|
<tr><td class="nowrap">bool <font class="func">is_pos_infinity</font>() const</td>
|
|
<td>Returns true if date is positive infinity</td>
|
|
<td class="nowrap">date d(neg_infin); d.is_pos_infinity() --> true;</td></tr>
|
|
<tr><td class="nowrap">bool <font class="func">is_not_a_date</font>() const</td>
|
|
<td>Returns true if value is not a date</td>
|
|
<td class="nowrap">date d(not_a_date_time); <br>
|
|
d.is_not_a_date() --> true;
|
|
</td></tr>
|
|
<tr><td class="nowrap">long <font class="func">modjulian_day</font>() const</td>
|
|
<td>Returns the modified julian day for the date.</td>
|
|
<td></td></tr>
|
|
<tr><td class="nowrap">long <font class="func">julian_day</font>() const</td>
|
|
<td>Returns the julian day for the date.</td>
|
|
<td></td></tr>
|
|
<tr><td>int <font class="func">week_number</font>() const</td>
|
|
<td>Returns the ISO 8601 week number for the date.</td>
|
|
<td></td></tr>
|
|
|
|
</table>
|
|
|
|
<p>
|
|
<h2><a name="conversiontostring">Conversion To String</a></h2>
|
|
|
|
These convenience functions provide simple ways to converts a date into
|
|
a string. The functions are in large part here to support legacy compilers
|
|
that do not correctly support locales. See operator<< below for a normal
|
|
way to convert a date into a string.
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td class="nowrap">std::string <font class="func">to_simple_string</font>(date d)</td>
|
|
<td>To YYYY-mmm-DD string where mmm 3 char month name.</td>
|
|
<td>2002-Jan-01</td></tr>
|
|
<tr><td class="nowrap">std::string <font class="func">to_iso_string</font>(date d)</td>
|
|
<td>To YYYYMMDD where all components are integers.</td>
|
|
<td>20020131</td></tr>
|
|
<tr><td class="nowrap">std::string <font class="func">to_iso_extended_string</font>(date d)</td>
|
|
<td>To YYYY-MM-DD where all components are integers.</td>
|
|
<td>2002-01-31</td></tr>
|
|
|
|
</table>
|
|
<p>
|
|
|
|
|
|
<h2><a name="operators">Operators</a></h2>
|
|
|
|
|
|
<p>
|
|
<table border=1 cellspacing=3 cellpadding=3>
|
|
<tr><td><b>Syntax</b></td><td><b>Description</b></td><td><b>Example</b></td></tr>
|
|
<tr><td>operator<<</td>
|
|
<td>Stream output operator. Format of the output is subject to the current
|
|
localization settings. See <a href="class_greg_base_facet.html">I/O localization</a>
|
|
for more.
|
|
</td>
|
|
<td>date d(2002,Jan,1)<br>
|
|
std::cout << d << std::endl;</td></tr>
|
|
<tr><td class="nowrap">operator==, operator!=,<br> operator>, operator<
|
|
<br> operator>=, operator<=</td>
|
|
<td>A full complement of comparison operators</td>
|
|
<td>d1 == d2, etc</td></tr>
|
|
<tr><td class="nowrap">date operator+(date_duration) const</td>
|
|
<td>Return a date adding a day offset</td>
|
|
<td>date d(2002,Jan,1);
|
|
<br>date_duration dd(1);
|
|
<br>date d2 = d + dd;</td></tr>
|
|
<tr><td class="nowrap">date operator-(date_duration) const</td>
|
|
<td>Return a date by adding a day offset </td>
|
|
<td>date d(2002,Jan,1);
|
|
<br>date_duration dd(1);
|
|
<br>date d2 = d - dd;</td></tr>
|
|
<tr><td class="nowrap">date_duration operator-(date) const</td>
|
|
<td>Return a date duration by subtracting two dates</td>
|
|
<td class="nowrap">date d1(2002,Jan,1); <br>
|
|
date d2(2002,Jan,2); <br>
|
|
date_duration dd = d2-d1;
|
|
</td></tr>
|
|
|
|
</table>
|
|
|
|
<hr>
|
|
<address><small>
|
|
<!-- hhmts start -->
|
|
Last modified: Mon Jan 19 21:34:44 MST 2004
|
|
<!-- hhmts end -->
|
|
by <a href="mailto:jeff@crystalclearsoftware.com">Jeff Garland</a> © 2000-2002
|
|
</small></address>
|
|
</body>
|
|
</html>
|
|
|