468
localtime_r(&n, tm);
469
}
470
471
+static void date_yesterday(struct tm *tm, int *num)
472
+{
473
+ update_tm(tm, 24*60*60);
474
+}
475
+
476
+static void date_time(struct tm *tm, int hour)
477
+{
478
+ if (tm->tm_hour < hour)
479
+ date_yesterday(tm, NULL);
480
+ tm->tm_hour = hour;
481
+ tm->tm_min = 0;
482
+ tm->tm_sec = 0;
483
+}
484
+
485
+static void date_midnight(struct tm *tm, int *num)
486
+{
487
+ date_time(tm, 0);
488
+}
489
+
490
+static void date_noon(struct tm *tm, int *num)
491
+{
492
+ date_time(tm, 12);
493
+}
494
+
495
+static void date_tea(struct tm *tm, int *num)
496
+{
497
+ date_time(tm, 17);
498
+}
499
+
500
+static const struct special {
501
+ const char *name;
502
+ void (*fn)(struct tm *, int *);
503
+} special[] = {
504
+ { "yesterday", date_yesterday },
505
+ { "noon", date_noon },
506
+ { "midnight", date_midnight },
507
+ { "tea", date_tea },
508
+ { NULL }
509
+};
510
+
511
static const char *number_name[] = {
512
"zero", "one", "two", "three", "four",
513
"five", "six", "seven", "eight", "nine", "ten",
514
};
515
476
-static struct typelen {
516
+static const struct typelen {
517
const char *type;
518
int length;
519
} typelen[] = {
527
528
static const char *approxidate_alpha(const char *date, struct tm *tm, int *num)
529
{
490
- struct typelen *tl;
530
+ const struct typelen *tl;
531
+ const struct special *s;
532
const char *end = date;
533
int n = 1, i;
534
543
}
544
}
545
505
- if (match_string(date, "yesterday") > 8) {
506
- update_tm(tm, 24*60*60);
507
- return end;
546
+ for (s = special; s->name; s++) {
547
+ int len = strlen(s->name);
548
+ if (match_string(date, s->name) == len) {
549
+ s->fn(tm, num);
550
+ return end;
551
+ }
552
}
553
554
if (!*num) {