public void testEquality()
 {
     Assert.IsTrue(HDate.make(2011, 6, 7).hequals(HDate.make(2011, 6, 7)));
     Assert.IsFalse(HDate.make(2011, 6, 7).hequals(HDate.make(2011, 6, 8)));
     Assert.IsFalse(HDate.make(2011, 6, 7).hequals(HDate.make(2011, 2, 7)));
     Assert.IsFalse(HDate.make(2011, 6, 7).hequals(HDate.make(2009, 6, 7)));
 }
Exemplo n.º 2
0
 private HaystackToken date(string s)
 {
     // Java use to bubble Parse exception as err - this just accepts that the debug printing
     //  will be done by the user of this toolkit.
     m_val = HDate.make(s);
     return(HaystackToken.date);
 }
        public void testZinc()
        {
            verifyZinc(
                HDict.Empty,
                "{}");
            verifyZinc(
                new HDictBuilder().add("foo_12").toDict(),
                "{foo_12}");
            verifyZinc(
                new HDictBuilder().add("fooBar", 123, "ft").toDict(),
                "{fooBar:123ft}");
            verifyZinc(
                new HDictBuilder().add("dis", "Bob").add("bday", HDate.make(1970, 6, 3)).add("marker").toDict(),
                "{dis:\"Bob\" bday:1970-06-03 marker}");

            // nested dict
            verifyZinc(
                new HDictBuilder().add("auth", HDict.Empty).toDict(),
                "{auth:{}}");
            verifyZinc(
                new HDictBuilder().add("auth",
                                       new HDictBuilder().add("alg", "scram").add("c", 10000).add("marker").toDict()
                                       ).toDict(),
                "{auth:{alg:\"scram\" c:10000 marker}}");

            // nested list
            verifyZinc(
                new HDictBuilder().add("arr", HList.make(new HVal[] { HNum.make(1.0), HNum.make(2), HNum.make(3) }))
                .add("x").toDict(),
                "{arr:[1,2,3] x}"); // Was "{arr:[1.0,2,3] x}" - double in .NET will not recognise the difference between 1.0 and 1
        }
 public void testCompare()
 {
     Assert.IsTrue(HDate.make(2011, 6, 9).CompareTo(HDate.make(2011, 6, 21)) < 0);
     Assert.IsTrue(HDate.make(2011, 10, 9).CompareTo(HDate.make(2011, 3, 21)) > 0);
     Assert.IsTrue(HDate.make(2010, 6, 9).CompareTo(HDate.make(2000, 9, 30)) > 0);
     Assert.AreEqual(HDate.make(2010, 6, 9).CompareTo(HDate.make(2010, 6, 9)), 0);
 }
Exemplo n.º 5
0
        public void testBasics()
        {
            HRow row = BuildRows(
                new[] { "id", "site", "geoAddr", "area", "date", "null" },
                new HVal[] { HRef.make("aaaa-bbbb"), HMarker.VAL, HStr.make("Richmond, Va"), HNum.make(1200, "ft"), HDate.make(2000, 12, 3), null })
                       .First();

            // size
            Assert.AreEqual(row.size(), 6);
            Assert.IsFalse(row.isEmpty());

            // configured tags
            Assert.IsTrue(row.get("id").hequals(HRef.make("aaaa-bbbb")));
            Assert.IsTrue(row.get("site").hequals(HMarker.VAL));
            Assert.IsTrue(row.get("geoAddr").hequals(HStr.make("Richmond, Va")));
            Assert.IsTrue(row.get("area").hequals(HNum.make(1200, "ft")));
            Assert.IsTrue(row.get("date").hequals(HDate.make(2000, 12, 3)));
            Assert.AreEqual(row.get("null", false), null);
            try
            {
                row.get("null");
                Assert.Fail();
            }
            catch (HaystackUnknownNameException)
            {
                Assert.IsTrue(true);
            }

            // missing tag
            Assert.IsFalse(row.has("foo"));
            Assert.IsTrue(row.missing("foo"));
            Assert.IsNull(row.get("foo", false));
            try { row.get("foo"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); }
            try { row.get("foo", true); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); }
        }
 public void testMidnight()
 {
     verifyMidnight(HDate.make(2011, 11, 3), "UTC", "2011-11-03T00:00:00Z UTC");
     // 18.08.2018 - fails on this my implementation has offset for New_York as -05:00 not -04:00 - test changed
     verifyMidnight(HDate.make(2011, 11, 3), "New_York", "2011-11-03T00:00:00-05:00 New_York");
     verifyMidnight(HDate.make(2011, 12, 15), "Chicago", "2011-12-15T00:00:00-06:00 Chicago");
     verifyMidnight(HDate.make(2008, 2, 29), "Phoenix", "2008-02-29T00:00:00-07:00 Phoenix");
 }
Exemplo n.º 7
0
        public void testInclude()
        {
            HDict a = new HDictBuilder()
                      .add("dis", "a")
                      .add("num", 100)
                      .add("foo", 99)
                      .add("date", HDate.make(2011, 10, 5))
                      .toDict();

            HDict b = new HDictBuilder()
                      .add("dis", "b")
                      .add("num", 200)
                      .add("foo", 88)
                      .add("date", HDate.make(2011, 10, 20))
                      .add("bar")
                      .add("ref", HRef.make("a"))
                      .toDict();

            HDict c = new HDictBuilder()
                      .add("dis", "c")
                      .add("num", 300)
                      .add("ref", HRef.make("b"))
                      .add("bar")
                      .toDict();

            Dictionary <string, HDict> db = new Dictionary <string, HDict>();

            db.Add("a", a);
            db.Add("b", b);
            db.Add("c", c);

            verifyInclude(db, "dis", "a,b,c");
            verifyInclude(db, "dis == \"b\"", "b");
            verifyInclude(db, "dis != \"b\"", "a,c");
            verifyInclude(db, "dis <= \"b\"", "a,b");
            verifyInclude(db, "dis >  \"b\"", "c");
            verifyInclude(db, "num < 200", "a");
            verifyInclude(db, "num <= 200", "a,b");
            verifyInclude(db, "num > 200", "c");
            verifyInclude(db, "num >= 200", "b,c");
            verifyInclude(db, "date", "a,b");
            verifyInclude(db, "date == 2011-10-20", "b");
            verifyInclude(db, "date < 2011-10-10", "a");
            verifyInclude(db, "foo", "a,b");
            verifyInclude(db, "not foo", "c");
            verifyInclude(db, "foo == 88", "b");
            verifyInclude(db, "foo != 88", "a");
            verifyInclude(db, "foo == \"x\"", "");
            verifyInclude(db, "ref", "b,c");
            verifyInclude(db, "ref->dis", "b,c");
            verifyInclude(db, "ref->dis == \"a\"", "b");
            verifyInclude(db, "ref->bar", "c");
            verifyInclude(db, "not ref->bar", "a,b");
            verifyInclude(db, "foo and bar", "b");
            verifyInclude(db, "foo or bar", "a,b,c");
            verifyInclude(db, "(foo and bar) or num==300", "b,c");
            verifyInclude(db, "foo and bar and num==300", "");
        }
 public void testPlusMinus()
 {
     Assert.IsTrue(HDate.make(2011, 12, 1).minusDays(0).hequals(HDate.make(2011, 12, 1)));
     Assert.IsTrue(HDate.make(2011, 12, 1).minusDays(1).hequals(HDate.make(2011, 11, 30)));
     Assert.IsTrue(HDate.make(2011, 12, 1).minusDays(-2).hequals(HDate.make(2011, 12, 3)));
     Assert.IsTrue(HDate.make(2011, 12, 1).plusDays(2).hequals(HDate.make(2011, 12, 3)));
     Assert.IsTrue(HDate.make(2011, 12, 1).plusDays(31).hequals(HDate.make(2012, 1, 1)));
     Assert.IsTrue(HDate.make(2008, 3, 3).minusDays(3).hequals(HDate.make(2008, 2, 29)));
     Assert.IsTrue(HDate.make(2008, 3, 3).minusDays(4).hequals(HDate.make(2008, 2, 28)));
 }
Exemplo n.º 9
0
        public void testWriter()
        {
            HGridBuilder gb = new HGridBuilder();

            gb.addCol("a");
            gb.addCol("b");
            gb.addRow(new HVal[] { HNA.VAL, HBool.TRUE }); // Original Unit test had null - this is not valid
            gb.addRow(new HVal[] { HMarker.VAL, HNA.VAL });
            gb.addRow(new HVal[] { HRemove.VAL, HNA.VAL });
            gb.addRow(new HVal[] { HStr.make("test"), HStr.make("with:colon") });
            gb.addRow(new HVal[] { HNum.make(12), HNum.make(72.3, "\u00b0F") });
            gb.addRow(new HVal[] { HNum.make(double.NegativeInfinity), HNum.make(Double.NaN) });
            gb.addRow(new HVal[] { HDate.make(2015, 6, 9), HTime.make(1, 2, 3) });
            var tz = HTimeZone.make("UTC", true);

            gb.addRow(new HVal[] { HDateTime.make(634429600180690000L, tz), HUri.make("foo.txt") });
            gb.addRow(new HVal[] { HRef.make("abc"), HRef.make("abc", "A B C") });
            gb.addRow(new HVal[] { HBin.make("text/plain"), HCoord.make(90, -123) });
            HGrid grid = gb.toGrid();

            string actual = HJsonWriter.gridToString(grid);

            // System.out.println(actual);
            string[] lines = actual.Split('\n');
            Assert.AreEqual(lines[0], "{");
            Assert.AreEqual(lines[1], "\"meta\": {\"ver\":\"2.0\"},");
            Assert.AreEqual(lines[2], "\"cols\":[");
            Assert.AreEqual(lines[3], "{\"name\":\"a\"},");
            Assert.AreEqual(lines[4], "{\"name\":\"b\"}");
            Assert.AreEqual(lines[5], "],");
            Assert.AreEqual(lines[6], "\"rows\":[");
            Assert.AreEqual(lines[7], "{\"a\":\"z:\", \"b\":true},");
            Assert.AreEqual(lines[8], "{\"a\":\"m:\", \"b\":\"z:\"},");
            Assert.AreEqual(lines[9], "{\"a\":\"x:\", \"b\":\"z:\"},");
            Assert.AreEqual(lines[10], "{\"a\":\"test\", \"b\":\"s:with:colon\"},");
            Assert.AreEqual(lines[11], "{\"a\":\"n:12\", \"b\":\"n:72.3 \u00b0F\"},");
            Assert.AreEqual(lines[12], "{\"a\":\"n:-INF\", \"b\":\"n:NaN\"},");
            Assert.AreEqual(lines[13], "{\"a\":\"d:2015-06-09\", \"b\":\"h:01:02:03\"},");
            Assert.AreEqual(lines[14], "{\"a\":\"t:2011-06-06T12:26:58.069Z UTC\", \"b\":\"u:foo.txt\"},");
            Assert.AreEqual(lines[15], "{\"a\":\"r:abc\", \"b\":\"r:abc A B C\"},");
            Assert.AreEqual(lines[16], "{\"a\":\"b:text/plain\", \"b\":\"c:90.0,-123.0\"}");
            Assert.AreEqual(lines[17], "]");
            Assert.AreEqual(lines[18], "}");
        }
        public void testBasics()
        {
            HDict tags = new HDictBuilder()
                         .add("id", HRef.make("aaaa-bbbb"))
                         .add("site")
                         .add("geoAddr", "Richmond, Va")
                         .add("area", 1200, "ft")
                         .add("date", HDate.make(2000, 12, 3))
                         .add("null", (HVal)null)
                         .toDict();

            // size
            Assert.AreEqual(tags.size(), 5);
            Assert.IsFalse(tags.isEmpty());

            // configured tags
            Assert.IsTrue(tags.get("id").hequals(HRef.make("aaaa-bbbb")));
            Assert.IsTrue(tags.get("site").hequals(HMarker.VAL));
            Assert.IsTrue(tags.get("geoAddr").hequals(HStr.make("Richmond, Va")));
            Assert.IsTrue(tags.get("area").hequals(HNum.make(1200, "ft")));
            Assert.IsTrue(tags.get("date").hequals(HDate.make(2000, 12, 3)));
            Assert.AreEqual(tags.get("null", false), null);
            try
            {
                tags.get("null");
                Assert.Fail();
            }
            catch (HaystackUnknownNameException)
            {
                Assert.IsTrue(true);
            }

            // missing tag
            Assert.IsFalse(tags.has("foo"));
            Assert.IsTrue(tags.missing("foo"));
            Assert.IsNull(tags.get("foo", false));
            try { tags.get("foo"); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); }
            try { tags.get("foo", true); Assert.Fail(); } catch (HaystackUnknownNameException) { Assert.IsTrue(true); }
        }
Exemplo n.º 11
0
        public void testTicks()
        {
            HDate     date    = HDate.make(2014, 12, 24);
            HTime     time    = HTime.make(11, 12, 13, 456);
            HTimeZone newYork = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (newYork == null)
            {
                return;
            }
            long utcTicks = 635550163334560000L; //635550163334560000

            HDateTime a = HDateTime.make(date, time, newYork);
            //  Not valid for us - HDateTime b = HDateTime.make(date, time, newYork, a.tzOffset);
            HDateTime c = HDateTime.make(utcTicks, newYork);
            HDateTime d = HDateTime.make("2014-12-24T11:12:13.456-05:00 New_York", false);

            Assert.AreEqual(a.Ticks, utcTicks);
            //Not Valid for us - Assert.AreEqual(b.millis(), utcTicks);
            Assert.AreEqual(c.Ticks, utcTicks);
            Assert.AreEqual(d.Ticks, utcTicks);
        }
Exemplo n.º 12
0
        public void testDateTime()
        {
            HaystackToken dt     = HaystackToken.dateTime;
            HTimeZone     ny     = HTimeZone.make("New_York", false);
            HTimeZone     utc    = HTimeZone.UTC;
            HTimeZone     london = HTimeZone.make("London", false);

            // Ignore issues with locally installed timezones.
            if (ny != null)
            {
                verifyToks("2016-01-13T09:51:33-05:00 New_York", new object[] { dt, HDateTime.make(2016, 1, 13, 9, 51, 33, ny /*, tzOffset(-5, 0)*/) });
                verifyToks("2016-01-13T09:51:33.353-05:00 New_York", new object[] { dt, HDateTime.make(HDate.make(2016, 1, 13), HTime.make(9, 51, 33, 353), ny /*, tzOffset(-5, 0)*/) });
            }
            verifyToks("2010-12-18T14:11:30.924Z", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), utc) });
            verifyToks("2010-12-18T14:11:30.924Z UTC", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), utc) });
            // Ignore issues with locally installed timezones.
            if (london != null)
            {
                verifyToks("2010-12-18T14:11:30.924Z London", new object[] { dt, HDateTime.make(HDate.make(2010, 12, 18), HTime.make(14, 11, 30, 924), london) });
            }
            // Apparently PST8PDT is not valid in java? - Not tested for windows either
            //    verifyToks("2015-01-02T06:13:38.701-08:00 PST8PDT", new Object[] {dt, HDateTime.make(HDate.make(2015,1,2), HTime.make(6,13,38,701), HTimeZone.make("PST8PDT"), tzOffset(-8,0))});
            var tz = HTimeZone.make("GMT+5", false);

            // Ignore issues with locally installed timezones.
            if (tz != null)
            {
                verifyToks("2010-03-01T23:55:00.013-05:00 GMT+5", new object[] { dt, HDateTime.make(HDate.make(2010, 3, 1), HTime.make(23, 55, 0, 13), tz /*, tzOffset(-5, 0)*/) });
            }
            tz = HTimeZone.make("GMT-10", false);
            // Ignore issues with locally installed timezones.
            if (tz != null)
            {
                verifyToks("2010-03-01T23:55:00.013+10:00 GMT-10 ", new object[] { dt, HDateTime.make(HDate.make(2010, 3, 1), HTime.make(23, 55, 0, 13), tz /*, tzOffset(10, 0)*/) });
            }
        }
 public void testZinc()
 {
     verifyZinc(HDate.make(2011, 6, 7), "2011-06-07");
     verifyZinc(HDate.make(2011, 10, 10), "2011-10-10");
     verifyZinc(HDate.make(2011, 12, 31), "2011-12-31");
 }
        public void testRange()
        {
            HTimeZone ny = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (ny == null)
            {
                return;
            }
            HDate     today     = HDate.today();
            HDate     yesterday = today.minusDays(1);
            HDate     x         = HDate.make(2011, 7, 4);
            HDate     y         = HDate.make(2011, 11, 4);
            HDateTime xa        = HDateTime.make(x, HTime.make(2, 30), ny);
            HDateTime xb        = HDateTime.make(x, HTime.make(22, 5), ny);

            verifyRange(HDateTimeRange.make("today", ny), today, today);
            verifyRange(HDateTimeRange.make("yesterday", ny), yesterday, yesterday);
            verifyRange(HDateTimeRange.make("2011-07-04", ny), x, x);
            verifyRange(HDateTimeRange.make("2011-07-04,2011-11-04", ny), x, y);
            verifyRange(HDateTimeRange.make("" + xa + "," + xb, ny), xa, xb);

            HDateTimeRange r = HDateTimeRange.make(xb.ToString(), ny);

            Assert.IsTrue(r.Start.hequals(xb));
            Assert.IsTrue(r.End.date.hequals(today));
            Assert.IsTrue(r.End.TimeZone.hequals(ny));

            // this week
            HDate sun = today;
            HDate sat = today;

            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisWeek(ny), sun, sat);

            // this month
            HDate first = today;
            HDate last  = today;

            while (first.Day > 1)
            {
                first = first.minusDays(1);
            }
            while (last.Day < DateTime.DaysInMonth(today.Year, today.Month))
            {
                last = last.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisMonth(ny), first, last);

            // this year
            first = HDate.make(today.Year, 1, 1);
            last  = HDate.make(today.Year, 12, 31);
            verifyRange(HDateTimeRange.thisYear(ny), first, last);

            // last week
            HDate prev = today.minusDays(7);

            sun = prev;
            sat = prev;
            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.lastWeek(ny), sun, sat);

            // last month
            last = today;
            while (last.Month == today.Month)
            {
                last = last.minusDays(1);
            }
            first = HDate.make(last.Year, last.Month, 1);
            verifyRange(HDateTimeRange.lastMonth(ny), first, last);

            // last year
            first = HDate.make(today.Year - 1, 1, 1);
            last  = HDate.make(today.Year - 1, 12, 31);
            verifyRange(HDateTimeRange.lastYear(ny), first, last);
        }
Exemplo n.º 15
0
        public void testDate()
        {
            HaystackToken date = HaystackToken.date;

            verifyToks("2016-06-06", new object[] { date, HDate.make(2016, 6, 6) });
        }
Exemplo n.º 16
0
        public void testZinc()
        {
            verifyZinc(
                HRow.Empty,
                "{}");
            verifyZinc(
                BuildRows(new[] { "fooBar" }, new[] { HNum.make(123, "ft") }).First(),
                "{fooBar:123ft}");
            verifyZinc(
                BuildRows(new[] { "dis", "bday", "marker" }, new HVal[] { HStr.make("Bob"), HDate.make(1970, 6, 3), HMarker.VAL }).First(),
                "{dis:\"Bob\" bday:1970-06-03 marker}");

            // nested dict
            verifyZinc(
                BuildRows(new[] { "auth" }, new HVal[] { HDict.Empty }).First(),
                "{auth:{}}");
            verifyZinc(
                BuildRows(new[] { "auth" }, BuildRows(new[] { "alg", "c", "marker" }, new HVal[] { HStr.make("scram"), HNum.make(10000), HMarker.VAL }).ToArray()).First(),
                "{auth:{alg:\"scram\" c:10000 marker}}");

            // nested list
            verifyZinc(
                BuildRows(new[] { "arr", "x" }, new HVal[] { HList.make(new HVal[] { HNum.make(1.0), HNum.make(2), HNum.make(3) }), HMarker.VAL }).First(),
                "{arr:[1,2,3] x}"); // Was "{arr:[1.0,2,3] x}" - double in .NET will not recognise the difference between 1.0 and 1
        }
        public void testRange()
        {
            HTimeZone ny = HTimeZone.make("New_York", false);

            // Ignore issues with locally installed timezones.
            if (ny == null)
            {
                return;
            }
            HDate     today     = HDate.today();
            HDate     yesterday = today.minusDays(1);
            HDate     x         = HDate.make(2011, 7, 4);
            HDate     y         = HDate.make(2011, 11, 4);
            HDateTime xa        = HDateTime.make(x, HTime.make(2, 30), ny);
            HDateTime xb        = HDateTime.make(x, HTime.make(22, 5), ny);

            // this week
            HDate sun = today;
            HDate sat = today;

            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisWeek(ny), sun, sat);

            // this month
            HDate first = today;
            HDate last  = today;

            while (first.Day > 1)
            {
                first = first.minusDays(1);
            }
            while (last.Day < DateTime.DaysInMonth(today.Year, today.Month))
            {
                last = last.plusDays(1);
            }
            verifyRange(HDateTimeRange.thisMonth(ny), first, last);

            // this year
            first = HDate.make(today.Year, 1, 1);
            last  = HDate.make(today.Year, 12, 31);
            verifyRange(HDateTimeRange.thisYear(ny), first, last);

            // last week
            HDate prev = today.minusDays(7);

            sun = prev;
            sat = prev;
            while (sun.weekday() > DayOfWeek.Sunday)
            {
                sun = sun.minusDays(1);
            }
            while (sat.weekday() < DayOfWeek.Saturday)
            {
                sat = sat.plusDays(1);
            }
            verifyRange(HDateTimeRange.lastWeek(ny), sun, sat);

            // last month
            last = today;
            while (last.Month == today.Month)
            {
                last = last.minusDays(1);
            }
            first = HDate.make(last.Year, last.Month, 1);
            verifyRange(HDateTimeRange.lastMonth(ny), first, last);

            // last year
            first = HDate.make(today.Year - 1, 1, 1);
            last  = HDate.make(today.Year - 1, 12, 31);
            verifyRange(HDateTimeRange.lastYear(ny), first, last);
        }
Exemplo n.º 18
0
 public void testDateTime()
 {
     verifyParse("foo < 2009-10-30", HFilter.lt("foo", HDate.make("2009-10-30")));
     verifyParse("foo < 08:30:00", HFilter.lt("foo", HTime.make("08:30:00")));
     verifyParse("foo < 13:00:00", HFilter.lt("foo", HTime.make("13:00:00")));
 }