From 48b5100a347dfb5bb48a4d695a44c81e4378d69d Mon Sep 17 00:00:00 2001 From: piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> Date: Sun, 30 Aug 2009 12:47:31 +0000 Subject: * allow setting chess_go results and lastlogin git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4801 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/calendar.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'mbbsd/calendar.c') diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index dad8bc46..a8c63eb3 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -31,28 +31,58 @@ Days(int y, int m, int d) } /** - * return 1 if date is invalid + * return 1 if date and time is invalid */ -int ParseDate(const char *date, int *year, int *month, int *day) +int ParseDateTime(const char *date, int *year, int *month, int *day, + int *hour, int *min, int *sec) { - char *y, *m, *d; + char *y, *m, *d, *hh, *mm, *ss; char buf[128]; char *strtok_pos; strlcpy(buf, date, sizeof(buf)); y = strtok_r(buf, "/", &strtok_pos); if (!y) return 1; m = strtok_r(NULL, "/", &strtok_pos);if (!m) return 1; - d = strtok_r(NULL, "", &strtok_pos); if (!d) return 1; + d = strtok_r(NULL, " ", &strtok_pos); if (!d) return 1; + + if (hour) { + hh = strtok_r(NULL, ":", &strtok_pos); + if (!hh) return 1; + *hour = atoi(hh); + } + if (min ) { + mm = strtok_r(NULL, ":", &strtok_pos); + if (!mm) return 1; + *min = atoi(mm); + } + if (sec ) { + ss = strtok_r(NULL, "", &strtok_pos); + if (!ss) return 1; + *sec = atoi(ss); + } *year = atoi(y); *month = atoi(m); *day = atoi(d); + + if (hour && (*hour < 0 || *hour > 23)) return 1; + if (min && (*min < 0 || *min > 59)) return 1; + if (sec && (*sec < 0 || *sec > 59)) return 1; + if (*year < 1 || *month < 1 || *month > 12 || *day < 1 || *day > MonthDay(*month, is_leap_year(*year))) return 1; return 0; } +/** + * return 1 if date is invalid + */ +int ParseDate(const char *date, int *year, int *month, int *day) +{ + return ParseDateTime(date, year, month, day, NULL, NULL, NULL); +} + /** * return 1 if date is invalid */ -- cgit v1.2.3