Diff for /parser3/src/classes/date.C between versions 1.65 and 1.71

version 1.65, 2004/02/19 15:38:00 version 1.71, 2005/08/09 08:14:47
Line 1 Line 1
 /** @file  /** @file
         Parser: @b date parser class.          Parser: @b date parser class.
   
         Copyright (c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 19  static const char * const IDENT_DATE_C=" Line 19  static const char * const IDENT_DATE_C="
   
 class MDate: public Methoded {  class MDate: public Methoded {
 public: // VStateless_class  public: // VStateless_class
         Value* create_new_value(Pool&) { return new VDate(0); }          Value* create_new_value(Pool&, HashStringValue&) { return new VDate(0); }
   
 public:  public:
         MDate();          MDate();
Line 79  static int to_tm_year(int iyear) { Line 79  static int to_tm_year(int iyear) {
                         "empty string is not valid datetime");                          "empty string is not valid datetime");
   
         char *cur=cstr;          char *cur=cstr;
         int date_delim=isdigit(cur[0])&&isdigit(cur[1])&&isdigit(cur[2])&&isdigit(cur[3])&&cur[4]==':'?':'          int date_delim=isdigit((unsigned char)cur[0])&&isdigit((unsigned char)cur[1])&&isdigit((unsigned char)cur[2])&&isdigit((unsigned char)cur[3])&&cur[4]==':'?':'
                 :'-';                  :'-';
         const char* year=lsplit(&cur, date_delim);          const char* year=lsplit(&cur, date_delim);
         const char* month=lsplit(&cur, date_delim);          const char* month=lsplit(&cur, date_delim);
Line 88  static int to_tm_year(int iyear) { Line 88  static int to_tm_year(int iyear) {
                 cur=cstr;                  cur=cstr;
         const char* hour=lsplit(&cur, ':');          const char* hour=lsplit(&cur, ':');
         const char* min=lsplit(&cur, ':');          const char* min=lsplit(&cur, ':');
         const char* sec=cur;          const char* sec=lsplit(&cur, '.');
           const char* msec=cur;
   
         tm tmIn;  memset(&tmIn, 0, sizeof(tmIn));          tm tmIn;  memset(&tmIn, 0, sizeof(tmIn));
         tmIn.tm_isdst=-1;          tmIn.tm_isdst=-1;
Line 102  static int to_tm_year(int iyear) { Line 103  static int to_tm_year(int iyear) {
                         tmIn.tm_mday=tmNow->tm_mday;                          tmIn.tm_mday=tmNow->tm_mday;
                         goto date_part_set;                          goto date_part_set;
                 } else                  } else
                         hour=min=sec=0; // not YYYY- & not HH: = just YYYY                                                                hour=min=sec=msec=0; // not YYYY- & not HH: = just YYYY                                 
         tmIn.tm_year=to_tm_year(pa_atoi(year));          tmIn.tm_year=to_tm_year(pa_atoi(year));
         tmIn.tm_mon=month?pa_atoi(month)-1:0;          tmIn.tm_mon=month?pa_atoi(month)-1:0;
         tmIn.tm_mday=mday?pa_atoi(mday):1;          tmIn.tm_mday=mday?pa_atoi(mday):1;
Line 110  date_part_set: Line 111  date_part_set:
         tmIn.tm_hour=hour?pa_atoi(hour):0;          tmIn.tm_hour=hour?pa_atoi(hour):0;
         tmIn.tm_min=min?pa_atoi(min):0;          tmIn.tm_min=min?pa_atoi(min):0;
         tmIn.tm_sec=sec?pa_atoi(sec):0;           tmIn.tm_sec=sec?pa_atoi(sec):0; 
           //tmIn.tm_[msec<<no such, waits reimplementation of the class]=f(msec);
         return tmIn;          return tmIn;
 }  }
   
 static void _create(Request& r, MethodParams& params) {  static void _create(Request& r, MethodParams& params) {
         VDate& vdate=GET_SELF(r, VDate);          VDate& vdate=GET_SELF(r, VDate);
   
         tm tmIn;  
         if(params.count()==1) {           if(params.count()==1) { 
                 // ^create[2002-04-25 18:14:00]                  // ^create[2002-04-25 18:14:00]
                 // ^create[18:14:00]                  // ^create[18:14:00]
Line 151  static void _sql_string(Request& r, Meth Line 152  static void _sql_string(Request& r, Meth
         VDate& vdate=GET_SELF(r, VDate);          VDate& vdate=GET_SELF(r, VDate);
         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=new(PointerFreeGC) char[size];          char *buf=new(PointerFreeGC) char[size];
         time_t time=vdate.get_time();          size=strftime(buf, size, "%Y-%m-%d %H:%M:%S", vdate.get_localtime());
         size=strftime(buf, size, "%Y-%m-%d %H:%M:%S", localtime(&time));  
                   
         r.write_assign_lang(String(buf, size));          r.write_assign_lang(String(buf, size));
 }  }

Removed from v.1.65  
changed lines
  Added in v.1.71


E-mail: