# add UTC option for pretty-formats

2 messages from 2010-10-27 to 2010-11-08. Participants: Jeff Carr, Jonathan Nieder.
Thread: https://gitlist.dev/t/25554

## Jeff Carr, 2010-10-27 01:32

Subject: add UTC option for pretty-formats
Message-ID: <AANLkTikN_B-bUTyy5440AVwTD=KkUWdkf_ukRszTuhYG@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTikN_B-bUTyy5440AVwTD%3DKkUWdkf_ukRszTuhYG%40mail.gmail.com

```
Adds displaying author and commit times in UTC using %au and %cu.


commit 99a429c3e369ca76113a8642f80245d7644b9a2f
Author: Jeff Carr <jcarr@basilarchia@gmail.com>
Date:   Tue Oct 26 18:25:06 2010 -0700

    Adds a UTC option to the pretty formats

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 561cc9f..df56147 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -114,6 +114,7 @@ The placeholders are:
 - '%ar': author date, relative
 - '%at': author date, UNIX timestamp
 - '%ai': author date, ISO 8601 format
+- '%au': author date, UTC
 - '%cn': committer name
 - '%cN': committer name (respecting .mailmap, see linkgit:git-shortlog[1] or linkgit:git-blame[1])
 - '%ce': committer email
@@ -123,6 +124,7 @@ The placeholders are:
 - '%cr': committer date, relative
 - '%ct': committer date, UNIX timestamp
 - '%ci': committer date, ISO 8601 format
+- '%cu': committer date, UTC
 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
 - '%e': encoding
 - '%s': subject
diff --git a/builtin/blame.c b/builtin/blame.c
index 1015354..33b04e6 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2343,6 +2343,9 @@ parse_done:
 	case DATE_SHORT:
 		blame_date_width = sizeof("2006-10-19");
 		break;
+	case DATE_UTC:
+		blame_date_width = sizeof("Fri Mar 12 20:18:53 UTC 2010");
+		break;
 	case DATE_RELATIVE:
 		/* "normal" is used as the fallback for "relative" */
 	case DATE_LOCAL:
diff --git a/cache.h b/cache.h
index 33decd9..a46965d 100644
--- a/cache.h
+++ b/cache.h
@@ -812,6 +812,7 @@ enum date_mode {
 	DATE_LOCAL,
 	DATE_ISO8601,
 	DATE_RFC2822,
+	DATE_UTC,
 	DATE_RAW
 };
 
diff --git a/date.c b/date.c
index 00f9eb5..64bbce0 100644
--- a/date.c
+++ b/date.c
@@ -157,6 +157,17 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode)
 		return timebuf;
 	}
 
+	if (mode == DATE_UTC) {
+		tm = time_to_tm(time, 0);
+		sprintf(timebuf, "%.3s %.3s %2d %02d:%02d:%02d UTC %d",
+			weekday_names[tm->tm_wday],
+			month_names[tm->tm_mon],
+			tm->tm_mday,
+			tm->tm_hour, tm->tm_min, tm->tm_sec,
+			tm->tm_year + 1900);
+		return timebuf;
+	}
+
 	if (mode == DATE_RELATIVE) {
 		struct timeval now;
 		gettimeofday(&now, NULL);
diff --git a/pretty.c b/pretty.c
index f85444b..9903a12 100644
--- a/pretty.c
+++ b/pretty.c
@@ -531,6 +531,9 @@ static size_t format_person_part(struct strbuf *sb, char part,
 	case 'i':	/* date, ISO 8601 */
 		strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
 		return placeholder_len;
+	case 'u':	/* date, UTC */
+		strbuf_addstr(sb, show_date(date, tz, DATE_UTC));
+		return placeholder_len;
 	}
 
 skip:

```

## Jonathan Nieder, 2010-11-08 08:41

Subject: Re: add UTC option for pretty-formats
Message-ID: <20101108084150.GB2430@burratino>
URL: https://gitlist.dev/e/20101108084150.GB2430%40burratino
In-Reply-To: <AANLkTikN_B-bUTyy5440AVwTD=KkUWdkf_ukRszTuhYG@mail.gmail.com>

```
Hi Jeff,

Jeff Carr wrote:

> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -114,6 +114,7 @@ The placeholders are:
>  - '%ar': author date, relative
>  - '%at': author date, UNIX timestamp
>  - '%ai': author date, ISO 8601 format
> +- '%au': author date, UTC

Why not:

	TZ=UTC git log --format=%ad --date=local

or something like:

	git log --format=%AD(rfc2822,tz=UTC)

?  In other words, why should we provide this feature with date=rfc
dates and not date=iso ones?

```
