@matheusbsbs / matheus-bagliano / commits / c933b28d87
Fork 0

date.c: s/is_date/set_date/

The function is_date, confusingly also set tm_year. tm_mon, and tm_mday after validating input. Rename to set_date to reflect its real usage. Also, change return value is 0 on success and -1 on failure following our convention on function do some real work. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Đoàn Trần Công Danh committed Apr 23, 2020 at 20:52 UTC c933b28d87062a0c68de298900b9060f577f865a
1 file changed +11 -11
date.c
+11 -11
@@ -497,7 +497,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
497 return skip_alpha(date);
498 }
499
500 -static int is_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm)
500 +static int set_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm)
501 {
502 if (month > 0 && month < 13 && day > 0 && day < 32) {
503 struct tm check = *tm;
@@ -518,9 +518,9 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
518 else if (year < 38)
519 r->tm_year = year + 100;
520 else
521 - return 0;
521 + return -1;
522 if (!now_tm)
523 - return 1;
523 + return 0;
524
525 specified = tm_to_time_t(r);
526
@@ -529,14 +529,14 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
529 * sure it is not later than ten days from now...
530 */
531 if ((specified != -1) && (now + 10*24*3600 < specified))
532 - return 0;
532 + return -1;
533 tm->tm_mon = r->tm_mon;
534 tm->tm_mday = r->tm_mday;
535 if (year != -1)
536 tm->tm_year = r->tm_year;
537 - return 1;
537 + return 0;
538 }
539 - return 0;
539 + return -1;
540 }
541
542 static int match_multi_number(timestamp_t num, char c, const char *date,
@@ -575,10 +575,10 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
575
576 if (num > 70) {
577 /* yyyy-mm-dd? */
578 - if (is_date(num, num2, num3, NULL, now, tm))
578 + if (set_date(num, num2, num3, NULL, now, tm) == 0)
579 break;
580 /* yyyy-dd-mm? */
581 - if (is_date(num, num3, num2, NULL, now, tm))
581 + if (set_date(num, num3, num2, NULL, now, tm) == 0)
582 break;
583 }
584 /* Our eastern European friends say dd.mm.yy[yy]
@@ -586,14 +586,14 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
586 * mm/dd/yy[yy] form only when separator is not '.'
587 */
588 if (c != '.' &&
589 - is_date(num3, num, num2, refuse_future, now, tm))
589 + set_date(num3, num, num2, refuse_future, now, tm) == 0)
590 break;
591 /* European dd.mm.yy[yy] or funny US dd/mm/yy[yy] */
592 - if (is_date(num3, num2, num, refuse_future, now, tm))
592 + if (set_date(num3, num2, num, refuse_future, now, tm) == 0)
593 break;
594 /* Funny European mm.dd.yy */
595 if (c == '.' &&
596 - is_date(num3, num, num2, refuse_future, now, tm))
596 + set_date(num3, num, num2, refuse_future, now, tm) == 0)
597 break;
598 return 0;
599 }