|
|
| version 1.76, 2007/03/22 13:38:25 | version 1.78, 2008/02/14 10:11:16 |
|---|---|
| Line 61 static void _now(Request& r, MethodParam | Line 61 static void _now(Request& r, MethodParam |
| } | } |
| /// shrinked range: 1970/1/1 to 2038/1/1 | /// shrinked range: 1970/1/1 to 2038/1/1 |
| static int to_tm_year(int iyear) { | static int to_year(int iyear) { |
| if(iyear<1970 || iyear>2038) | if(iyear<1970 || iyear>2038) |
| throw Exception(0, | throw Exception(0, |
| 0, | 0, |
| "year '%d' is out of valid range", iyear); | "year '%d' is out of valid range", iyear); |
| return iyear-1900; | return iyear; |
| } | |
| static int to_month(int imonth) { | |
| return max(1, min(imonth, 12)) -1; | |
| } | } |
| static int to_tm_year(int iyear) { | |
| return to_year(iyear)-1900; | |
| } | |
| // 2002-04-25 18:14:00 | // 2002-04-25 18:14:00 |
| // 18:14:00 | // 18:14:00 |
| // 2002:04:25 [+maybe time] | // 2002:04:25 [+maybe time] |
| Line 171 static void _roll(Request& r, MethodPara | Line 180 static void _roll(Request& r, MethodPara |
| vdate.set_tz(&argument_tz); | vdate.set_tz(&argument_tz); |
| return; | return; |
| } else | } else |
| throw Exception("parser.runtime", | throw Exception(PARSER_RUNTIME, |
| &what, | &what, |
| "must be year|month|day|TZ"); | "must be year|month|day|TZ"); |
| Line 241 static Table& fill_month_days(Request& r | Line 250 static Table& fill_month_days(Request& r |
| 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); |
| int year=params.as_int(1, "year must be int", r); | int year=to_year(params.as_int(1, "year must be int", r)); |
| int month=max(1, min(params.as_int(2, "month must be int", r), 12)) -1; | int month=to_month(params.as_int(2, "month must be int", r)); |
| tm tmIn; | tm tmIn; |
| memset(&tmIn, 0, sizeof(tmIn)); | memset(&tmIn, 0, sizeof(tmIn)); |
| Line 316 static Table& fill_week_days(Request& r, | Line 325 static Table& fill_week_days(Request& r, |
| *columns+=new String("weekday"); | *columns+=new String("weekday"); |
| Table& result=*new Table(columns); | Table& result=*new Table(columns); |
| int year=params.as_int(1, "year must be int", r); | int year=to_year(params.as_int(1, "year must be int", r)); |
| int month=max(1, min(params.as_int(2, "month must be int", r), 12)) -1; | int month=to_month(params.as_int(2, "month must be int", r)); |
| int day=params.as_int(3, "day must be int", r); | int day=params.as_int(3, "day must be int", r); |
| tm tmIn; | tm tmIn; |
| Line 365 static void _calendar(Request& r, Method | Line 374 static void _calendar(Request& r, Method |
| else if(what=="eng") | else if(what=="eng") |
| rus=false; | rus=false; |
| else | else |
| throw Exception("parser.runtime", | throw Exception(PARSER_RUNTIME, |
| &what, | &what, |
| "must be rus|eng"); | "must be rus|eng"); |
| Line 397 static void _unix_timestamp(Request& r, | Line 406 static void _unix_timestamp(Request& r, |
| } | } |
| } | } |
| static void _lastday(Request& r, MethodParams& params) { | |
| int year; | |
| int month; | |
| if(&r.get_self() == date_class) { | |
| // ^date:lastday(year;month) | |
| if(params.count() == 2) { | |
| year=to_year(params.as_int(0, "year must be int", r)); | |
| month=to_month(params.as_int(1, "month must be int", r)); | |
| } else | |
| throw Exception(PARSER_RUNTIME, | |
| 0, | |
| "year and month must be defined"); | |
| } else { | |
| // ^date.lastday[] | |
| tm &tmIn=GET_SELF(r, VDate).get_localtime(); | |
| year=tmIn.tm_year+1900; | |
| month=tmIn.tm_mon; | |
| } | |
| r.write_assign_lang(*new VInt(getMonthDays(year, month))); | |
| } | |
| // constructor | // constructor |
| MDate::MDate(): Methoded("date") { | MDate::MDate(): Methoded("date") { |
| // ^now[] | // ^date::now[] |
| add_native_method("now", Method::CT_DYNAMIC, _now, 0, 1); | add_native_method("now", Method::CT_DYNAMIC, _now, 0, 1); |
| // ^create(float days) | // ^date::create(float days) |
| add_native_method("create", Method::CT_DYNAMIC, _create, 1, 6); | add_native_method("create", Method::CT_DYNAMIC, _create, 1, 6); |
| // old name for compatibility with <= v1.17 2002/2/18 12:13:42 paf | // old name for compatibility with <= v1.17 2002/2/18 12:13:42 paf |
| add_native_method("set", Method::CT_DYNAMIC, _create, 1, 6); | add_native_method("set", Method::CT_DYNAMIC, _create, 1, 6); |
| // ^sql-string[] | // ^date.sql-string[] |
| add_native_method("sql-string", Method::CT_DYNAMIC, _sql_string, 0, 0); | add_native_method("sql-string", Method::CT_DYNAMIC, _sql_string, 0, 0); |
| // ^roll(year|month|day;+/- 1) | // ^date:lastday(year;month) |
| // ^date.lastday[] | |
| add_native_method("lastday", Method::CT_ANY, _lastday, 0, 2); | |
| // ^date.roll(year|month|day;+/- 1) | |
| add_native_method("roll", Method::CT_DYNAMIC, _roll, 2, 2); | add_native_method("roll", Method::CT_DYNAMIC, _roll, 2, 2); |
| // ^date:calendar[month|montheng;year;month] = table | // ^date:calendar[month|montheng;year;month] = table |
| Line 420 MDate::MDate(): Methoded("date") { | Line 454 MDate::MDate(): Methoded("date") { |
| add_native_method("calendar", Method::CT_STATIC, _calendar, 3, 4); | add_native_method("calendar", Method::CT_STATIC, _calendar, 3, 4); |
| // ^unix-timestamp[] | // ^date.unix-timestamp[] |
| // ^date::unix-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); |
| } | } |