diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-30 20:47:31 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-08-30 20:47:31 +0800 |
commit | 48b5100a347dfb5bb48a4d695a44c81e4378d69d (patch) | |
tree | 9eb7d4c6a9965ea15978afd7996310f1df0a2be0 /mbbsd/calendar.c | |
parent | be508920d9516539c9423d351fa2ba7fe2b910e1 (diff) | |
download | pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar.gz pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar.bz2 pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar.lz pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar.xz pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.tar.zst pttbbs-48b5100a347dfb5bb48a4d695a44c81e4378d69d.zip |
* allow setting chess_go results and lastlogin
git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4801 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/calendar.c')
-rw-r--r-- | mbbsd/calendar.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index dad8bc46..a8c63eb3 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -31,22 +31,44 @@ 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; @@ -56,6 +78,14 @@ int ParseDate(const char *date, int *year, int *month, int *day) /** * 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 + */ static int ParseEventDate(const char *date, event_t * t) { |