Bug #780
closedWCartesianChart breaks for certain date ranges
0%
Description
In WAxis::getLabelTicks there is functionality for stepping along an axis at a certain number of years/months/days/hours/minutes. It seems as though this code doesn't take account of the fact that the resulting date might be invalid, for example stepping from 30th January to the 30th February (or stepping from 29th February 2000 to 29th February 2001). When this condition is encountered an invalid date is generated, a message is logged and the application hangs (and spins up to 100% CPU). Backtrace of the failure is as follows:
#0 Wt::WDate::setDate (this=0xb3007b90, year=2010, month=2, day=29)
at .../wt-3.1.8/src/Wt/WDate.C:97
#1 0x00c9e702 in WDate (this=0xb3007b90, year=2010, month=2, day=29)
at .../wt-3.1.8/src/Wt/WDate.C:45
#2 0x00c9eb4f in Wt::WDate::addMonths (this=0xb3007ba0, nmonths=1)
at .../wt-3.1.8/src/Wt/WDate.C:72
#3 0x00ca9226 in Wt::WDateTime::addMonths (this=0xb3007e9c, nmonths=1)
at .../wt-3.1.8/src/Wt/WDateTime.C:167
#4 0x00ec153c in Wt::Chart::WAxis::getLabelTicks (this=0xe605a68, renderer=..., ticks=..., segment=0)
at .../wt-3.1.8/src/Wt/Chart/WAxis.C:858
#5 0x00ed3e5b in Wt::Chart::WChart2DRenderer::renderAxis (this=0xb1119f78, axis=..., properties=...)
at .../wt-3.1.8/src/Wt/Chart/WChart2DRenderer.C:945
#6 0x00ed51eb in Wt::Chart::WChart2DRenderer::renderAxes (this=0xb1119f78, properties=...)
at .../wt-3.1.8/src/Wt/Chart/WChart2DRenderer.C:1086
#7 0x00ed558b in Wt::Chart::WChart2DRenderer::render (this=0xb1119f78)
One possible solution is to simplify WDate by using the month and year stepping functionality in Boost.date_time, viz:
WDate WDate::addMonths(int nmonths) const
{
if (valid_) {
date d(year_, month_, day_);
d += months (nmonths);
return WDate(d.year(), d.month(), d.day());
} else
return *this;
}
WDate WDate::addYears(int nyears) const
{
if (valid_) {
date d(year_, month_, day_);
d += years (nyears);
return WDate(d.year(), d.month(), d.day());
} else
return *this;
}
IMHO, WDate should just wrap a single boost::gregorian::date - this would simplify the class considerably as well as reducing its storage size and probably increase performance (I speak from experience).
PS. thanks for an excellent package!
Updated by Koen Deforche over 13 years ago
- Status changed from New to Resolved
Hey,
I believe this has been fixed in git, at least the WDate::addMonths() and WDate::addYears() implementations, in the way you describe (if those are the new implementations?), and this fix is available in the just release Wt 3.1.9 ! Could you confirm that that solves the problem with the chart?
I agree with the regret for WDate not being based more on boost::gregorian::date (starting with using it as internal representation).
Regards,
koen
Updated by Koen Deforche over 13 years ago
- Status changed from Resolved to Closed