Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 931e8e2

Browse files
peffgitster
authored andcommitted
fix approxidate parsing of relative months and years
These were broken by b5373e9. The problem is that the code marks the month and year with "-1" for "we don't know it yet", but the month and year code paths were not adjusted to fill in the current time before doing their calculations (whereas other units follow a different code path and are fine). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 34dc6e7 commit 931e8e2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

date.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
857857
}
858858

859859
if (match_string(date, "months") >= 5) {
860-
int n = tm->tm_mon - *num;
860+
int n;
861+
update_tm(tm, now, 0); /* fill in date fields if needed */
862+
n = tm->tm_mon - *num;
861863
*num = 0;
862864
while (n < 0) {
863865
n += 12;
@@ -868,6 +870,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
868870
}
869871

870872
if (match_string(date, "years") >= 4) {
873+
update_tm(tm, now, 0); /* fill in date fields if needed */
871874
tm->tm_year -= *num;
872875
*num = 0;
873876
return end;

t/t0006-date.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ check_approxidate 10.minutes.ago '2009-08-30 19:10:00'
5353
check_approxidate yesterday '2009-08-29 19:20:00'
5454
check_approxidate 3.days.ago '2009-08-27 19:20:00'
5555
check_approxidate 3.weeks.ago '2009-08-09 19:20:00'
56-
check_approxidate 3.months.ago '2009-05-30 19:20:00' failure
57-
check_approxidate 2.years.3.months.ago '2007-05-30 19:20:00' failure
56+
check_approxidate 3.months.ago '2009-05-30 19:20:00'
57+
check_approxidate 2.years.3.months.ago '2007-05-30 19:20:00'
5858

5959
check_approxidate '6am yesterday' '2009-08-29 06:00:00'
6060
check_approxidate '6pm yesterday' '2009-08-29 18:00:00'

0 commit comments

Comments
 (0)