X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=date.c;h=18259227321f47988386c2bd70888b3c967d8ab6;hb=0f03ca946142bd656c1af9ff811cb9efbc8314da;hp=4ff6604a09045789ca6abcdc0396fdc4467e1101;hpb=e92a54d99cb36eab6e29069fe3b135e6e6b24f12;p=git.git diff --git a/date.c b/date.c index 4ff6604a0..182592273 100644 --- a/date.c +++ b/date.c @@ -256,8 +256,12 @@ static int match_alpha(const char *date, struct tm *tm, int *offset) } if (match_string(date, "PM") == 2) { - if (tm->tm_hour > 0 && tm->tm_hour < 12) - tm->tm_hour += 12; + tm->tm_hour = (tm->tm_hour % 12) + 12; + return 2; + } + + if (match_string(date, "AM") == 2) { + tm->tm_hour = (tm->tm_hour % 12) + 0; return 2; } @@ -598,6 +602,34 @@ static void date_tea(struct tm *tm, int *num) date_time(tm, 17); } +static void date_pm(struct tm *tm, int *num) +{ + int hour, n = *num; + *num = 0; + + hour = tm->tm_hour; + if (n) { + hour = n; + tm->tm_min = 0; + tm->tm_sec = 0; + } + tm->tm_hour = (hour % 12) + 12; +} + +static void date_am(struct tm *tm, int *num) +{ + int hour, n = *num; + *num = 0; + + hour = tm->tm_hour; + if (n) { + hour = n; + tm->tm_min = 0; + tm->tm_sec = 0; + } + tm->tm_hour = (hour % 12); +} + static const struct special { const char *name; void (*fn)(struct tm *, int *); @@ -606,6 +638,8 @@ static const struct special { { "noon", date_noon }, { "midnight", date_midnight }, { "tea", date_tea }, + { "PM", date_pm }, + { "AM", date_am }, { NULL } }; @@ -717,6 +751,18 @@ static const char *approxidate_digit(const char *date, struct tm *tm, int *num) char *end; unsigned long number = strtoul(date, &end, 10); + switch (*end) { + case ':': + case '.': + case '/': + case '-': + if (isdigit(end[1])) { + int match = match_multi_number(number, *end, date, end, tm); + if (match) + return date + match; + } + } + *num = number; return end; }