예제 #1
0
        public void TestParseDateTime(string f0, int y0, int m0, int d0, int h0, int mn0, int s0)
        {
            string     format = f0.Length > 0 ? "{0:" + f0 + "}" : "{0}";
            FormatSpec fs     = new FormatSpec(format, 0, format.Length);
            DateTime   dtnow  = DateTime.Now;

            if (y0 == 0)
            {
                y0 = dtnow.Year;
            }
            if (m0 == 0)
            {
                m0 = dtnow.Month;
            }
            if (d0 == 0)
            {
                d0 = dtnow.Day;
            }
            DateTime dt00 = new DateTime(y0, m0, d0, h0, mn0, s0);
            DateTime dt0  = DateTime.SpecifyKind(dt00, DateTimeKind.Utc);
            String   l0   = String.Format("***" + format + "***", dt0);
            int      j1   = fs.Parse(l0, 3, typeof(DateTime), out object d1);

            _output.WriteLine($"dt0 = {dt0}, d1 = {d1}, f0 = {f0}, l0 = {l0}");
            Assert.Equal(l0.Length - 3, j1);
            Assert.Equal(d1, dt0);
        }
예제 #2
0
        public void TestParse(string s0, int i0, int l0, string t0, int k0, Type y0, int j0, object d0)
        {
            FormatSpec fs = new FormatSpec(s0, i0, l0);
            int        j1 = fs.Parse(t0, k0, y0, out object d1);

            Assert.Equal(j0, j1);
            Assert.Equal(d0, d1);
        }
예제 #3
0
        public void TestParseTimeSpan(string f0, int d0, int h0, int m0, int ms0)
        {
            string     format = f0.Length > 0 ? "{0:" + f0 + "}" : "{0}";
            FormatSpec fs     = new FormatSpec(format, 0, format.Length);
            TimeSpan   ts0    = new TimeSpan(d0, h0, m0, ms0);
            String     l0     = String.Format("aaa" + format + "bbb", ts0);
            int        j1     = fs.Parse(l0, 3, typeof(TimeSpan), out object d1);

            Assert.Equal(l0.Length - 3, j1);
            Assert.Equal(d1, ts0);
        }