--- parser3/src/classes/date.C 2003/04/08 12:47:29 1.42.2.11.2.11 +++ parser3/src/classes/date.C 2003/04/11 16:05:43 1.42.2.11.2.13 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_DATE_C="$Date: 2003/04/08 12:47:29 $"; +static const char* IDENT_DATE_C="$Date: 2003/04/11 16:05:43 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -183,53 +183,66 @@ static void _roll(Request& r, MethodPara time_t self_time=vdate.get_time(); tm tmIn=*localtime(&self_time); tm tmSaved=tmIn; + int adjust_day=0; + time_t t_changed_date; + while(true) { + tmIn.tm_year+=oyear; + tmIn.tm_mon+=omonth; + tmIn.tm_mday+=oday+adjust_day; + tmIn.tm_hour=24/2; + tmIn.tm_min=0; + tmIn.tm_sec=0; + int saved_mon=(tmIn.tm_mon+12*100)%12; // crossing year boundary backwards + t_changed_date=mktime/*normalizetime*/(&tmIn); + if(t_changed_date<0) + throw Exception(0, + 0, + "bad resulting time (rolled out of valid date range)"); + if(oday==0 && tmIn.tm_mon!=saved_mon/*but it changed*/) { + if(adjust_day <= -3/*31->28 max, so never, but...*/) + throw Exception(0, + 0, + "bad resulting time (day hole still with %d day adjustment)", adjust_day ); + + tmIn=tmSaved; // restoring + --adjust_day; //retrying with prev day + } else + break; + } - tmIn.tm_year+=oyear; - tmIn.tm_mon+=omonth; - tmIn.tm_mday+=oday; - tmIn.tm_hour=24/2; - tmIn.tm_min=0; - tmIn.tm_sec=0; - time_t t=mktime/*normalizetime*/(&tmIn); - if(t<0) - throw Exception(0, - 0, - "bad resulting time (after roll)"); - if(oday==0 && tmIn.tm_mday!=tmSaved.tm_mday) - throw Exception(0, - 0, - "bad resulting time (day hole)", t); - - tm *tmOut=localtime(&t); + tm *tmOut=localtime(&t_changed_date); if(!tmOut) throw Exception(0, 0, - "bad resulting time (seconds from epoch=%ld)", t); + "bad resulting time (seconds from epoch=%d)", t_changed_date); - tmOut->tm_hour=tmSaved.tm_hour; - tmOut->tm_min=tmSaved.tm_min; - tmOut->tm_sec=tmSaved.tm_sec; + tmOut->tm_hour=tmSaved.tm_hour; + tmOut->tm_min=tmSaved.tm_min; + tmOut->tm_sec=tmSaved.tm_sec; tmOut->tm_isdst=-1; { - time_t t=mktime/*normalizetime*/(tmOut); + time_t t_changed_time=mktime/*normalizetime*/(tmOut); + /*autofix: in msk timezone last sunday of april hour hole: [2am->3am) if( tmOut->tm_hour!=tmSaved.tm_hour ||tmOut->tm_min!=tmSaved.tm_min) throw Exception(0, 0, "bad resulting time (hour hole)"); + */ - if(t<0) + if(t_changed_time<0) throw Exception(0, 0, "bad resulting time (after reconstruction)"); - vdate.set_time(t); + vdate.set_time(t_changed_time); } } static Table& fill_month_days(Request& r, MethodParams& params, bool rus){ - Table& result=*new Table(date_calendar_table_template); + Table::Action_options table_options; + Table& result=*new Table(date_calendar_table_template, table_options); int year=params.as_int(1, "year must be int", r); int month=max(1, min(params.as_int(2, "month must be int", r), 12)) -1;