Commit e385fc421f331989f2e6518465e5ead42e5a0618

Stefan Sperling 2021-08-30T15:48:05

use gmtime_r(3) instead of localtime_r(3) to display time in UTC as intended Problem noticed by naddy due to failing regress tests at midnight, and then analyzed with additional help from millert. ok naddy

diff --git a/got/got.c b/got/got.c
index f48598b..b008eec 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4659,8 +4659,8 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
 	}
 
 	committer_time = got_object_commit_get_committer_time(commit);
-	if (localtime_r(&committer_time, &tm) == NULL)
-		return got_error_from_errno("localtime_r");
+	if (gmtime_r(&committer_time, &tm) == NULL)
+		return got_error_from_errno("gmtime_r");
 	if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
 	    &tm) == 0) {
 		err = got_error(GOT_ERR_NO_SPACE);
@@ -8414,8 +8414,8 @@ get_commit_brief_str(char **brief_str, struct got_commit_object *commit)
 	char *logmsg0 = NULL, *logmsg, *newline;
 
 	committer_time = got_object_commit_get_committer_time(commit);
-	if (localtime_r(&committer_time, &tm) == NULL)
-		return got_error_from_errno("localtime_r");
+	if (gmtime_r(&committer_time, &tm) == NULL)
+		return got_error_from_errno("gmtime_r");
 	if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d", &tm) == 0)
 		return got_error(GOT_ERR_NO_SPACE);
 
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 7d851f4..360a75d 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -3909,8 +3909,8 @@ gw_blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
 	}
 
 	committer_time = got_object_commit_get_committer_time(commit);
-	if (localtime_r(&committer_time, &tm) == NULL)
-		return got_error_from_errno("localtime_r");
+	if (gmtime_r(&committer_time, &tm) == NULL)
+		return got_error_from_errno("gmtime_r");
 	if (strftime(bline->datebuf, sizeof(bline->datebuf), "%G-%m-%d",
 	    &tm) == 0) {
 		err = got_error(GOT_ERR_NO_SPACE);
diff --git a/tog/tog.c b/tog/tog.c
index c175ea3..fc51be8 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1340,8 +1340,8 @@ draw_commit(struct tog_view *view, struct got_commit_object *commit,
 	struct tog_color *tc;
 
 	committer_time = got_object_commit_get_committer_time(commit);
-	if (localtime_r(&committer_time, &tm) == NULL)
-		return got_error_from_errno("localtime_r");
+	if (gmtime_r(&committer_time, &tm) == NULL)
+		return got_error_from_errno("gmtime_r");
 	if (strftime(datebuf, sizeof(datebuf), "%G-%m-%d ", &tm) == 0)
 		return got_error(GOT_ERR_NO_SPACE);