--- parser3/src/classes/date.C 2023/11/26 16:02:41 1.115 +++ parser3/src/classes/date.C 2025/10/04 00:22:18 1.122 @@ -1,7 +1,7 @@ /** @file Parser: @b date parser class. - Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ @@ -14,7 +14,7 @@ #include "pa_vtable.h" #include "pa_vbool.h" -volatile const char * IDENT_DATE_C="$Id: date.C,v 1.115 2023/11/26 16:02:41 moko Exp $" IDENT_PA_VDATE_H; +volatile const char * IDENT_DATE_C="$Id: date.C,v 1.122 2025/10/04 00:22:18 moko Exp $" IDENT_PA_VDATE_H; // class @@ -43,8 +43,12 @@ public: } }; - -Table date_calendar_table_template(new Date_calendar_table_template_columns); +static Table &date_calendar_table_template(){ + static Table *singleton=NULL; + if(!singleton) + singleton=new Table(new Date_calendar_table_template_columns); + return *singleton; +} // methods @@ -193,7 +197,8 @@ tm cstr_to_time_t(char *cstr, const char char *cur=cstr; 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); if(delim != ':' || delim == ':' && strlen(year) >=4 ){ @@ -259,8 +264,8 @@ static void _create(Request& r, MethodPa vdate.set_tz(tz); vdate.set_tm(tmIn); } else { // ^create(float days) or ^create[date object] - if(Value* adate=params[0].as(VDATE_TYPE)) - vdate.set_tz(static_cast(adate)->get_tz()); + if(VDate* adate=dynamic_cast(¶ms[0])) + vdate.set_tz(adate->get_tz()); 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]]]]) @@ -278,7 +283,8 @@ static void _create(Request& r, MethodPa } static void _sql_string(Request& r, MethodParams& params) { - VDate& vdate=GET_SELF(r, VDate); + bool dynamic=&r.get_self() != date_class; + VDate& vdate=dynamic ? GET_SELF(r, VDate) : *new VDate((pa_time_t)time(0)); VDate::sql_string_type format = VDate::sql_string_datetime; if(params.count() > 0) { @@ -297,13 +303,15 @@ static void _sql_string(Request& r, Meth } static void _gmt_string(Request& r, MethodParams&) { - VDate& vdate=GET_SELF(r, VDate); + bool dynamic=&r.get_self() != date_class; + VDate& vdate=dynamic ? GET_SELF(r, VDate) : *new VDate((pa_time_t)time(0)); r.write(*vdate.get_gmt_string()); } static void _iso_string(Request& r, MethodParams& params) { - VDate& vdate=GET_SELF(r, VDate); + bool dynamic=&r.get_self() != date_class; + VDate& vdate=dynamic ? GET_SELF(r, VDate) : *new VDate((pa_time_t)time(0)); VDate::iso_string_type format=VDate::iso_string_default; @@ -394,7 +402,7 @@ static void _roll(Request& r, MethodPara static Table& fill_month_days(Request& r, MethodParams& params, bool rus){ 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; memset(&tmIn, 0, sizeof(tmIn)); @@ -566,13 +574,16 @@ MDate::MDate(): Methoded("date") { add_native_method("set", Method::CT_DYNAMIC, _create, 1, 7); // ^date.sql-string[] - add_native_method("sql-string", Method::CT_DYNAMIC, _sql_string, 0, 1); + // ^date:sql-string[] + add_native_method("sql-string", Method::CT_ANY, _sql_string, 0, 1); // ^date.gmt-string[] - add_native_method("gmt-string", Method::CT_DYNAMIC, _gmt_string, 0, 0); + // ^date:gmt-string[] + add_native_method("gmt-string", Method::CT_ANY, _gmt_string, 0, 0); // ^date.iso-string[$.colon(true) $.z(true) $.ms(false)] - add_native_method("iso-string", Method::CT_DYNAMIC, _iso_string, 0, 1); + // ^date:iso-string[...] + add_native_method("iso-string", Method::CT_ANY, _iso_string, 0, 1); // ^date:lastday(year;month) // ^date.lastday[]