|
|
| version 1.97, 2015/09/22 13:53:04 | version 1.100, 2016/03/27 20:53:43 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b date parser class. | Parser: @b date parser class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2015 Art. Lebedev Studio (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 50 Table date_calendar_table_template(new D | Line 50 Table date_calendar_table_template(new D |
| static void _now(Request& r, MethodParams& params) { | static void _now(Request& r, MethodParams& params) { |
| VDate& vdate=GET_SELF(r, VDate); | VDate& vdate=GET_SELF(r, VDate); |
| time_t t=time(0); | pa_time_t t=(pa_time_t)time(0); |
| if(params.count()==1) // ^now(offset) | if(params.count()==1) // ^now(offset) |
| t+=(time_t)round(params.as_double(0, "offset must be double", r)*SECS_PER_DAY); | t+=(pa_time_t)round(params.as_double(0, "offset must be double", r)*SECS_PER_DAY); |
| vdate.set_time(t); | vdate.set_time(t); |
| } | } |
| Line 290 static void _gmt_string(Request& r, Meth | Line 290 static void _gmt_string(Request& r, Meth |
| r.write_assign_lang(*vdate.get_gmt_string()); | r.write_assign_lang(*vdate.get_gmt_string()); |
| } | } |
| static void _iso_string(Request& r, MethodParams&) { | static void _iso_string(Request& r, MethodParams& params) { |
| VDate& vdate=GET_SELF(r, VDate); | VDate& vdate=GET_SELF(r, VDate); |
| r.write_assign_lang(*vdate.get_iso_string()); | VDate::iso_string_type format=VDate::iso_string_default; |
| if(params.count()>0) | |
| if(HashStringValue* options=params.as_hash(0)){ | |
| int valid_options=0; | |
| if(Value* vshow_ms=options->get("ms")){ | |
| if(r.process_to_value(*vshow_ms).as_bool()) | |
| format=VDate::iso_string_type(format|VDate::iso_string_ms); | |
| valid_options++; | |
| } | |
| if(Value* vshow_colon=options->get("colon")){ | |
| if(!r.process_to_value(*vshow_colon).as_bool()) | |
| format=VDate::iso_string_type(format|VDate::iso_string_no_colon); | |
| valid_options++; | |
| } | |
| if(Value* vshow_z=options->get("z")){ | |
| if(!r.process_to_value(*vshow_z).as_bool()) | |
| format=VDate::iso_string_type(format|VDate::iso_string_no_z); | |
| valid_options++; | |
| } | |
| if(valid_options != options->count()) | |
| throw Exception(PARSER_RUNTIME, 0, CALLED_WITH_INVALID_OPTION); | |
| } | |
| r.write_assign_lang(*vdate.get_iso_string(format)); | |
| } | } |
| static void _roll(Request& r, MethodParams& params) { | static void _roll(Request& r, MethodParams& params) { |
| Line 519 MDate::MDate(): Methoded("date") { | Line 543 MDate::MDate(): Methoded("date") { |
| // ^date.gmt-string[] | // ^date.gmt-string[] |
| add_native_method("gmt-string", Method::CT_DYNAMIC, _gmt_string, 0, 0); | add_native_method("gmt-string", Method::CT_DYNAMIC, _gmt_string, 0, 0); |
| // ^date.iso-string[] | // ^date.iso-string[$.colon(true) $.z(true) $.ms(false)] |
| add_native_method("iso-string", Method::CT_DYNAMIC, _iso_string, 0, 0); | add_native_method("iso-string", Method::CT_DYNAMIC, _iso_string, 0, 1); |
| // ^date:lastday(year;month) | // ^date:lastday(year;month) |
| // ^date.lastday[] | // ^date.lastday[] |