public virtual void TestAuthorScriptConverter() { // -1 h timezone offset PersonIdent ident = new PersonIdent("Author name", "*****@*****.**", 123456789123L , -60); string convertedAuthor = git.Rebase().ToAuthorScript(ident); string[] lines = convertedAuthor.Split("\n"); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='*****@*****.**'", lines[1]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 -0100'", lines[2]); PersonIdent parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString (convertedAuthor, "UTF-8")); NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName()); NUnit.Framework.Assert.AreEqual(ident.GetEmailAddress(), parsedIdent.GetEmailAddress ()); // this is rounded to the last second NUnit.Framework.Assert.AreEqual(123456789000L, parsedIdent.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual(ident.GetTimeZoneOffset(), parsedIdent.GetTimeZoneOffset ()); // + 9.5h timezone offset ident = new PersonIdent("Author name", "*****@*****.**", 123456789123L, +570); convertedAuthor = git.Rebase().ToAuthorScript(ident); lines = convertedAuthor.Split("\n"); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_NAME='Author name'", lines[0]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_EMAIL='*****@*****.**'", lines[1]); NUnit.Framework.Assert.AreEqual("GIT_AUTHOR_DATE='123456789 +0930'", lines[2]); parsedIdent = git.Rebase().ParseAuthor(Sharpen.Runtime.GetBytesForString(convertedAuthor , "UTF-8")); NUnit.Framework.Assert.AreEqual(ident.GetName(), parsedIdent.GetName()); NUnit.Framework.Assert.AreEqual(ident.GetEmailAddress(), parsedIdent.GetEmailAddress ()); NUnit.Framework.Assert.AreEqual(123456789000L, parsedIdent.GetWhen().GetTime()); NUnit.Framework.Assert.AreEqual(ident.GetTimeZoneOffset(), parsedIdent.GetTimeZoneOffset ()); }
/// <summary> /// Format committer, author or tagger ident according to this formatter's /// specification. /// </summary> /// <remarks> /// Format committer, author or tagger ident according to this formatter's /// specification. /// </remarks> /// <param name="ident"></param> /// <returns>formatted version of date, time and time zone</returns> public virtual string FormatDate(PersonIdent ident) { TimeZoneInfo tz; switch (format) { case GitDateFormatter.Format.RAW: { int offset = ident.GetTimeZoneOffset(); string sign = offset < 0 ? "-" : "+"; int offset2; if (offset < 0) { offset2 = -offset; } else { offset2 = offset; } int hours = offset2 / 60; int minutes = offset2 % 60; return(string.Format("%d %s%02d%02d", ident.GetWhen().GetTime() / 1000, sign, hours , minutes)); } case GitDateFormatter.Format.RELATIVE: { return(RelativeDateFormatter.Format(ident.GetWhen())); } case GitDateFormatter.Format.LOCALELOCAL: case GitDateFormatter.Format.LOCAL: { dateTimeInstance.SetTimeZone(SystemReader.GetInstance().GetTimeZone()); return(dateTimeInstance.Format(ident.GetWhen())); } case GitDateFormatter.Format.LOCALE: { tz = ident.GetTimeZone(); if (tz == null) { tz = SystemReader.GetInstance().GetTimeZone(); } dateTimeInstance.SetTimeZone(tz); dateTimeInstance2.SetTimeZone(tz); return(dateTimeInstance.Format(ident.GetWhen()) + " " + dateTimeInstance2.Format( ident.GetWhen())); } default: { tz = ident.GetTimeZone(); if (tz == null) { tz = SystemReader.GetInstance().GetTimeZone(); } dateTimeInstance.SetTimeZone(ident.GetTimeZone()); return(dateTimeInstance.Format(ident.GetWhen())); break; } } }