Exemplo n.º 1
0
        private void AssertFormat(long ageFromNow, long timeUnit, string expectedFormat)
        {
            DateTime d = Sharpen.Extensions.CreateDate(Runtime.CurrentTimeMillis() - ageFromNow
                                                       * timeUnit);
            string s = RelativeDateFormatter.Format(d);

            NUnit.Framework.Assert.AreEqual(expectedFormat, s);
        }
        private void AssertFormat(long ageFromNow, long timeUnit, string expectedFormat)
        {
            DateTime d = Sharpen.Extensions.CreateDate(SystemReader.GetInstance().GetCurrentTime
                                                           () - ageFromNow * timeUnit);
            string s = RelativeDateFormatter.Format(d);

            NUnit.Framework.Assert.AreEqual(expectedFormat, s);
        }
Exemplo n.º 3
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;
            }
            }
        }