diff options
author | Vincent Ambo <tazjin@google.com> | 2020-01-06T16·00+0000 |
---|---|---|
committer | Vincent Ambo <Vincent Ambo> | 2020-01-11T23·43+0000 |
commit | 8082d87da385e2a4aeaff915799d26feb42b83af (patch) | |
tree | a22174be203faacc06e3cccfaf698606c15952ae /third_party/git/date.c | |
parent | 7ef0d62730840ded097b524104cc0a0904591a63 (diff) |
feat(third_party/git/date): add "dottime" format r/374
Adds dottime (as defined on https://dotti.me) as a timestamp format. This format is designed to simplify working with timestamps across many different timezones by keeping the timestamp format itself in UTC (and indicating this with a dot character), but appending the local offset. This is implemented as a new format because the timestamp needs to be rendered both as UTC and including the offset, an implementation using a strftime formatting string is not sufficient.
Diffstat (limited to 'third_party/git/date.c')
-rw-r--r-- | third_party/git/date.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/third_party/git/date.c b/third_party/git/date.c index 8126146c5069..06340a77f319 100644 --- a/third_party/git/date.c +++ b/third_party/git/date.c @@ -350,6 +350,21 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode) tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, sign, tz / 100, tz % 100); + } else if (mode->type == DATE_DOTTIME) { + char sign = (tz >= 0) ? '+' : '-'; + tz = abs(tz); + + // Time is converted again without the timezone as the + // dottime format includes the zone only in offset + // position. + time_t t = gm_time_t(time, 0); + tm = gmtime(&t); + strbuf_addf(&timebuf, "%04d-%02d-%02dT%02d·%02d%c%02d%02d", + tm->tm_year + 1900, + tm->tm_mon + 1, + tm->tm_mday, + tm->tm_hour, tm->tm_min, + sign, tz / 100, tz % 100); } else if (mode->type == DATE_RFC2822) strbuf_addf(&timebuf, "%.3s, %d %.3s %d %02d:%02d:%02d %+05d", weekday_names[tm->tm_wday], tm->tm_mday, @@ -921,6 +936,8 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) return DATE_UNIX; if (skip_prefix(format, "format", end)) return DATE_STRFTIME; + if (skip_prefix(format, "dottime", end)) + return DATE_DOTTIME; /* * Please update $__git_log_date_formats in * git-completion.bash when you add new formats. |