|
|
| version 1.112, 2020/12/15 17:10:27 | version 1.115, 2023/11/26 16:02:41 |
|---|---|
| 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-2023 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 57 static void _now(Request& r, MethodParam | Line 58 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 525 static void _last_day(Request& r, Method | Line 530 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 553 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 588 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); | |
| } | } |