Example #1
0
        public void NpgsqlDateToString()
        {
            Assert.AreEqual("2009-05-31", new NpgsqlDate(2009, 5, 31).ToString());

            Assert.AreEqual("0001-05-07 BC", new NpgsqlDate(-1, 5, 7).ToString());

            var testCulture = new CultureInfo("fr-FR");

            Assert.AreEqual(",", testCulture.NumberFormat.NumberDecimalSeparator, "decimal seperator");
            using (TestUtil.SetCurrentCulture(testCulture))
                Assert.AreEqual("2009-05-31", new NpgsqlDate(2009, 5, 31).ToString());
        }
Example #2
0
        public void NpgsqlIntervalToString()
        {
            Assert.AreEqual("00:00:00", new NpgsqlTimeSpan().ToString());

            Assert.AreEqual("00:02:03.456789", new NpgsqlTimeSpan(1234567890).ToString());

            Assert.AreEqual("00:02:03.456789", new NpgsqlTimeSpan(1234567891).ToString());

            Assert.AreEqual("1 day 02:03:04.005",
                            new NpgsqlTimeSpan(new TimeSpan(1, 2, 3, 4, 5)).JustifyInterval().ToString());

            Assert.AreEqual("3 mons 2 days 00:02:03.456789", new NpgsqlTimeSpan(3, 2, 1234567890).ToString());

            Assert.AreEqual("1 day 02:03:04", new NpgsqlTimeSpan(1, 2, 3, 4).ToString());

            Assert.AreEqual("1 day 02:03:04.005", new NpgsqlTimeSpan(1, 2, 3, 4, 5).ToString());

            Assert.AreEqual("1 mon 2 days 03:04:05.006", new NpgsqlTimeSpan(1, 2, 3, 4, 5, 6).ToString());

            Assert.AreEqual("14 mons 3 days 04:05:06.007", new NpgsqlTimeSpan(1, 2, 3, 4, 5, 6, 7).ToString());

            Assert.AreEqual(new NpgsqlTimeSpan(0, 2, 3, 4, 5).ToString(), new NpgsqlTimeSpan(new TimeSpan(0, 2, 3, 4, 5)).ToString());

            Assert.AreEqual(new NpgsqlTimeSpan(1, 2, 3, 4, 5).ToString(), new NpgsqlTimeSpan(new TimeSpan(1, 2, 3, 4, 5)).ToString());
            const long moreThanAMonthInTicks = TimeSpan.TicksPerDay * 40;

            Assert.AreEqual(new NpgsqlTimeSpan(moreThanAMonthInTicks).ToString(), new NpgsqlTimeSpan(new TimeSpan(moreThanAMonthInTicks)).ToString());

            var testCulture = new CultureInfo("fr-FR");

            Assert.AreEqual(",", testCulture.NumberFormat.NumberDecimalSeparator, "decimal seperator");
            using (TestUtil.SetCurrentCulture(testCulture))
            {
                Assert.AreEqual("14 mons 3 days 04:05:06.007", new NpgsqlTimeSpan(1, 2, 3, 4, 5, 6, 7).ToString());
            }
        }
Example #3
0
        public void NpgsqlIntervalParse()
        {
            string         input;
            NpgsqlTimeSpan test;

            input = "1 day";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(1).Ticks, test.TotalTicks, input);

            input = "2 days";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(2).Ticks, test.TotalTicks, input);

            input = "2 days 3:04:05";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(2, 3, 4, 5).Ticks, test.TotalTicks, input);

            input = "-2 days";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(-2).Ticks, test.TotalTicks, input);

            input = "-2 days -3:04:05";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(-2, -3, -4, -5).Ticks, test.TotalTicks, input);

            input = "-2 days -0:01:02";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(-2, 0, -1, -2).Ticks, test.TotalTicks, input);

            input = "2 days -12:00";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(2, -12, 0, 0).Ticks, test.TotalTicks, input);

            input = "1 mon";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30).Ticks, test.TotalTicks, input);

            input = "2 mons";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(60).Ticks, test.TotalTicks, input);

            input = "1 mon -1 day";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(29).Ticks, test.TotalTicks, input);

            input = "1 mon -2 days";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(28).Ticks, test.TotalTicks, input);

            input = "-1 mon -2 days -3:04:05";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(-32, -3, -4, -5).Ticks, test.TotalTicks, input);

            input = "1 year";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 12).Ticks, test.TotalTicks, input);

            input = "2 years";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 24).Ticks, test.TotalTicks, input);

            input = "1 year -1 mon";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 11).Ticks, test.TotalTicks, input);

            input = "1 year -2 mons";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 10).Ticks, test.TotalTicks, input);

            input = "1 year -1 day";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 12 - 1).Ticks, test.TotalTicks, input);

            input = "1 year -2 days";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 12 - 2).Ticks, test.TotalTicks, input);

            input = "1 year -1 mon -1 day";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 11 - 1).Ticks, test.TotalTicks, input);

            input = "1 year -2 mons -2 days";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(TimeSpan.FromDays(30 * 10 - 2).Ticks, test.TotalTicks, input);

            input = "1 day 2:3:4.005";
            test  = NpgsqlTimeSpan.Parse(input);
            Assert.AreEqual(new TimeSpan(1, 2, 3, 4, 5).Ticks, test.TotalTicks, input);

            var testCulture = new CultureInfo("fr-FR");

            Assert.AreEqual(",", testCulture.NumberFormat.NumberDecimalSeparator, "decimal seperator");
            using (TestUtil.SetCurrentCulture(testCulture))
            {
                input = "1 day 2:3:4.005";
                test  = NpgsqlTimeSpan.Parse(input);
                Assert.AreEqual(new TimeSpan(1, 2, 3, 4, 5).Ticks, test.TotalTicks, input);
            }
        }