Esempio n. 1
0
        public virtual void TestStringtoTime_Ticks()
        {
            long time = DateTools.StringToTime("197001010000", NumericRepresentation.TICKS);

            // we use default locale since LuceneTestCase randomizes it
            //Calendar cal = new GregorianCalendar(TimeZone.GetTimeZone("GMT"), Locale.Default);
            //cal.Clear();

            DateTime cal = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); //new GregorianCalendar().ToDateTime(1970, 1, 1, 0, 0, 0, 0); // hour, minute, second -  year=1970, month=january, day=1

            //cal.set(DateTime.MILLISECOND, 0);
            Assert.AreEqual(cal.Ticks, time);

            cal = new DateTime(1980, 2, 2, 11, 5, 0, 0, DateTimeKind.Utc); //new GregorianCalendar().ToDateTime(1980, 2, 2, 11, 5, 0, 0); // hour, minute, second -  year=1980, month=february, day=2
            //cal.set(DateTime.MILLISECOND, 0);
            time = DateTools.StringToTime("198002021105", NumericRepresentation.TICKS);
            Assert.AreEqual(cal.Ticks, time);
        }
Esempio n. 2
0
        public virtual void TestDateToolsUTC()
        {
            /*// Sun, 30 Oct 2005 00:00:00 +0000 -- the last second of 2005's DST in Europe/London
             * long time = 1130630400;
             * try
             * {
             *  TimeZone.Default = TimeZone.getTimeZone("Europe/London"); // "GMT"
             *  string d1 = DateTools.DateToString(new DateTime(time * 1000), DateTools.Resolution.MINUTE);
             *  string d2 = DateTools.DateToString(new DateTime((time+3600) * 1000), DateTools.Resolution.MINUTE);
             *  Assert.IsFalse(d1.Equals(d2, StringComparison.Ordinal), "different times");
             *  Assert.AreEqual(DateTools.StringToTime(d1), time * 1000, "midnight");
             *  Assert.AreEqual(DateTools.StringToTime(d2), (time+3600) * 1000, "later");
             * }
             * finally
             * {
             *  TimeZone.Default = null;
             * }*/

            // Sun, 30 Oct 2005 00:00:00 +0000 -- the last second of 2005's DST in Europe/London
            //long time = 1130630400;
            DateTime time1 = new DateTime(2005, 10, 30);
            DateTime time2 = time1.AddHours(1);

            try
            {
                //TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); // {{Aroush-2.0}} need porting 'java.util.TimeZone.getTimeZone'
                System.DateTime tempAux  = time1;
                System.String   d1       = DateTools.DateToString(tempAux, DateTools.Resolution.MINUTE);
                System.DateTime tempAux2 = time2;
                System.String   d2       = DateTools.DateToString(tempAux2, DateTools.Resolution.MINUTE);
                Assert.IsFalse(d1.Equals(d2, StringComparison.Ordinal), "different times");
                Assert.AreEqual(DateTools.StringToTime(d1), time1.Ticks, "midnight");
                Assert.AreEqual(DateTools.StringToTime(d2), time2.Ticks, "later");
            }
            finally
            {
                //TimeZone.SetDefault(null);    // {{Aroush-2.0}} need porting 'java.util.TimeZone.setDefault'
            }
        }
Esempio n. 3
0
        public virtual void TestDateToolsUTC_DateTimeOffset_TicksAsMilliseconds()
        {
            // Sun, 30 Oct 2005 00:00:00 +0000 -- the last second of 2005's DST in Europe/London
            //long time = 1130630400;
            DateTimeOffset time1 = new DateTimeOffset(2005, 10, 30, 0, 0, 0, TimeSpan.Zero);
            DateTimeOffset time2 = time1.AddHours(1);

            {
                TimeZoneInfo   timeZone = TZConvert.GetTimeZoneInfo("Europe/London");
                DateTimeOffset tempAux  = TimeZoneInfo.ConvertTime(time1, timeZone);
                string         d1       = DateTools.DateToString(tempAux, DateResolution.MINUTE);
                DateTimeOffset tempAux2 = TimeZoneInfo.ConvertTime(time2, timeZone);
                string         d2       = DateTools.DateToString(tempAux2, DateResolution.MINUTE);
                Assert.IsFalse(d1.Equals(d2, StringComparison.Ordinal), "different times");
                Assert.AreEqual(DateTools.StringToTime(d1, NumericRepresentation.TICKS_AS_MILLISECONDS), time1.Ticks / TimeSpan.TicksPerMillisecond, "midnight");
                Assert.AreEqual(DateTools.StringToTime(d2, NumericRepresentation.TICKS_AS_MILLISECONDS), time2.Ticks / TimeSpan.TicksPerMillisecond, "later");
            }

            {
                string d1 = DateTools.DateToString(time1, DateResolution.MINUTE);
                string d2 = DateTools.DateToString(time2, DateResolution.MINUTE);
                Assert.IsFalse(d1.Equals(d2, StringComparison.Ordinal), "different times");
                Assert.AreEqual(DateTools.StringToTime(d1, NumericRepresentation.TICKS_AS_MILLISECONDS), time1.Ticks / TimeSpan.TicksPerMillisecond, "midnight");
                Assert.AreEqual(DateTools.StringToTime(d2, NumericRepresentation.TICKS_AS_MILLISECONDS), time2.Ticks / TimeSpan.TicksPerMillisecond, "later");
            }

            time1 = new DateTimeOffset(2005, 10, 30, 0, 0, 0, TimeSpan.Zero).ToLocalTime();
            time2 = time1.AddHours(1);

            {
                string d1 = DateTools.DateToString(time1, DateResolution.MINUTE);
                string d2 = DateTools.DateToString(time2, DateResolution.MINUTE);
                Assert.IsFalse(d1.Equals(d2, StringComparison.Ordinal), "different times");
                Assert.AreEqual(DateTools.StringToTime(d1, NumericRepresentation.TICKS_AS_MILLISECONDS), time1.ToUniversalTime().Ticks / TimeSpan.TicksPerMillisecond, "midnight");
                Assert.AreEqual(DateTools.StringToTime(d2, NumericRepresentation.TICKS_AS_MILLISECONDS), time2.ToUniversalTime().Ticks / TimeSpan.TicksPerMillisecond, "later");
            }
        }