|
|
| version 1.2, 2001/07/07 17:59:02 | version 1.9, 2001/10/08 16:42:06 |
|---|---|
| Line 2 | Line 2 |
| Parser: @b date parser class. | Parser: @b date parser class. |
| Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) | Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) |
| $Id$ | $Id$ |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| #include "classes.h" | #include "classes.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| Line 44 static void _set(Request& r, const Strin | Line 42 static void _set(Request& r, const Strin |
| time_t time; | time_t time; |
| if(params->size()==1) // ^set(float days) | if(params->size()==1) // ^set(float days) |
| time=(time_t)(params->as_double(0, r)*SECS_PER_DAY); | time=(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]]]) | else if(params->size()>=3) { // ^set(y;m;d[;h[;m[;s]]]) |
| tm tmIn={0}; | tm tmIn={0}; |
| tmIn.tm_isdst=-1; | tmIn.tm_isdst=-1; |
| int year=params->as_int(0, r); | int year=params->as_int(0, "year must be int", r); |
| if(year<70) // 0..69 -> 100..169 [2000..2069] | if(year<70) // 0..69 -> 100..169 [2000..2069] |
| year+=100; | year+=100; |
| if(year>=1900) | |
| year-=1900; | |
| tmIn.tm_year=year; | tmIn.tm_year=year; |
| tmIn.tm_mon=params->as_int(1, r)-1; | tmIn.tm_mon=params->as_int(1, "month must be int", r)-1; |
| tmIn.tm_mday=params->as_int(2, r); | tmIn.tm_mday=params->as_int(2, "mday must be int", r); |
| if(params->size()>3) tmIn.tm_hour=params->as_int(3, r); | 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, 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, r); | if(params->size()>5) tmIn.tm_sec=params->as_int(5, "seconds must be int", r); |
| time=mktime(&tmIn); | time=mktime(&tmIn); |
| if(time<0) | if(time<0) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| Line 69 static void _set(Request& r, const Strin | Line 69 static void _set(Request& r, const Strin |
| vdate->set_time(time); | 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(); | Pool& pool=r.pool(); |
| VDate *vdate=static_cast<VDate *>(r.self); | VDate *vdate=static_cast<VDate *>(r.self); |
| int size=1+ 4+1+2+1+2 +1+ 2+1+2+1+2 +1 +1; | int size=1+ 4+1+2+1+2 +1+ 2+1+2+1+2 +1 +1; |
| char *buf=(char *)pool.malloc(size); | char *buf=(char *)pool.malloc(size); |
| time_t time=vdate->get_time(); | time_t time=vdate->get_time(); |
| size=strftime(buf, size, "'%Y-%m-%d %H:%M:%S'", gmtime(&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); | r.write_assign_lang(result); |
| } | } |
| Line 99 static void _roll(Request& r, const Stri | Line 103 static void _roll(Request& r, const Stri |
| &what, | &what, |
| "must be year|month|day"); | "must be year|month|day"); |
| *offset=params->as_int(1, r); | *offset=params->as_int(1, "offset must be int", r); |
| if(!(*offset==1 || *offset==-1)) | if(!(*offset==1 || *offset==-1)) |
| PTHROW(0, 0, | PTHROW(0, 0, |
| &method_name, | &method_name, |
| Line 130 MDate::MDate(Pool& apool) : Methoded(apo | Line 134 MDate::MDate(Pool& apool) : Methoded(apo |
| // ^set(float days) | // ^set(float days) |
| add_native_method("set", Method::CT_DYNAMIC, _set, 1, 6); | add_native_method("set", Method::CT_DYNAMIC, _set, 1, 6); |
| // ^string[] | // ^sql-string[] |
| add_native_method("string", Method::CT_DYNAMIC, _string, 0, 0); | add_native_method("sql-string", Method::CT_DYNAMIC, _sql_string, 0, 0); |
| // ^roll(year|month|day;+/- 1) | // ^roll(year|month|day;+/- 1) |
| add_native_method("roll", Method::CT_DYNAMIC, _roll, 2, 2); | add_native_method("roll", Method::CT_DYNAMIC, _roll, 2, 2); |