summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorĐoàn Trần Công Danh <congdanhqx@gmail.com>2020-04-24 15:07:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-04-24 21:06:09 (GMT)
commit4f89f4fc9ac494fde3f3bede19a7599f77afe8dc (patch)
treef21a5dceba50bb2cfc746ad5bd2df1f4a2e6dd73
parentc933b28d87062a0c68de298900b9060f577f865a (diff)
downloadgit-4f89f4fc9ac494fde3f3bede19a7599f77afe8dc.zip
git-4f89f4fc9ac494fde3f3bede19a7599f77afe8dc.tar.gz
git-4f89f4fc9ac494fde3f3bede19a7599f77afe8dc.tar.bz2
date.c: validate and set time in a helper function
In a later patch, we will reuse this logic, move it to a helper, now. While we're at it, explicit states that we intentionally ignore old-and-defective 2nd leap second. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--date.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/date.c b/date.c
index b67c5ab..fa39e5e 100644
--- a/date.c
+++ b/date.c
@@ -539,6 +539,20 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now,
return -1;
}
+static int set_time(long hour, long minute, long second, struct tm *tm)
+{
+ /* We accept 61st second because of leap second */
+ if (0 <= hour && hour <= 24 &&
+ 0 <= minute && minute < 60 &&
+ 0 <= second && second <= 60) {
+ tm->tm_hour = hour;
+ tm->tm_min = minute;
+ tm->tm_sec = second;
+ return 0;
+ }
+ return -1;
+}
+
static int match_multi_number(timestamp_t num, char c, const char *date,
char *end, struct tm *tm, time_t now)
{
@@ -556,10 +570,7 @@ static int match_multi_number(timestamp_t num, char c, const char *date,
case ':':
if (num3 < 0)
num3 = 0;
- if (num < 25 && num2 >= 0 && num2 < 60 && num3 >= 0 && num3 <= 60) {
- tm->tm_hour = num;
- tm->tm_min = num2;
- tm->tm_sec = num3;
+ if (set_time(num, num2, num3, tm) == 0) {
break;
}
return 0;