Skip to content

Commit c933b28

Browse files
sgngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent efe3874 commit c933b28

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

date.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int match_alpha(const char *date, struct tm *tm, int *offset)
497497
return skip_alpha(date);
498498
}
499499

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)
501501
{
502502
if (month > 0 && month < 13 && day > 0 && day < 32) {
503503
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,
518518
else if (year < 38)
519519
r->tm_year = year + 100;
520520
else
521-
return 0;
521+
return -1;
522522
if (!now_tm)
523-
return 1;
523+
return 0;
524524

525525
specified = tm_to_time_t(r);
526526

@@ -529,14 +529,14 @@ static int is_date(int year, int month, int day, struct tm *now_tm, time_t now,
529529
* sure it is not later than ten days from now...
530530
*/
531531
if ((specified != -1) && (now + 10*24*3600 < specified))
532-
return 0;
532+
return -1;
533533
tm->tm_mon = r->tm_mon;
534534
tm->tm_mday = r->tm_mday;
535535
if (year != -1)
536536
tm->tm_year = r->tm_year;
537-
return 1;
537+
return 0;
538538
}
539-
return 0;
539+
return -1;
540540
}
541541

542542
static int match_multi_number(timestamp_t num, char c, const char *date,
@@ -575,25 +575,25 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
575575

576576
if (num > 70) {
577577
/* yyyy-mm-dd? */
578-
if (is_date(num, num2, num3, NULL, now, tm))
578+
if (set_date(num, num2, num3, NULL, now, tm) == 0)
579579
break;
580580
/* yyyy-dd-mm? */
581-
if (is_date(num, num3, num2, NULL, now, tm))
581+
if (set_date(num, num3, num2, NULL, now, tm) == 0)
582582
break;
583583
}
584584
/* Our eastern European friends say dd.mm.yy[yy]
585585
* is the norm there, so giving precedence to
586586
* mm/dd/yy[yy] form only when separator is not '.'
587587
*/
588588
if (c != '.' &&
589-
is_date(num3, num, num2, refuse_future, now, tm))
589+
set_date(num3, num, num2, refuse_future, now, tm) == 0)
590590
break;
591591
/* 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)
593593
break;
594594
/* Funny European mm.dd.yy */
595595
if (c == '.' &&
596-
is_date(num3, num, num2, refuse_future, now, tm))
596+
set_date(num3, num, num2, refuse_future, now, tm) == 0)
597597
break;
598598
return 0;
599599
}

0 commit comments

Comments
 (0)