예제 #1
0
        public void testZinc()
        {
            TimeZoneInfo tziNewYork;

            try
            {
                tziNewYork = TimeZoneConverter.TZConvert.GetTimeZoneInfo("Eastern Standard Time");
            }
            catch
            {
                // Ignore issues with locally installed timezones.
                return;
            }
            var       tz = HTimeZone.make("New_York", false);
            HDateTime ts;

            // Ignore issues with locally installed timezones.
            if (tz != null)
            {
                ts = HDateTime.make(634429600180690000L, tz);
                verifyZinc(ts, "2011-06-06T12:26:58.069-05:00 New_York");
                Assert.AreEqual(ts.date.ToString(), "2011-06-06");
                Assert.AreEqual(ts.time.ToString(), "12:26:58.069");
                Assert.AreEqual(ts.Offset.TotalSeconds, -5 * 60 * 60);
                Assert.AreEqual(ts.TimeZone.dntz, tziNewYork);
                Assert.AreEqual(ts.Ticks, 634429600180690000L);
            }

            // convert back to millis
            ts = HDateTime.make("2011-06-06T12:26:58.069-04:00 New_York", false);
            // Ignore issues with locally installed timezones.
            if (ts != null)
            {
                Assert.AreEqual(ts.Ticks, 634429600180690000L);
            }

            // different timezones
            ts = HDateTime.make(630850574400000000L, HTimeZone.make("New_York", false));
            // Ignore issues with locally installed timezones.
            if (ts != null)
            {
                verifyZinc(ts, "2000-02-02T03:04:00-05:00 New_York");
            }
            ts = HDateTime.make(630850754400000000L, HTimeZone.make("UTC", false));
            // Ignore issues with locally installed timezones.
            if (ts != null)
            {
                verifyZinc(ts, "2000-02-02T08:04:00Z UTC");
            }
            ts = HDateTime.make(630851042400000000L, HTimeZone.make("Taipei", false));
            // Ignore issues with locally installed timezones.
            if (ts != null)
            {
                verifyZinc(ts, "2000-02-02T16:04:00+08:00 Taipei");
                verifyZinc(HDateTime.make("2011-06-07T11:03:43-10:00 GMT+10", false),
                           "2011-06-07T11:03:43-10:00 GMT+10");
                verifyZinc(HDateTime.make("2011-06-08T04:07:33.771+07:00 GMT-7", false),
                           "2011-06-08T04:07:33.771+07:00 GMT-7");
            }
        }
        private void verifyTz(string name, params string[] dntzIds)
        {
            HTimeZone tz = HTimeZone.make(name, false);

            // Ignore issues with locally installed timezones.
            if (tz == null)
            {
                return;
            }
            TimeZoneInfo dntz = tz.dntz;

            Assert.AreEqual(tz.ToString(), name);
            Assert.IsTrue(dntzIds.Contains(dntz.Id), $"{dntz.Id} not in [{string.Join(", ", dntzIds)}]");
            // TODO: What is this testing? Move into another test?
            //TimeZoneInfo dntzByID = TimeZoneConverter.TZConvert.GetTimeZoneInfo(dntz.Id);
            //Assert.IsTrue(tz.hequals(HTimeZone.make(dntzByID, false)), $"{tz} does not equal {dntzByID}");
        }
예제 #3
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], "}");
        }
        private void verifyMidnight(HDate date, string tzName, string str)
        {
            var tz = HTimeZone.make(tzName, false);

            // Ignore issues with locally installed timezones.
            if (tz == null)
            {
                return;
            }
            HDateTime ts = date.midnight(tz);

            Assert.AreEqual(ts.date, date);
            Assert.AreEqual(ts.time.Hour, 0);
            Assert.AreEqual(ts.time.Minute, 0);
            Assert.AreEqual(ts.time.Second, 0);
            Assert.AreEqual(ts.ToString(), str);
            Assert.IsTrue(ts.hequals(read(ts.toZinc())));
            Assert.AreEqual(ts.Ticks, ((HDateTime)read(str)).Ticks);
        }
예제 #5
0
        private void verifyTz(string name, string dntzId)
        {
            HTimeZone tz = HTimeZone.make(name, false);

            // Ignore issues with locally installed timezones.
            if (tz == null)
            {
                return;
            }
            TimeZoneInfo dntz = tz.dntz;

            Assert.AreEqual(tz.ToString(), name);
            Assert.AreEqual(dntz.Id, dntzId);
            try
            {
                TimeZoneInfo dntzByID = TimeZoneInfo.FindSystemTimeZoneById(dntzId);
                Assert.IsTrue(tz.hequals(HTimeZone.make(dntzByID, false)));
            }
            catch (Exception)
            {
                Assert.Fail();
            }
        }
예제 #6
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);
        }
예제 #7
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 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);
        }
        public void make_sidney()
        {
            var tz = HTimeZone.make("Sydney", false);

            Assert.IsTrue(new[] { "AUS Eastern Standard Time", "Australia/Sydney" }.Contains(tz.dntz.Id));
        }
        public void make_utc()
        {
            var tz = HTimeZone.make("UTC", false);

            Assert.IsTrue(new[] { "UTC", "Etc/UTC" }.Contains(tz.dntz.Id));
        }
        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);
        }