string GetCommitDate(GitRunner.BlamePorcelainEntry be) { int tzOffset = GetTZOffset(be.CommitterTZ, be); int committerTimeUTC = (int)be.CommitterTime + tzOffset; var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); DateTime dt = unixEpoch.AddSeconds(committerTimeUTC); return(dt.ToString("R", DateTimeFormatInfo.InvariantInfo)); }
int GetTZOffset(string tz, GitRunner.BlamePorcelainEntry be) { if (String.IsNullOrEmpty(tz)) { Log.DebugLine($"No timezone information from `git blame` for commit {be.Commit}"); return(0); } if (tz.Length != 5) { LogUnexpectedFormat(); return(0); } int tzSign; switch (tz [0]) { case '-': tzSign = 1; break; case '+': tzSign = -1; break; default: LogUnexpectedFormat(); return(0); } if (!Int32.TryParse(tz.Substring(1, 2), out int hours)) { LogUnexpectedFormat(); return(0); } if (!Int32.TryParse(tz.Substring(3, 2), out int minutes)) { LogUnexpectedFormat(); return(0); } return(tzSign * ((hours * 3600) + (minutes * 60))); void LogUnexpectedFormat() { Log.DebugLine($"Unexpected timezone format from `git blame` for commit {be.Commit}: {tz}"); } }