--- parser3/src/classes/date.C 2002/03/28 14:26:48 1.23 +++ parser3/src/classes/date.C 2002/04/18 10:50:59 1.27 @@ -4,7 +4,7 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - $Id: date.C,v 1.23 2002/03/28 14:26:48 paf Exp $ + $Id: date.C,v 1.27 2002/04/18 10:50:59 paf Exp $ */ #include "classes.h" @@ -13,10 +13,6 @@ #include "pa_vdate.h" #include "pa_vtable.h" -// defines - -#define DATE_CLASS_NAME "date" - // class class MDate : public Methoded { @@ -47,9 +43,13 @@ static void _create(Request& r, const St VDate *vdate=static_cast(r.self); time_t t; - if(params->size()==1) // ^set(float days) + if(params->size()==1) { // ^set(float days) t=(time_t)(params->as_double(0, "float days must be double", r)*SECS_PER_DAY); - else if(params->size()>=3) { // ^set(y;m;d[;h[;m[;s]]]) + if(t<0 || !localtime(&t)) + throw Exception(0, + &method_name, + "invalid datetime"); + } else if(params->size()>=2) { // ^set(y;m;d[;h[;m[;s]]]) tm tmIn={0}; tmIn.tm_isdst=-1; int year=params->as_int(0, "year must be int", r); @@ -59,7 +59,7 @@ static void _create(Request& r, const St year-=1900; tmIn.tm_year=year; tmIn.tm_mon=params->as_int(1, "month must be int", r)-1; - tmIn.tm_mday=params->as_int(2, "mday must be int", r); + tmIn.tm_mday=params->size()>2?params->as_int(2, "mday must be int", r):1; if(params->size()>3) tmIn.tm_hour=params->as_int(3, "hour must be int", r); if(params->size()>4) tmIn.tm_min=params->as_int(4, "minutes must be int", r); if(params->size()>5) tmIn.tm_sec=params->as_int(5, "seconds must be int", r); @@ -71,7 +71,7 @@ static void _create(Request& r, const St } else throw Exception("parser.runtime", &method_name, - "invalid params count, must be 1 or >=3"); + "invalid params count, must be 1 or >=2"); vdate->set_time(t); } @@ -87,8 +87,7 @@ static void _sql_string(Request& r, cons string.APPEND_CLEAN(buf, size, method_name.origin().file, method_name.origin().line); - Value& result=*new(pool) VString(string); - r.write_assign_lang(result); + r.write_assign_lang(string); } @@ -126,6 +125,10 @@ static void _roll(Request& r, const Stri throw Exception(0, &method_name, "bad resulting time (after roll)"); + if(oday==0 && tmIn.tm_mday!=tmSaved.tm_mday) + throw Exception(0, + &method_name, + "bad resulting time (day hole)", t); tm *tmOut=localtime(&t); if(!tmOut) @@ -144,7 +147,7 @@ static void _roll(Request& r, const Stri ||tmOut->tm_min!=tmSaved.tm_min) throw Exception(0, &method_name, - "bad resulting time (timeline hole)"); + "bad resulting time (hour hole)"); if(t<0) throw Exception(0, @@ -263,16 +266,12 @@ static void _calendar(Request& r, const table=fill_week_days(r, method_name, params, rus); VTable& result=*new(pool) VTable(pool, table); - result.set_name(method_name); r.write_no_lang(result); } // constructor -MDate::MDate(Pool& apool) : Methoded(apool) { - set_name(*NEW String(pool(), DATE_CLASS_NAME)); - - +MDate::MDate(Pool& apool) : Methoded(apool, "date") { // ^now[] add_native_method("now", Method::CT_DYNAMIC, _now, 0, 1);