Diff for /parser3/src/classes/date.C between versions 1.112 and 1.121

version 1.112, 2020/12/15 17:10:27 version 1.121, 2024/12/23 16:59:17
Line 1 Line 1
 /** @file  /** @file
         Parser: @b date parser class.          Parser: @b date parser class.
   
         Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #include "classes.h"  #include "classes.h"
Line 12 Line 12
 #include "pa_vdouble.h"  #include "pa_vdouble.h"
 #include "pa_vdate.h"  #include "pa_vdate.h"
 #include "pa_vtable.h"  #include "pa_vtable.h"
   #include "pa_vbool.h"
   
 volatile const char * IDENT_DATE_C="$Id$" IDENT_PA_VDATE_H;  volatile const char * IDENT_DATE_C="$Id$" IDENT_PA_VDATE_H;
   
Line 42  public: Line 43  public:
         }          }
 };  };
   
   static Table &date_calendar_table_template(){
 Table date_calendar_table_template(new Date_calendar_table_template_columns);          static Table *singleton=NULL;
           if(!singleton)
                   singleton=new Table(new Date_calendar_table_template_columns);
           return *singleton;
   }
   
 // methods  // methods
   
Line 57  static void _now(Request& r, MethodParam Line 62  static void _now(Request& r, MethodParam
         vdate.set_time(t);          vdate.set_time(t);
 }  }
   
 static void _today(Request& r, MethodParams&) {  static void _today(Request& r, MethodParams& params) {
         VDate& vdate=GET_SELF(r, VDate);          VDate& vdate=GET_SELF(r, VDate);
   
         time_t t=time(0);          time_t t=time(0);
   
         tm today=*localtime(&t);          tm today=*localtime(&t);
   
           if (params.count() == 1) // ^today(offset)
                   today.tm_mday += params.as_int(0, "offset must be int", r);
   
         today.tm_hour=0;          today.tm_hour=0;
         today.tm_min=0;          today.tm_min=0;
         today.tm_sec=0;          today.tm_sec=0;
Line 188  tm cstr_to_time_t(char *cstr, const char Line 197  tm cstr_to_time_t(char *cstr, const char
         char *cur=cstr;          char *cur=cstr;
   
         const char *year, *month, *mday;          const char *year, *month, *mday;
         const char *hour, *min, *sec, *msec PA_ATTR_UNUSED;          const char *hour, *min, *sec;
           PA_UNUSED const char *msec;
   
         year=skip_number(&cur, "-:", &delim);          year=skip_number(&cur, "-:", &delim);
         if(delim != ':' || delim == ':' && strlen(year) >=4 ){          if(delim != ':' || delim == ':' && strlen(year) >=4 ){
Line 254  static void _create(Request& r, MethodPa Line 264  static void _create(Request& r, MethodPa
                                 vdate.set_tz(tz);                                  vdate.set_tz(tz);
                         vdate.set_tm(tmIn);                          vdate.set_tm(tmIn);
                 } else { // ^create(float days) or ^create[date object]                  } else { // ^create(float days) or ^create[date object]
                         if(Value* adate=params[0].as(VDATE_TYPE))                          if(VDate* adate=dynamic_cast<VDate*>(&params[0]))
                                 vdate.set_tz(static_cast<VDate*>(adate)->get_tz());                                  vdate.set_tz(adate->get_tz());
                         vdate.set_time(round(params.as_double(0, "float days must be double", r)*SECS_PER_DAY));                          vdate.set_time(round(params.as_double(0, "float days must be double", r)*SECS_PER_DAY));
                 }                  }
         } else { // ^create(y;m;d[;h[;m[;s[;TZ]]]])          } else { // ^create(y;m;d[;h[;m[;s[;TZ]]]])
Line 389  static void _roll(Request& r, MethodPara Line 399  static void _roll(Request& r, MethodPara
   
 static Table& fill_month_days(Request& r, MethodParams& params, bool rus){  static Table& fill_month_days(Request& r, MethodParams& params, bool rus){
         Table::Action_options table_options;          Table::Action_options table_options;
         Table& result=*new Table(date_calendar_table_template, table_options);          Table& result=*new Table(date_calendar_table_template(), table_options);
                   
         tm tmIn;          tm tmIn;
         memset(&tmIn, 0, sizeof(tmIn));          memset(&tmIn, 0, sizeof(tmIn));
Line 525  static void _last_day(Request& r, Method Line 535  static void _last_day(Request& r, Method
         r.write(*new VInt(VDate::getMonthDays(tmIn.tm_year, tmIn.tm_mon)));          r.write(*new VInt(VDate::getMonthDays(tmIn.tm_year, tmIn.tm_mon)));
 }  }
   
   static void _int(Request& r, MethodParams&) {
           VDate& vdate=GET_SELF(r, VDate);
           r.write(*new VInt(vdate.as_int()));
   }
   
   static void _double(Request& r, MethodParams&) {
           VDate& vdate=GET_SELF(r, VDate);
           r.write(*new VDouble(vdate.as_double()));
   }
   
   static void _bool(Request& r, MethodParams&) {
           VDate& vdate=GET_SELF(r, VDate);
           r.write(VBool::get(vdate.as_bool()));
   }
   
 // constructor  // constructor
   
 MDate::MDate(): Methoded("date") {  MDate::MDate(): Methoded("date") {
Line 533  MDate::MDate(): Methoded("date") { Line 558  MDate::MDate(): Methoded("date") {
         add_native_method("now", Method::CT_DYNAMIC, _now, 0, 1);          add_native_method("now", Method::CT_DYNAMIC, _now, 0, 1);
   
         // ^date::today[]          // ^date::today[]
         add_native_method("today", Method::CT_DYNAMIC, _today, 0, 0);          // ^date::today(offset int days)
           add_native_method("today", Method::CT_DYNAMIC, _today, 0, 1);
   
         // ^date::create(float days)          // ^date::create(float days)
         // ^date::create[date]          // ^date::create[date]
Line 567  MDate::MDate(): Methoded("date") { Line 593  MDate::MDate(): Methoded("date") {
         // ^date.unix-timestamp[]          // ^date.unix-timestamp[]
         // ^date::unix-timestamp(timestamp)          // ^date::unix-timestamp(timestamp)
         add_native_method("unix-timestamp", Method::CT_DYNAMIC, _unix_timestamp, 0, 1);          add_native_method("unix-timestamp", Method::CT_DYNAMIC, _unix_timestamp, 0, 1);
   
           // date.int[default for ^string.int compatibility]
           add_native_method("int", Method::CT_DYNAMIC, _int, 0, 1);
   
           // ^date.double[default for ^string.double compatibility]
           add_native_method("double", Method::CT_DYNAMIC, _double, 0, 1);
   
           // ^date.bool[default for ^string.bool compatibility]
           add_native_method("bool", Method::CT_DYNAMIC, _bool, 0, 1);
 }  }

Removed from v.1.112  
changed lines
  Added in v.1.121


E-mail: