Opened 10 years ago

#7840 new Bugs

Failure in posix_time_zone when specifying start date as Jn

Reported by: andrew.lang@… Owned by: az_sw_dude
Milestone: To Be Determined Component: date_time
Version: Boost 1.50.0 Severity: Problem
Keywords: Cc:

Description

If you use the time zone specification "CST-2CDT,J365/00,J1/00" to create a boost::local_time::posix_time_zone, it fails with an exception.

The problem appears to be in boost\date_time\local_time\posix_time_zone.hpp, julian_no_leap(...). The conversion of the start date uses this loop which has a "less than or equal" clause:

while(sd >= calendar::end_of_month_day(year,sm)){

sd -= calendar::end_of_month_day(year,sm++);

}

sd is the converted start specifier (365 in this case); sm is the current month (initialized to 1). The loop continues until sd=0 and sm=13, at which point end_of_month_day() throws an exception.

Conversion of the end date uses an almost identical loop except that its while clause is "strictly less than":

while(ed > calendar::end_of_month_day(year,em)){

ed -= calendar::end_of_month_day(year,em++);

}

So the specifier "CST-2CDT,J1/00,J365/00" leaves ed=31 and em=12 as you would hope.

In fact any start specifier at the end of a month (J31, J59,...J334) will fail later because it will result in sd=0 which is outside the range of 1..31.

This code is identical in boost 1.52.0. The fix appears to be just to use "strictly less than" in both loops.

Attachments (1)

ticket7840-01112013.patch (500 bytes ) - added by genevivewoo@… 10 years ago.

Download all attachments as: .zip

Change History (1)

by genevivewoo@…, 10 years ago

Attachment: ticket7840-01112013.patch added
Note: See TracTickets for help on using tickets.