diff options
Diffstat (limited to 'src/sh/dates.cc')
| -rw-r--r-- | src/sh/dates.cc | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/sh/dates.cc b/src/sh/dates.cc new file mode 100644 index 0000000..a37103b --- /dev/null +++ b/src/sh/dates.cc | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <sh/htc.h> | ||
| 21 | #include <mt/dates.h> | ||
| 22 | #include <limits.h> | ||
| 23 | |||
| 24 | const int ENDTIME=INT_MAX-4*SEC_PER_DAY; | ||
| 25 | |||
| 26 | TOK_IMPL(endtime) { out<<ENDTIME; } | ||
| 27 | TOK_IMPL(now) { out<<Now(); } | ||
| 28 | TOK_IMPL(minutes) { out<<(60*atoi(env[0])); } | ||
| 29 | TOK_IMPL(days) { out<<Days(atoi(env[0])); } | ||
| 30 | TOK_IMPL(today) { out<<Today(atoi(env[0])); } | ||
| 31 | TOK_IMPL(sunday) { out<<Sunday(atoi(env[0])); } | ||
| 32 | TOK_IMPL(week) { out<<Week(env.req->lang,atoi(env[0])); } | ||
| 33 | TOK_IMPL(month) { out<<Month(env.req->lang,atoi(env[0])); } | ||
| 34 | TOK_IMPL(sweek) { out<<SWeek(env.req->lang,atoi(env[0])); } | ||
| 35 | TOK_IMPL(smonth) { out<<SMonth(env.req->lang,atoi(env[0])); } | ||
| 36 | |||
| 37 | //////////////////////////////////////////////////////////// | ||
| 38 | |||
| 39 | TOK_IMPL(time2http) { out<<httpTime(atoi(env[0])); } | ||
| 40 | TOK_IMPL(time2htc) { out<<htcTime(env.req->lang,atoi(env[0])); } | ||
| 41 | TOK_IMPL(htc2time) { out<<htcTime(env.req->lang,env[0]); } | ||
| 42 | TOK_IMPL(cvttime) { out<<cvtTime(env[0]); } | ||
| 43 | |||
| 44 | //////////////////////////////////////////////////////////// | ||
| 45 | |||
| 46 | void envAddDates(tokmap& T) | ||
| 47 | { | ||
| 48 | TOK_ADD(endtime,"",tok_t::PUBLIC, | ||
| 49 | "%Endtime\n" | ||
| 50 | "%Syntax: \\endtime\n" | ||
| 51 | "%\n" | ||
| 52 | "%Last time (safely) representable by internal format\n" | ||
| 53 | ); | ||
| 54 | TOK_ADD(now,"",tok_t::PUBLIC, | ||
| 55 | "%Now\n" | ||
| 56 | "%Syntax: \\now\n" | ||
| 57 | "%\n" | ||
| 58 | "%Current system time. Note that this may be out of\n" | ||
| 59 | "%sync with filesystem.\n" | ||
| 60 | ); | ||
| 61 | TOK_ADD(minutes,"x",tok_t::PUBLIC, | ||
| 62 | "%Minutes in seconds\n" | ||
| 63 | "%Syntax: \\minutes{m}\n" | ||
| 64 | ); | ||
| 65 | TOK_ADD(days,"x",tok_t::PUBLIC, | ||
| 66 | "%Days in seconds\n" | ||
| 67 | "%Syntax: \\days{d}\n" | ||
| 68 | ); | ||
| 69 | TOK_ADD(today,"x",tok_t::PUBLIC, | ||
| 70 | "%Beginning of day\n" | ||
| 71 | "%Syntax: \\today{t}\n" | ||
| 72 | "%\n" | ||
| 73 | "%Get beginning of day.\n" | ||
| 74 | ); | ||
| 75 | TOK_ADD(sunday,"x",tok_t::PUBLIC, | ||
| 76 | "%Last sunday\n" | ||
| 77 | "%Syntax: \\sunday{t}\n" | ||
| 78 | "%\n" | ||
| 79 | "%Get beginning of last sunday.\n" | ||
| 80 | ); | ||
| 81 | TOK_ADD(week,"x",tok_t::PUBLIC, | ||
| 82 | "%Weekday (long)\n" | ||
| 83 | "%Syntax: \\week{t}\n" | ||
| 84 | "%\n" | ||
| 85 | "%Get long weekday format.\n" | ||
| 86 | "%Output in current language.\n" | ||
| 87 | ); | ||
| 88 | TOK_ADD(month,"x",tok_t::PUBLIC, | ||
| 89 | "%Month (long)\n" | ||
| 90 | "%Syntax: \\month{t}\n" | ||
| 91 | "%\n" | ||
| 92 | "%Get long month format.\n" | ||
| 93 | "%Output in current language.\n" | ||
| 94 | ); | ||
| 95 | TOK_ADD(sweek,"x",tok_t::PUBLIC, | ||
| 96 | "%Weekday (short)\n" | ||
| 97 | "%Syntax: \\sweek{t}\n" | ||
| 98 | "%\n" | ||
| 99 | "%Get short weekday format.\n" | ||
| 100 | "%Output in current language.\n" | ||
| 101 | ); | ||
| 102 | TOK_ADD(smonth,"x",tok_t::PUBLIC, | ||
| 103 | "%Month (short)\n" | ||
| 104 | "%Syntax: \\smonth{t}\n" | ||
| 105 | "%\n" | ||
| 106 | "%Get short month format.\n" | ||
| 107 | "%Output in current language.\n" | ||
| 108 | ); | ||
| 109 | |||
| 110 | ////////////////////////////////////////////////////// | ||
| 111 | |||
| 112 | TOK_ADD(time2http,"x",tok_t::PUBLIC, | ||
| 113 | "%HTTP Standard Time (GMT)\n" | ||
| 114 | "%Syntax: \\time2http{t}\n" | ||
| 115 | "%\n" | ||
| 116 | "%Outputs time in standard HTTP format.\n" | ||
| 117 | ); | ||
| 118 | TOK_ADD(time2htc,"x",tok_t::PUBLIC, | ||
| 119 | "%HTC Standard Time (Local)\n" | ||
| 120 | "%Syntax: \\time2htc{t}\n" | ||
| 121 | "%\n" | ||
| 122 | "%Outputs time in standard HTC format, which is local time.\n" | ||
| 123 | "%Output in current language.\n" | ||
| 124 | ); | ||
| 125 | TOK_ADD(htc2time,"x",tok_t::PUBLIC, | ||
| 126 | "%Convert to time from HTC (Local)\n" | ||
| 127 | "%Syntax: \\htc2time{timestring}\n" | ||
| 128 | "%\n" | ||
| 129 | "%Converts text to local time internal format.\n" | ||
| 130 | ); | ||
| 131 | TOK_ADD(cvttime,"x",tok_t::PUBLIC, | ||
| 132 | "%Convert user input time (Local)\n" | ||
| 133 | "%Syntax: \\cvttime{timestring}\n" | ||
| 134 | "%\n" | ||
| 135 | "%Tries to make an intelligent conversion of user input\n" | ||
| 136 | "%under the assumption that a local time is given.\n" | ||
| 137 | ); | ||
| 138 | } | ||
