--- parser3/src/classes/date.C 2001/07/07 16:38:01 1.1 +++ parser3/src/classes/date.C 2001/09/21 14:46:09 1.7 @@ -4,10 +4,8 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: date.C,v 1.1 2001/07/07 16:38:01 parser Exp $ */ -static const char *RCSId="$Id: date.C,v 1.1 2001/07/07 16:38:01 parser Exp $"; +static const char *RCSId="$Id: date.C,v 1.7 2001/09/21 14:46:09 parser Exp $"; #include "classes.h" #include "pa_request.h" @@ -51,6 +49,8 @@ static void _set(Request& r, const Strin int year=params->as_int(0, r); if(year<70) // 0..69 -> 100..169 [2000..2069] year+=100; + if(year>=1900) + year-=1900; tmIn.tm_year=year; tmIn.tm_mon=params->as_int(1, r)-1; tmIn.tm_mday=params->as_int(2, r); @@ -69,43 +69,23 @@ static void _set(Request& r, const Strin vdate->set_time(time); } -static void _string(Request& r, const String& method_name, MethodParams *) { +static void _sql_string(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); VDate *vdate=static_cast(r.self); - int size=4+1+2+1+2 +1+ 2+1+2+1+2 +1; + int size=1+ 4+1+2+1+2 +1+ 2+1+2+1+2 +1 +1; char *buf=(char *)pool.malloc(size); time_t time=vdate->get_time(); size=strftime(buf, size, "%Y-%m-%d %H:%M:%S", gmtime(&time)); - Value& result=*new(pool) VString(*new(pool) String(pool, buf, size)); + String& string=*new(pool) String(pool); + string.APPEND_CLEAN(buf, size, + method_name.origin().file, + method_name.origin().line); + Value& result=*new(pool) VString(string); r.write_assign_lang(result); } -static int isLeap(int year) { - return !( - (year % 4) || ((year % 400) && !(year % 100)) - ); -} - -static int getMonthDays(int year, int month) { - int monthDays[]={ - 31, - isLeap(year) ? 29 : 28, - 31, - 30, - 31, - 30, - 31, - 31, - 30, - 31, - 30, - 31 - }; - return monthDays[month]; -} - static void _roll(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); VDate *vdate=static_cast(r.self); @@ -154,8 +134,8 @@ MDate::MDate(Pool& apool) : Methoded(apo // ^set(float days) add_native_method("set", Method::CT_DYNAMIC, _set, 1, 6); - // ^string[] - add_native_method("string", Method::CT_DYNAMIC, _string, 0, 0); + // ^sql-string[] + add_native_method("sql-string", Method::CT_DYNAMIC, _sql_string, 0, 0); // ^roll(year|month|day;+/- 1) add_native_method("roll", Method::CT_DYNAMIC, _roll, 2, 2);