--- parser3/src/classes/date.C 2003/11/03 11:06:18 1.49 +++ parser3/src/classes/date.C 2003/11/20 17:07:43 1.55 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char* IDENT_DATE_C="$Date: 2003/11/03 11:06:18 $"; +static const char * const IDENT_DATE_C="$Date: 2003/11/20 17:07:43 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -19,7 +19,7 @@ static const char* IDENT_DATE_C="$Date: class MDate: public Methoded { public: // VStateless_class - Value* create_new_value() { return new VDate(0); } + Value* create_new_value(Pool&) { return new VDate(0); } public: MDate(); @@ -91,7 +91,7 @@ static int NN_year_to_NNNN(int year) { const char* min=lsplit(&cur, ':'); const char* sec=cur; - tm tmIn={0}; + tm tmIn; memset(tmIn, 0, sizeof(tmIn)); tmIn.tm_isdst=-1; if(!month) if(min) { @@ -138,7 +138,7 @@ static void _create(Request& r, MethodPa "invalid datetime"); } } else if(params.count()>=2) { // ^create(y;m;d[;h[;m[;s]]]) - tm tmIn={0}; + tm tmIn; memset(tmIn, 0, sizeof(tmIn)); tmIn.tm_isdst=-1; tmIn.tm_year=NN_year_to_NNNN(params.as_int(0, "year must be int", r)); tmIn.tm_mon=params.as_int(1, "month must be int", r)-1; @@ -257,7 +257,12 @@ static Table& fill_month_days(Request& r 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; - tm tmIn={0, 0, 0, 1, month, year-1900}; + tm tmIn; + memset(tmIn, 0, sizeof(tmIn)); + tmIn.tm_mday=1; + tmIn.tm_mon=month; + tmIn.tm_yday=year-1900; + time_t t=mktime(&tmIn); if(t<0) throw Exception(0, @@ -273,9 +278,9 @@ static Table& fill_month_days(Request& r for(int _day=1-weekDay1; _day<=monthDays;) { Table::element_type row(new ArrayString(7)); // calculating year week no [1..54] - char *weekno_buf; - size_t weekno_size; - int weekyear; + char *weekno_buf=0; // surely would be assigned to, but to calm down compiler + size_t weekno_size=0; // same + int weekyear=0; // same // 0..6 week days-cells fill with month days for(int wday=0; wday<7; wday++, _day++) { String* cell=new String; @@ -326,7 +331,13 @@ static Table& fill_week_days(Request& r, int month=max(1, min(params.as_int(2, "month must be int", r), 12)) -1; int day=params.as_int(3, "day must be int", r); - tm tmIn={0, 0, 18, day, month, year-1900}; + tm tmIn; + memset(tmIn, 0, sizeof(tmIn)); + tmIn.tm_hour=18; + tmIn.tm_mday=day; + tmIn.tm_mon=month; + tmIn.tm_yday=year-1900; + time_t t=mktime(&tmIn); if(t<0) throw Exception(0, @@ -385,10 +396,15 @@ static void _unix_timestamp(Request& r, // ^date.unix-timestamp[] r.write_no_lang(*new VInt((int)vdate.get_time())); } else { - // ^unix-timestamp(time_t) - time_t t=(time_t)params.as_int(0, "Unix timestamp must be integer", r); + if(vdate.get_time()) + throw Exception(0, + 0, + "date object already constructed"); + + // ^unix-timestamp(time_t) + time_t t=(time_t)params.as_int(0, "Unix timestamp must be integer", r); - vdate.set_time(t); + vdate.set_time(t); } }