Opened 11 years ago
#6664 new Bugs
std::setw() is ignored by operator<< for ptime, time_duration, and date
| Reported by: | Owned by: | az_sw_dude | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | date_time |
| Version: | Boost 1.48.0 | Severity: | Cosmetic |
| Keywords: | stream manipulator ptime setw | Cc: |
Description
The following complete program demonstrates the issue. when using operator<< to display a ptime/time_duration/date, then the setw() manipulator is ignored.
My development environment is boost 1.48, building a 32-bit app on Win7 (x64) under VS2008.
I consider this a cosmetic issue as there is a very simple work-aroud - simply manually convert the ptime/date/duration object to a string before inserting it into the ostream object.
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iomanip>
#include <iostream>
#include <string>
int main()
{
boost::posix_time::ptime const now = boost::posix_time::second_clock::local_time();
std::cout
<< "\ncorrectly formatted: " << std::setw(40) << boost::posix_time::to_simple_string(now)
<< "\nptime: " << std::setw(40) << now
<< "\ntime_duration: " << std::setw(40) << now.date()
<< "\ndate: " << std::setw(40) << now.time_of_day()
<< std::endl;
}
Note:
See TracTickets
for help on using tickets.
