Commit 2dbceb9f authored by Philip Gladstone's avatar Philip Gladstone

Change the way that the ?date= stuff is parsed. It now takes a time (with optional date)

in local time rather than GMT. Note that you are advised to use the date as well as the time
as the time is relative to the current day (which is not much use if the time is in the
future). The date format parsing is pretty strict still:
YYYY-MM-DDTHH:MM:SS   is a format that works. The T is a literal non-digit character. I wouldn't
use a space. The :SS can be omitted. The number of digits *must* be four in the Year.

Originally committed as revision 691 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4fd60448
...@@ -880,55 +880,45 @@ INT64 parse_date(const char *datestr, int duration) ...@@ -880,55 +880,45 @@ INT64 parse_date(const char *datestr, int duration)
{ {
const char *p; const char *p;
INT64 t; INT64 t;
int sec; struct tm dt;
memset(&dt, 0, sizeof(dt));
p = datestr; p = datestr;
if (!duration) { if (!duration) {
static const UINT8 months[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year, month, day, i;
if (strlen(p) >= 5 && p[4] == '-') { if (strlen(p) >= 5 && p[4] == '-') {
dt.tm_year = strtol(p, (char **)&p, 10);
year = strtol(p, (char **)&p, 10);
if (*p) if (*p)
p++; p++;
month = strtol(p, (char **)&p, 10) - 1; dt.tm_mon = strtol(p, (char **)&p, 10) - 1;
if (*p) if (*p)
p++; p++;
day = strtol(p, (char **)&p, 10) - 1; dt.tm_mday = strtol(p, (char **)&p, 10) - 1;
if (*p) if (*p)
p++; p++;
day += (year - 1970) * 365;
/* if >= March, take February of current year into account too */
if (month >= 2)
year++;
for(i=1970;i<year;i++) {
if ((i % 100) == 0) {
if ((i % 400) == 0) day++;
} else if ((i % 4) == 0) {
day++;
}
}
for(i=0;i<month;i++)
day += months[i];
} else { } else {
day = (time(NULL) / (3600 * 24)); time_t now = time(0);
dt = *localtime(&now);
dt.tm_hour = 0;
dt.tm_min = 0;
dt.tm_sec = 0;
} }
t = day * (3600 * 24);
} else {
t = 0;
} }
sec = 0; dt.tm_hour = strtol(p, (char **)&p, 10);
for(;;) { if (*p)
int val;
val = strtol(p, (char **)&p, 10);
sec = sec * 60 + val;
if (*p != ':')
break;
p++; p++;
dt.tm_min = strtol(p, (char **)&p, 10);
if (*p)
p++;
dt.tm_sec = strtol(p, (char **)&p, 10);
if (duration) {
t = (INT64) 1000000 * (dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec);
} else {
t = (INT64) 1000000 * mktime(&dt);
} }
t = (t + sec) * 1000000;
if (*p == '.') { if (*p == '.') {
int val, n; int val, n;
p++; p++;
...@@ -945,7 +935,7 @@ INT64 parse_date(const char *datestr, int duration) ...@@ -945,7 +935,7 @@ INT64 parse_date(const char *datestr, int duration)
return t; return t;
} }
/* syntax: '?tag1=val1&tag2=val2...'. No URL decoding is done. Return /* syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. Return
1 if found */ 1 if found */
int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
{ {
...@@ -967,8 +957,12 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) ...@@ -967,8 +957,12 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
if (*p == '=') { if (*p == '=') {
p++; p++;
while (*p != '&' && *p != '\0') { while (*p != '&' && *p != '\0') {
if ((q - arg) < arg_size - 1) if ((q - arg) < arg_size - 1) {
if (*p == '+')
*q++ = ' ';
else
*q++ = *p; *q++ = *p;
}
p++; p++;
} }
*q = '\0'; *q = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment