diff options
author | dwmalone <dwmalone@FreeBSD.org> | 2001-01-02 11:35:57 +0000 |
---|---|---|
committer | dwmalone <dwmalone@FreeBSD.org> | 2001-01-02 11:35:57 +0000 |
commit | 53a3f567649231292f6d2d30eacf90124de02bee (patch) | |
tree | 4e92ee1920b3dbdc3109720223106a7b0181ed4d /usr.bin/calendar/day.c | |
parent | f41cea7e3911617cd40849a9e2785c99afd6c520 (diff) | |
download | FreeBSD-src-53a3f567649231292f6d2d30eacf90124de02bee.zip FreeBSD-src-53a3f567649231292f6d2d30eacf90124de02bee.tar.gz |
Use a slightly better documented way of calculating easter and
include a reference to the Calendar FAQ. Also make argument parsing
a little more robust.
PR: 23881
Diffstat (limited to 'usr.bin/calendar/day.c')
-rw-r--r-- | usr.bin/calendar/day.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c index cdc3678..cf619b6 100644 --- a/usr.bin/calendar/day.c +++ b/usr.bin/calendar/day.c @@ -165,17 +165,13 @@ settime(now) time_t Mktime (dp) char *dp; { - char *date; time_t t; - int len; + int d, m, y; struct tm tm; - if ((date = strdup(dp)) == NULL) - errx(1, "strdup failed in Mktime"); (void)time(&t); tp = localtime(&t); - len = strlen(date); tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 0; @@ -184,31 +180,23 @@ time_t Mktime (dp) tm.tm_mon = tp->tm_mon; tm.tm_year = tp->tm_year; - - /* day */ - *(date+2) = '\0'; - tm.tm_mday = atoi(date); - - /* month */ - if (len >= 4) { - *(date+5) = '\0'; - tm.tm_mon = atoi(date+3) - 1; - } - - /* Year */ - if (len >= 7) { - tm.tm_year = atoi(date+6); - - /* tm_year up 1900 ... */ - if (tm.tm_year > 1900) - tm.tm_year -= 1900; + switch (sscanf(dp, "%d.%d.%d", &d, &m, &y)) { + case 3: + if (y > 1900) + y -= 1900; + tm.tm_year = y; + /* FALLTHROUGH */ + case 2: + tm.tm_mon = m - 1; + /* FALLTHROUGH */ + case 1: + tm.tm_mday = d; } #ifdef DEBUG fprintf(stderr, "Mktime: %d %d %d %s\n", (int)mktime(&tm), (int)t, len, asctime(&tm)); #endif - free(date); return(mktime(&tm)); } |