Compare commits

...

4 Commits

Author SHA1 Message Date
nobody 74f716d2eb This commit was manufactured by cvs2svn to create tag
'Version_1_29_0'.

[SVN r15904]
2002-10-11 15:17:55 +00:00
Jeff Garland 57480d6044 add a warning about the need to define DATE_TIME_INLINE
[SVN r15754]
2002-10-06 22:51:01 +00:00
Jeff Garland b088701465 add ability to change date order in facet
[SVN r15558]
2002-09-29 20:10:47 +00:00
nobody 32091a6498 This commit was manufactured by cvs2svn to create branch 'RC_1_29_0'.
[SVN r15460]
2002-09-19 20:49:39 +00:00
9 changed files with 294 additions and 49 deletions
+7 -3
View File
@@ -26,7 +26,12 @@
The library has several functions that require the creation of a library file.
The Jamfile in the build directory will produce a library
(<font class="bold">libboost_date_time</font>) that contains these functions.
<p>
The variable <b>DATE_TIME_INLINE</b> is used to control the inlining of
certain core functions. By default this variable is defined by
in the compilation of the library. All <b>compiles using the
library must also include this define or linking errors will
result</b>.
<p>
<H2><a name="options">Compilation Options</a></H2>
<p>
@@ -40,7 +45,6 @@ for many applications that do not require nano-second resolutions.
The variable BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG, as defined in
build/Jamfile, selects between these options. To select the 64 bit
integer implementation simply remove this define from the Jamfile.
<p>
<H2><a name="portability">Compiler/Portability Notes</a></H2>
<p>
@@ -105,7 +109,7 @@ The library depends on
<hr>
<address><small>
<!-- hhmts start -->
Last modified: Wed Aug 21 15:08:31 MST 2002
Last modified: Sun Oct 6 15:55:53 MST 2002
<!-- hhmts end -->
by <a href="mailto:jeff&#64;crystalclearsoftware.com">Jeff Garland</a> &copy; 2000-2002
</small></address>
+18
View File
@@ -0,0 +1,18 @@
// This example displays the amount of time until new year's in days
#include "boost/date_time/gregorian/gregorian.hpp"
#include <iostream>
int
main()
{
using namespace boost::gregorian;
date::ymd_type today = day_clock::local_day_ymd();
date new_years_day(today.year + 1,1,1);
date_duration dd = new_years_day - date(today);
std::cout << "Days till new year: " << dd.days() << std::endl;
return 0;
};
+37
View File
@@ -0,0 +1,37 @@
// Simple program that uses the gregorian calendar to find the last
// day of the month.
#include "boost/date_time/gregorian/gregorian.hpp"
#include <iostream>
int
main()
{
std::cout << " Enter Year(ex: 2002): ";
int year, month;
std::cin >> year;
std::cout << " Enter Month(1..12): ";
std::cin >> month;
try {
int day = boost::gregorian::gregorian_calendar::end_of_month_day(year,month);
boost::gregorian::date endOfMonth(year,month,day);
std::cout << boost::gregorian::to_simple_string(endOfMonth) << std::endl;
//Iterate thru by months --
boost::gregorian::month_iterator mitr(endOfMonth,1);
boost::gregorian::date startOfNextYear(year+1,1,1);
//loop thru the days and print each one
while (mitr < startOfNextYear){
std::cout << boost::gregorian::to_simple_string(*mitr) << std::endl;
++mitr;
}
}
catch(...) {
std::cout << "Invalid Date Entered" << std::endl;
}
return 0;
}
+67 -17
View File
@@ -21,6 +21,15 @@ const char* const de_long_weekday_names[]={"Sonntag", "Montag", "Dienstag","Mitt
const char* const de_short_weekday_names[]={"Son", "Mon", "Die","Mit", "Don", "Fre", "Sam"};
const char* const us_short_month_names[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec", "NAD"};
const char* const us_long_month_names[]={"January","February","March","April","May","June","July","August","September","October","November","December","Not-A-Date"};
const char* const us_special_value_names[]={"Not-A-Date","-infinity", "+infinity"};
const char* const us_long_weekday_names[]={"Sunday", "Monday", "Tuesday","Wenesday", "Thursday", "Friday", "Saturday"};
const char* const us_short_weekday_names[]={"Sun", "Mon", "Tue","Wed", "Thu", "Fri", "Sat"};
int
main()
@@ -33,26 +42,67 @@ main()
//create a new local
std::locale default_locale;
std::locale german_dates(default_locale,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
'.'));
std::locale german_dates1(default_locale,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
'.',
boost::date_time::ymd_order_dmy,
boost::date_time::month_as_integer));
date d1(2002, Oct, 1);
std::cout.imbue(german_dates1);
// output the date in German using short month names
std::cout << d1 << std::endl; //01.10.2002
std::locale german_dates2(default_locale,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
'.',
boost::date_time::ymd_order_dmy,
boost::date_time::month_as_long_string));
std::cout.imbue(german_dates2);
greg_month m = d1.month();
std::cout << m << std::endl; //Oktober
greg_weekday wd = d1.day_of_week();
std::cout << wd << std::endl; //Dienstag
date d1(2002, Oct, 1);
std::cout.imbue(german_dates);
// output the date in German using short month names
std::cout << d1 << std::endl; //2002-Okt-01
greg_month m = d1.month();
std::cout << m << std::endl; //Oktober
greg_weekday wd = d1.day_of_week();
std::cout << wd << std::endl; //Dienstag
//Numeric date format with US month/day/year ordering
std::locale usa_dates1(default_locale,
new date_facet(us_short_month_names,
us_long_month_names,
us_special_value_names,
us_short_weekday_names,
us_long_weekday_names,
'/',
boost::date_time::ymd_order_us,
boost::date_time::month_as_integer));
std::cout.imbue(usa_dates1);
std::cout << d1 << std::endl; // 10/01/2002
//English names, iso order (year-month-day), '-' separator
std::locale usa_dates2(default_locale,
new date_facet(us_short_month_names,
us_long_month_names,
us_special_value_names,
us_short_weekday_names,
us_long_weekday_names,
'-',
boost::date_time::ymd_order_iso,
boost::date_time::month_as_short_string));
std::cout.imbue(usa_dates2);
std::cout << d1 << std::endl; // 2002-Oct-01
#else
std::cout << "Sorry, localization is not supported by this compiler/library"
<< std::endl;
+24
View File
@@ -0,0 +1,24 @@
// Simple program that uses the gregorian calendar to find the last
// day of the month.
#include "boost/date_time/gregorian/gregorian.hpp"
#include <iostream>
int
main()
{
using namespace boost::gregorian;
typedef boost::date_time::month_functor<date> add_month;
date d = day_clock::local_day();
add_month mf(1);
date d2 = d + mf.get_offset(d);
std::cout << to_simple_string(d2) << std::endl;
return 0;
}
@@ -33,11 +33,10 @@ namespace date_time {
//! Formats a month as as string into an output iterator
static void format_month(const month_type& month,
ostream_type& os,
const facet_type& f,
month_format_spec fs)
const facet_type& f)
{
switch (fs)
switch (f.month_format())
{
case month_as_short_string:
{
@@ -122,27 +121,55 @@ namespace date_time {
// return ss.str();
// }
// Put ymd to ostream -- part of ostream refactor
static void ymd_put(ymd_type ymd,
ostream_type& os,
const facet_type& f)
{
os << ymd.year;
std::ostreambuf_iterator<charT> oitr(os);
if (f.has_date_sep_chars()) {
f.month_sep_char(oitr);
switch (f.date_order()) {
case ymd_order_iso: {
os << ymd.year;
if (f.has_date_sep_chars()) {
f.month_sep_char(oitr);
}
month_formatter::format_month(ymd.month, os, f);
if (f.has_date_sep_chars()) {
f.day_sep_char(oitr);
}
os << std::setw(2) << std::setfill('0')
<< ymd.day;
break;
}
case ymd_order_us: {
month_formatter::format_month(ymd.month, os, f);
if (f.has_date_sep_chars()) {
f.day_sep_char(oitr);
}
os << std::setw(2) << std::setfill('0')
<< ymd.day;
if (f.has_date_sep_chars()) {
f.month_sep_char(oitr);
}
os << ymd.year;
break;
}
case ymd_order_dmy: {
os << std::setw(2) << std::setfill('0')
<< ymd.day;
if (f.has_date_sep_chars()) {
f.day_sep_char(oitr);
}
month_formatter::format_month(ymd.month, os, f);
if (f.has_date_sep_chars()) {
f.month_sep_char(oitr);
}
os << ymd.year;
break;
}
}
month_formatter::format_month(ymd.month, os,
f, month_as_short_string);
if (f.has_date_sep_chars()) {
f.day_sep_char(oitr);
}
os << std::setw(2) << std::setfill('0')
<< ymd.day;
}
};
+39 -4
View File
@@ -12,6 +12,7 @@
#include "boost/date_time/special_defs.hpp"
#include "boost/date_time/date_defs.hpp"
#include "boost/date_time/parse_format_base.hpp"
#include <locale>
@@ -84,6 +85,16 @@ namespace date_time {
{
do_day_sep_char(oitr);
}
//! Determines the order to put the date elements
ymd_order_spec date_order() const
{
return do_date_order();
}
//! Determines if month is displayed as integer, short or long string
month_format_spec month_format() const
{
return do_month_format();
}
protected:
//! Default facet implementation uses month_type defaults
@@ -145,7 +156,16 @@ namespace date_time {
{
put_string(oitr, "-");
}
//! Default for date order
virtual ymd_order_spec do_date_order() const
{
return ymd_order_iso;
}
//! Default month format
virtual month_format_spec do_month_format() const
{
return month_as_short_string;
}
void put_string(iter_type& oi, const char* const s) const
{
string_type s1(s);
@@ -169,12 +189,16 @@ namespace date_time {
const char* const special_value_names[],
const char* const weekday_short_names[],
const char* const weekday_long_names[],
char separator_char = '-') :
char separator_char = '-',
ymd_order_spec order_spec = ymd_order_iso,
month_format_spec month_format = month_as_short_string) :
month_short_names_(month_short_names),
month_long_names_(month_long_names),
special_value_names_(special_value_names),
weekday_short_names_(weekday_short_names),
weekday_long_names_(weekday_long_names)
weekday_long_names_(weekday_long_names),
order_spec_(order_spec),
month_format_spec_(month_format)
{
separator_char_[0] = separator_char;
separator_char_[1] = '\0';
@@ -219,6 +243,16 @@ namespace date_time {
{
put_string(oitr, separator_char_);
}
//! Set the date ordering
virtual ymd_order_spec do_date_order() const
{
return order_spec_;
}
//! Set the date ordering
virtual month_format_spec do_month_format() const
{
return month_format_spec_;
}
private:
const char* const* month_short_names_;
@@ -227,7 +261,8 @@ namespace date_time {
const char* const* weekday_short_names_;
const char* const* weekday_long_names_;
char separator_char_[2];
ymd_order_spec order_spec_;
month_format_spec month_format_spec_;
};
} } //namespace boost::date_time
@@ -45,7 +45,7 @@ namespace gregorian {
std::locale locale = os.getloc();
if (std::has_facet<greg_base_facet>(locale)) {
const greg_base_facet& f = std::use_facet<greg_base_facet>(locale);
greg_month_formatter::format_month(m, os, f, date_time::month_as_long_string);
greg_month_formatter::format_month(m, os, f);
}
else { //default to numeric
+58 -8
View File
@@ -14,7 +14,7 @@
const char* const de_long_month_names[]={"Januar","Februar","Marz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember","NichtDerMonat"};
const char* const de_special_value_names[]={"NichtDatumzeit","-unbegrenztheit", "+unbegrenztheit"};
// const char* const de_short_weekday_names[]={"Son", "Mon", "Diens"};
const char* const de_short_weekday_names[]={"Son", "Mon", "Die","Mit", "Don", "Fre", "Sam"};
const char* const de_long_weekday_names[]={"Sonntag", "Montag", "Dienstag","Mittwoch", "Donnerstag", "Freitag", "Samstag"};
@@ -40,7 +40,9 @@ main()
date_facet gdnp(de_short_month_names, de_long_month_names,
de_special_value_names, de_long_weekday_names,
de_long_weekday_names);
de_long_weekday_names,
'.',
boost::date_time::ymd_order_dmy);
std::stringstream ss;
std::ostreambuf_iterator<char> coi(ss);
@@ -50,13 +52,13 @@ main()
ss.str(""); //reset string stream
greg_month m(Oct);
month_formatter::format_month(m, ss, gdnp, boost::date_time::month_as_short_string);
month_formatter::format_month(m, ss, gdnp);
check("check german short month: " + ss.str(),
ss.str() == std::string("Okt"));
ss.str(""); //reset string stream
month_formatter::format_month(m, ss, gdnp, boost::date_time::month_as_long_string);
check("check german long month: " + ss.str(),
ss.str() == std::string("Oktober"));
// month_formatter::format_month(m, ss, gdnp);
// check("check german long month: " + ss.str(),
// ss.str() == std::string("Oktober"));
greg_year_month_day ymd(2002,Oct,1);
@@ -64,7 +66,7 @@ main()
ss.str(""); //reset string stream
ymd_formatter::ymd_put(ymd, ss, gdnp);
check("check ymd: " + ss.str(),
ss.str() == std::string("2002-Okt-01"));
ss.str() == std::string("01.Okt.2002"));
typedef boost::date_time::ostream_date_formatter<date, date_facet_base> datef;
@@ -73,7 +75,7 @@ main()
date d1(2002, Oct, 1);
datef::date_put(d1, os, gdnp);
check("ostream low level check string:"+os.str(),
os.str() == std::string("2002-Okt-01"));
os.str() == std::string("01.Okt.2002"));
// //Locale tests
std::locale global;
@@ -128,6 +130,54 @@ main()
f << d1 << std::endl;
// // date formatter that takes locale and gets facet from locale
std::locale german_dates1(global,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
'.',
boost::date_time::ymd_order_dmy,
boost::date_time::month_as_integer));
os3.imbue(german_dates1);
os3.str("");
os3 << d1;
check("check date order: "+os3.str(),
os3.str() == std::string("01.10.2002"));
std::locale german_dates2(global,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
' ',
boost::date_time::ymd_order_iso,
boost::date_time::month_as_short_string));
os3.imbue(german_dates2);
os3.str("");
os3 << d1;
check("check date order: "+os3.str(),
os3.str() == std::string("2002 Okt 01"));
std::locale german_dates3(global,
new date_facet(de_short_month_names,
de_long_month_names,
de_special_value_names,
de_short_weekday_names,
de_long_weekday_names,
' ',
boost::date_time::ymd_order_us,
boost::date_time::month_as_long_string));
os3.imbue(german_dates3);
os3.str("");
os3 << d1;
check("check date order: "+os3.str(),
os3.str() == std::string("Oktober 01 2002"));
#else