コード例 #1
0
ファイル: ReflogReaderTest.cs プロジェクト: ashmind/ngit
        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()));
        }
コード例 #2
0
        /// <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;
            }
            }
        }
コード例 #3
0
        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);
        }