--- parser3/src/classes/date.C 2004/01/30 09:39:45 1.59 +++ parser3/src/classes/date.C 2004/02/19 15:16:53 1.63 @@ -1,11 +1,11 @@ /** @file Parser: @b date parser class. - Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_DATE_C="$Date: 2004/01/30 09:39:45 $"; +static const char * const IDENT_DATE_C="$Date: 2004/02/19 15:16:53 $"; #include "classes.h" #include "pa_vmethod_frame.h" @@ -61,21 +61,12 @@ static void _now(Request& r, MethodParam } /// shrinked range: 1970/1/1 to 2038/1/1 -static int check_year(int iyear) { +static int to_tm_year(int iyear) { if(iyear<1970 || iyear>2038) throw Exception(0, 0, "year '%d' is out of valid range", iyear); - return iyear; -} - -static int ato_year(const char* syear) { - int iyear=atoi(syear); - if(iyear==0) - throw Exception(0, - 0, - "invalid year: '%s'", syear); - return check_year(iyear); + return iyear-1900; } // 2002-04-25 18:14:00 @@ -114,13 +105,13 @@ static int ato_year(const char* syear) { goto date_part_set; } else hour=min=sec=0; // not YYYY- & not HH: = just YYYY - tmIn.tm_year=ato_year(year); - tmIn.tm_mon=month?atoi(month)-1:0; - tmIn.tm_mday=mday?atoi(mday):1; + tmIn.tm_year=to_tm_year(pa_atoi(year)); + tmIn.tm_mon=month?pa_atoi(month)-1:0; + tmIn.tm_mday=mday?pa_atoi(mday):1; date_part_set: - tmIn.tm_hour=hour?atoi(hour):0; - tmIn.tm_min=min?atoi(min):0; - tmIn.tm_sec=sec?atoi(sec):0; + tmIn.tm_hour=hour?pa_atoi(hour):0; + tmIn.tm_min=min?pa_atoi(min):0; + tmIn.tm_sec=sec?pa_atoi(sec):0; time_t result=mktime(&tmIn); if(result<0) if(fail_on_error) @@ -150,7 +141,7 @@ static void _create(Request& r, MethodPa } else if(params.count()>=2) { // ^create(y;m;d[;h[;m[;s]]]) tm tmIn; memset(&tmIn, 0, sizeof(tmIn)); tmIn.tm_isdst=-1; - tmIn.tm_year=check_year(params.as_int(0, "year must be int", r)); + tmIn.tm_year=to_tm_year(params.as_int(0, "year must be int", r)); tmIn.tm_mon=params.as_int(1, "month must be int", r)-1; tmIn.tm_mday=params.count()>2?params.as_int(2, "mday must be int", r):1; if(params.count()>3) tmIn.tm_hour=params.as_int(3, "hour must be int", r); @@ -242,7 +233,7 @@ static void _roll(Request& r, MethodPara tmOut->tm_isdst=-1; { time_t t_changed_time=mktime/*normalizetime*/(tmOut); - /*autofix: in msk timezone last sunday of april hour hole: [2am->3am) + /*autofix: in msk timezone last sunday of march hour hole: [2am->3am) if( tmOut->tm_hour!=tmSaved.tm_hour ||tmOut->tm_min!=tmSaved.tm_min)