// // // /// <summary> /// Increment the /// <see cref="author">author</see> /// and /// <see cref="committer">committer</see> /// times. /// </summary> protected internal virtual void Tick() { long delta = TimeUnit.MILLISECONDS.Convert(5 * 60, TimeUnit.SECONDS); long now = author.GetWhen().GetTime() + delta; author = new PersonIdent(author, now, tz); committer = new PersonIdent(committer, now, tz); }
private string Iso(PersonIdent id) { SimpleDateFormat fmt; fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); fmt.SetTimeZone(id.GetTimeZone()); return(fmt.Format(id.GetWhen())); }
public static DateTime when(this PersonIdent personIdent) { if (personIdent.notNull()) { return(personIdent.GetWhen()); } return(default(DateTime)); }
internal virtual long Timeof(RevObject o) { if (o is RevCommit) { return(((RevCommit)o).CommitTime); } if (o is RevTag) { RevTag tag = (RevTag)o; PersonIdent who = tag.GetTaggerIdent(); return(who != null?who.GetWhen().GetTime() : 0); } return(0); }
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 ()); }
internal virtual long Timeof(RevObject o) { if (o is RevCommit) { return(((RevCommit)o).CommitTime); } if (o is RevTag) { RevTag tag = (RevTag)o; try { this._enclosing.ParseBody(tag); } catch (IOException) { return(0); } PersonIdent who = tag.GetTaggerIdent(); return(who != null?who.GetWhen().GetTime() : 0); } return(0); }
public virtual void CommitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime( ) { Git git = new Git(db); WriteTrashFile("file1", "file1"); git.Add().AddFilepattern("file1").Call(); string authorName = "First Author"; string authorEmail = "*****@*****.**"; DateTime authorDate = Sharpen.Extensions.CreateDate(1349621117000L); PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail, authorDate, Sharpen.Extensions.GetTimeZone ("UTC")); git.Commit().SetMessage("initial commit").SetAuthor(firstAuthor).Call(); RevCommit amended = git.Commit().SetAmend(true).SetMessage("amend commit").Call(); PersonIdent amendedAuthor = amended.GetAuthorIdent(); NUnit.Framework.Assert.AreEqual(authorName, amendedAuthor.GetName()); NUnit.Framework.Assert.AreEqual(authorEmail, amendedAuthor.GetEmailAddress()); NUnit.Framework.Assert.AreEqual(authorDate.GetTime(), amendedAuthor.GetWhen().GetTime ()); }
/// <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; } } }
public virtual void TestParse_NoParents() { ObjectId treeId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); string authorName = "A U. Thor"; string authorEmail = "*****@*****.**"; int authorTime = 1218123387; string authorTimeZone = "+0700"; string committerName = "C O. Miter"; string committerEmail = "*****@*****.**"; int committerTime = 1218123390; string committerTimeZone = "-0500"; StringBuilder body = new StringBuilder(); body.Append("tree "); body.Append(treeId.Name); body.Append("\n"); body.Append("author "); body.Append(authorName); body.Append(" <"); body.Append(authorEmail); body.Append("> "); body.Append(authorTime); body.Append(" "); body.Append(authorTimeZone); body.Append(" \n"); body.Append("committer "); body.Append(committerName); body.Append(" <"); body.Append(committerEmail); body.Append("> "); body.Append(committerTime); body.Append(" "); body.Append(committerTimeZone); body.Append("\n"); body.Append("\n"); RevWalk rw = new RevWalk(db); RevCommit c; c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); NUnit.Framework.Assert.IsNull(c.Tree); NUnit.Framework.Assert.IsNull(c.parents); c.ParseCanonical(rw, Sharpen.Runtime.GetBytesForString(body.ToString(), "UTF-8")); NUnit.Framework.Assert.IsNotNull(c.Tree); NUnit.Framework.Assert.AreEqual(treeId, c.Tree.Id); NUnit.Framework.Assert.AreSame(rw.LookupTree(treeId), c.Tree); NUnit.Framework.Assert.IsNotNull(c.parents); NUnit.Framework.Assert.AreEqual(0, c.parents.Length); NUnit.Framework.Assert.AreEqual(string.Empty, c.GetFullMessage()); PersonIdent cAuthor = c.GetAuthorIdent(); NUnit.Framework.Assert.IsNotNull(cAuthor); NUnit.Framework.Assert.AreEqual(authorName, cAuthor.GetName()); NUnit.Framework.Assert.AreEqual(authorEmail, cAuthor.GetEmailAddress()); NUnit.Framework.Assert.AreEqual((long)authorTime * 1000, cAuthor.GetWhen().GetTime ()); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + authorTimeZone ).BaseUtcOffset, cAuthor.GetTimeZone().BaseUtcOffset); PersonIdent cCommitter = c.GetCommitterIdent(); NUnit.Framework.Assert.IsNotNull(cCommitter); NUnit.Framework.Assert.AreEqual(committerName, cCommitter.GetName()); NUnit.Framework.Assert.AreEqual(committerEmail, cCommitter.GetEmailAddress()); NUnit.Framework.Assert.AreEqual((long)committerTime * 1000, cCommitter.GetWhen(). GetTime()); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.GetTimeZone("GMT" + committerTimeZone ).BaseUtcOffset, cCommitter.GetTimeZone().BaseUtcOffset); }