Beispiel #1
0
        public void Validate_Timestamp(DateTime testTimestamp)
        {
            HdDateTime time = new HdDateTime(testTimestamp);

            Assert.IsTrue(time.DateTime == testTimestamp,
                          String.Format("DateTime {0} != {1}", time.DateTime.Ticks, testTimestamp.Ticks));
        }
Beispiel #2
0
        public void Validate_Nanoseconds(Int64 nanoseconds)
        {
            HdDateTime time = new HdDateTime(nanoseconds);

            Assert.IsTrue(time.EpochNanoseconds == nanoseconds,
                          String.Format("Nanoseconds : {0} != {1}", time.EpochNanoseconds, nanoseconds));
        }
Beispiel #3
0
        void GoToNextBreakPoint(HdDateTime destinationTime)
        {
            if (needPop)
            {
                memoryManager.Delete(breakPoints.Pop().Value);
            }
            if (breakPoints.Count == 0)
            {
                needPop = false;
                return;
            }
            BreakPoint breakPoint = breakPoints.Peek.Value;

            if (breakPoint.Time > destinationTime)
            {
                needPop = false;
                return;
            }
            needPop = true;
            long numberOfMessage = breakPoint.NumberOfMessage;

            CurrentTime = breakPoint.Time;
            int key = (int)breakPoint.Key;

            breakPoint.BreakPointAction(CurrentTime, breakPoint.CustomData);
        }
Beispiel #4
0
        /// <summary>
        /// Add new breakpoint to this provider.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="time">Time of new breakpoint.</param>
        /// <param name="context">Context of new breakpoint.</param>
        /// <param name="action">Action which will be called on new breakpoint.</param>
        /// <param name="priority">Priority of new breakpoint(breakpoints with lesser priority with same time called earlier).</param>
        /// <returns>Key of this breakpoint(positive ingeger number) or -1(if we can't add this breakpoint(For example time less than currentTime))</returns>
        public long AddBreakPoint <T>(HdDateTime time, T context, Action <HdDateTime, object> action, int priority = 0)
        {
            if (time < CurrentTime)
            {
                return(-1);
            }
            key++;
            BreakPoint breakPoint = memoryManager.New();

            breakPoint.Time             = time;
            breakPoint.CustomData       = context;
            breakPoint.Priority         = priority;
            breakPoint.BreakPointAction = action;
            breakPoint.NumberOfMessage  = key;
            int _key;

            if (needPop)
            {
                memoryManager.Delete(breakPoints.Peek.Value);
                _key    = breakPoints.ModifyTop(breakPoint).Key;
                needPop = false;
            }
            else
            {
                _key = breakPoints.Add(breakPoint);
            }
            breakPoint.Key = _key;
            return(_key);
        }
Beispiel #5
0
        public static Boolean TryParse(String source, IFormatProvider formatProvider, out HdDateTime hdDateTime)
        {
            if (String.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException("source", "source is null.");
            }

            Byte  preciseTimeSource;
            Int32 preciseTimeCount, preciseTimePosition;

            // find and replace preciseTime source
            Boolean isPreciseTimeFormat = Formatter.FindAndReplacePreciseTimeSource(source, out preciseTimeSource, out preciseTimeCount, out preciseTimePosition);

            // parse time
            DateTime dateTime;
            Boolean  isSuccessfullyParsed = false;

            try
            {
                isSuccessfullyParsed = DateTime.TryParse(source, formatProvider, DateTimeStyles.None, out dateTime);
                hdDateTime           = new HdDateTime(dateTime, preciseTimeSource);
                return(isSuccessfullyParsed);
            }

            finally
            {
                // rollback replacement
                if (isPreciseTimeFormat)
                {
                    Formatter.RollbackPreciseTimeSourceReplacement(source, preciseTimePosition, preciseTimeCount, preciseTimeSource);
                }
            }
        }
Beispiel #6
0
        // this method is unused, because it can partically format timestamp, including intermediate nanoseconds format.
        private static String FormatMiddleOccurences(HdDateTime time, String format, IFormatProvider formatProvider)
        {
            if (String.IsNullOrEmpty(format))
            {
                format = HdDateTimeFormatter.GetDefaultFormat();
            }

            // takes away all precise time formats.
            MutableString dateTimeFormat;
            IDictionary <Int32, String> preciseTimeFormats;
            Boolean isPreciseTimeFormat = HdDateTimeFormatter.TakeAwayPreciseTimeFormat(format, out dateTimeFormat, out preciseTimeFormats);

            if (!isPreciseTimeFormat)
            {
                return(time.RawDateTime.ToString(format, formatProvider));
            }

            Byte timestampModulo = time.TimestampModulo;

            // in case, when preciseTime is GMT time with nanos component we skip its formatting
            if (time.Nanoseconds / 100 != 0)
            {             // replace all upper case FFFF symbols with ffff, in case, when whey are upper case and timestamp ticks != 0
                CorrectDateTimeFormat(dateTimeFormat, preciseTimeFormats, timestampModulo);
            }

            MutableString preciseTimeFormattingResult = FormatTimestamp(time.RawDateTime, dateTimeFormat.ToString(), formatProvider);

            ValidateDateTimeFormat(format, preciseTimeFormattingResult);
            FormatTimestampModuloOccurences(timestampModulo, preciseTimeFormats, preciseTimeFormattingResult);

            return(preciseTimeFormattingResult.ToString());
        }
Beispiel #7
0
        /// <summary>
        ///   Converts the specified string representation of a date and time to its <see cref="HdDateTime" /> equivalent and
        ///   returns a value that indicates whether the conversion succeeded. The format of the string representation must match
        ///   the specified format exactly.
        /// </summary>
        /// <param name="source">A string containing a date and time to convert.</param>
        /// <param name="format">
        ///   A format specifier, that defines the required format of <paramref name="source" />. The format of
        ///   the string representation must match the specified format exactly.
        /// </param>
        /// <param name="result">
        ///   An object that is equivalent to the date and time contained in <paramref name="source" />, as specified by
        ///   <paramref name="format" />.
        /// </param>
        /// <returns>
        ///   A value that indicates whether the conversion succeeded.
        /// </returns>
        /// <remarks>
        ///   A date and time format, which can be the same as <see cref="System.DateTime" /> format. If you want to specify
        ///   nanoseconds formatting, you can use "FFFFFFFFF" (9 Fs) or "fffffffff" (9 fs).
        /// </remarks>
        public Boolean TryParseExact(String source, String format, out HdDateTime result)
        {
            String ownSource = String.Copy(source);
            String ownFormat = GetAllocatedFormat(format);

            return(PreciseTimeParse.TryParseExact(ownSource, ownFormat, null, out result));
        }
Beispiel #8
0
        public void TestParseExact(String testFormat)
        {
            HdDateTimeParser parser          = new HdDateTimeParser();
            String           immutableFormat = String.Copy(testFormat);

            foreach (HdDateTime testValue in TestHdDateDates)
            {
                String source          = testValue.ToString(testFormat);
                String immutableSource = String.Copy(source);

                HdDateTime parsedValue = parser.ParseExact(source, testFormat);
                if (testFormat.ToLower().Contains("ffffffff") && !testFormat.ToLower().Contains("fffffffff"))
                {
                    Assert.IsTrue(testValue.EpochNanoseconds / 10 == parsedValue.EpochNanoseconds / 10,
                                  String.Format("{0} != {1}.", testValue.EpochNanoseconds, parsedValue.EpochNanoseconds));
                }
                else if (testValue.TimestampModulo != 0)
                {
                    Assert.IsTrue(testValue == parsedValue,
                                  String.Format("{0} != {1}.", testValue.EpochNanoseconds, parsedValue.EpochNanoseconds));
                }
                else
                {
                    Assert.IsTrue(testValue.DateTime == parsedValue.DateTime,
                                  String.Format("{0} != {1}.", testValue.EpochNanoseconds, parsedValue.EpochNanoseconds));
                }

                Assert.IsTrue(immutableFormat == testFormat, "Format has been changed.");
                Assert.IsTrue(immutableSource == source, "Source has been changed.");
            }
        }
Beispiel #9
0
        // TODO: WIP On new range checks
        //[Test]
        public void TestMinvalueConversion()
        {
            HdDateTime time1 = HdDateTime.MinValue;
            HdDateTime time2 = time1.Add(new HdTimeSpan(10));

            var dt = time2.Date;
        }
Beispiel #10
0
        /// <summary>
        /// Move current time to new time.
        /// </summary>
        /// <param name="time">New time of time provider.</param>
        public void GoToTime(HdDateTime time)
        {
            while (breakPoints.Count > 0 && breakPoints.Peek.Value.Time <= time)
            {
                GoToNextBreakPoint(time);
            }

            CurrentTime = time;
        }
Beispiel #11
0
        public void TestSubtractDates(DateTime a, DateTime b)
        {
            TimeSpan timeSpan = a - b;

            HdDateTime hdA        = a;
            HdDateTime hdB        = b;
            HdTimeSpan hdTimeSpan = hdA - hdB;

            Assert.IsTrue(hdTimeSpan == timeSpan);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            HdDateTime dt = new HdDateTime(2000, 1, 1, 1, 1, 1, 12);

            Console.WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            Console.WriteLine(dt.ToString("yyyy-MM-dd HH:mm:ss.ff"));

            SimpleBenchmark.Run();
            //Scratchpad();
        }
Beispiel #13
0
        public void TestModuloNegative()
        {
            HdDateTime dt = new HdDateTime(123);

            Assert.AreEqual(23, (dt - new HdTimeSpan(1000000000000L)).TimestampModulo);
            dt = new HdDateTime(new DateTime(1971, 1, 1), 42);
            Assert.AreEqual(42, dt.TimestampModulo);
            Assert.AreEqual(42, (dt - thousandDays).TimestampModulo);
            Assert.AreEqual(42, (dt + thousandDays - thousandDays + day).TimestampModulo);
        }
Beispiel #14
0
        public void CheckPrint(String str, String fmt, HdDateTime dt)
        {
            Assert.AreEqual(str, dt.ToString(fmt));

            // TODO: Enable later
            //Assert.AreEqual(dt.DateTime.ToString(), ((HdDateTime)(dt.DateTime)).ToString(fmt));

            //StringBuilder sb = new StringBuilder();
            //Assert.AreEqual(str, num.appendTo(sb, fmt).toString());
        }
Beispiel #15
0
        public void TestMinMaxVsDateTime()
        {
            HdDateTime maxValue = HdDateTime.MaxValue;
            HdDateTime minValue = HdDateTime.MinValue;

            // Min/Max casts are a special case, treated like +Inf, -Inf, should be equal
            Assert.True(HdDateTime.MaxValue == DateTime.MaxValue);
            Assert.True(HdDateTime.MinValue == DateTime.MinValue);

            for (int i = 1; i < 0x400; ++i)
            // But in reality HdDateTime representable time interval is much smaller
            // and we are going to test this and also the validity of our typecasts
            {
                // Exceptions are slow, so don't test each iteration
                if (i < 120 || (i & 3) == 0)
                {
                    Assert.Throws <ArgumentOutOfRangeException>(
                        () => ToVoid((HdDateTime)DateTime.MaxValue.AddTicks(-i)));
                    Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                ToVoid((HdDateTime)DateTime.MinValue.AddTicks(i)));

                    // Maybe there is a point in implementing comparison with out-of-range DateTime
                    // but currently this throws
                    Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                ToVoid(maxValue < (HdDateTime)DateTime.MaxValue.AddTicks(-i)));
                    Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                                ToVoid(minValue > (HdDateTime)DateTime.MinValue.AddTicks(i)));
                }

                Assert.True(maxValue > ((HdDateTime)DateTime.MaxValue).AddNanoseconds(-i));
                Assert.True(minValue < ((HdDateTime)DateTime.MinValue).AddNanoseconds(i));
                Assert.True(maxValue > ((HdDateTime)DateTime.MaxValue).AddTicks(-i));
                Assert.True(minValue < ((HdDateTime)DateTime.MinValue).AddTicks(i));

                Assert.True(maxValue.AddNanoseconds(-i) < DateTime.MaxValue);
                Assert.True(minValue.AddNanoseconds(i) > DateTime.MinValue);
                Assert.True(maxValue.AddTicks(-i) < DateTime.MaxValue);
                Assert.True(minValue.AddTicks(i) > DateTime.MinValue);
                Assert.True(maxValue.AddMilliseconds(-i) < DateTime.MaxValue);
                Assert.True(minValue.AddMilliseconds(i) > DateTime.MinValue);

                Assert.True((DateTime)maxValue.AddNanoseconds(-i) < DateTime.MaxValue);
                Assert.True((DateTime)minValue.AddNanoseconds(i) > DateTime.MinValue);
                Assert.True((DateTime)maxValue.AddTicks(-i) < DateTime.MaxValue);
                Assert.True((DateTime)minValue.AddTicks(i) > DateTime.MinValue);
                Assert.True((DateTime)maxValue.AddMilliseconds(-i) < DateTime.MaxValue);
                Assert.True((DateTime)minValue.AddMilliseconds(i) > DateTime.MinValue);

                // Must add at least 1 nanosecond to avoid Max<=>Max Min<=>Min conversion
                Assert.True(((DateTime)maxValue.AddNanoseconds(-1)).AddTicks(-i) < DateTime.MaxValue);
                Assert.True(((DateTime)maxValue.AddNanoseconds(-1)).AddTicks(i) < DateTime.MaxValue);
                Assert.True(((DateTime)minValue.AddNanoseconds(1)).AddTicks(-i) > DateTime.MinValue);
                Assert.True(((DateTime)minValue.AddNanoseconds(1)).AddTicks(i) > DateTime.MinValue);
            }
        }
Beispiel #16
0
        public void Validate_ToJavaMilliseconds(DateTime testValue)
        {
            Int64      javaMillisecondsModulo;
            HdDateTime d1 = new HdDateTime(testValue);
            Int64      javaMilliseconds = DateConverter.ToEpochMilliseconds(testValue, out javaMillisecondsModulo);
            DateTime   timestamp        = HdDateTime.FromEpochMilliseconds(javaMilliseconds, javaMillisecondsModulo).DateTime;

            Assert.AreEqual(testValue, d1.DateTime);
            //Assert.AreEqual(timestamp.Ticks, testValue.Ticks, String.Format("{0} != {1}", timestamp.Ticks, testValue.Ticks));
            Assert.AreEqual(testValue, timestamp, String.Format("{0} != {1}", timestamp.Ticks, testValue.Ticks));
        }
Beispiel #17
0
        private void CheckParse(String from, String fmt, HdDateTime expected)
        {
            HdDateTime parsed = HdDateTime.Parse(from, fmt);

            if (!expected.Equals(parsed))
            {
                // Comparison is here to avoid problems with Formatter affecting tests for Parser
                Assert.AreEqual(expected, parsed);
                Assert.AreEqual(expected.ToString(), parsed.ToString());
            }

            Assert.AreEqual(expected.EpochNanoseconds, parsed.EpochNanoseconds);
        }
Beispiel #18
0
        public void Validate_TimestampAndTimestampModulo(DateTime testTimestamp, Byte testTimestampModulo)
        {
            HdDateTime time = new HdDateTime(testTimestamp, testTimestampModulo);

            Assert.IsTrue(time.DateTime == testTimestamp,
                          String.Format("Timestamp is incorrect: {0}. Must be {1}", time.DateTime.Ticks, testTimestamp.Ticks));
            if (testTimestamp != DateTime.MinValue && testTimestamp != DateTime.MaxValue)
            {
                Assert.IsTrue(
                    time.TimestampModulo == testTimestampModulo,
                    String.Format("Timestamp modulo is incorrect: {0}. Must be {1}.", time.TimestampModulo,
                                  testTimestampModulo));
            }
        }
Beispiel #19
0
        public void PrintMinMaxConstants()
        {
            HdDateTime maxValue     = HdDateTime.MaxValue;
            HdDateTime minValue     = HdDateTime.MinValue;
            var        tickNanosMin = 100 - ((DateTime)minValue.AddTicks(1) - minValue).TotalNanoseconds;
            var        tickNanosMax = (maxValue.AddTicks(-1) - (DateTime)(maxValue.AddTicks(-1))).TotalNanoseconds;

            var secondNanosMin = 1000000000 + minValue.AddSeconds(1).EpochNanoseconds % 1000000000;
            var secondNanosMax = maxValue.EpochNanoseconds % 1000000000;

            Console.WriteLine($"HDT MinValue       = {minValue.AddSeconds(1)} - 1s, {tickNanosMin} / {HdDateTime.MinValue.EpochNanoseconds}");
            Console.WriteLine($"HDT MinValue       = {minValue.RawDateTime} {secondNanosMin}");
            Console.WriteLine();
            Console.WriteLine($"HDT MaxValue       = {maxValue.AddSeconds(-1)} + 1s, {tickNanosMax} / {HdDateTime.MaxValue.EpochNanoseconds}");
            Console.WriteLine($"HDT MaxValue       = {maxValue.RawDateTime} {secondNanosMax}");
        }
Beispiel #20
0
        public void Validate_PreciseTimestamp(DateTime testTimestamp, Byte testTimestampModulo)
        {
            HdDateTime testTime = new HdDateTime(testTimestamp, testTimestampModulo);
            HdDateTime testTimeFromNanoseconds  = new HdDateTime(testTime.EpochNanoseconds);
            HdDateTime testTimeFromMilliseconds =
                HdDateTime.FromEpochMilliseconds(testTime.EpochMilliseconds, testTime.EpochMillisecondsModulo);
            HdDateTime testTimeFromTimestamp =
                new HdDateTime(testTime.DateTime, testTime.TimestampModulo);

            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromNanoseconds.EpochNanoseconds);
            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromMilliseconds.EpochNanoseconds);
            Assert.AreEqual(testTime.EpochNanoseconds, testTimeFromTimestamp.EpochNanoseconds);
            Assert.AreEqual(testTime, testTimeFromNanoseconds);
            Assert.AreEqual(testTime, testTimeFromMilliseconds);
            Assert.AreEqual(testTime, testTimeFromTimestamp);
        }
Beispiel #21
0
        private void AddXX(Func <HdDateTime, long, HdDateTime> a, Func <DateTime, long, DateTime> b)
        {
            var r = new Random();

            DateTime   dt0  = DateTime.UtcNow.AddDays((r.NextDouble() * 20 - 10) * 365);
            HdDateTime hdt0 = dt0;

            Assert.AreEqual(a(hdt0, 0L), (HdDateTime)b(dt0, 0L));

            for (int i = 0; i < 10000; ++i)
            {
                DateTime   dt = DateTime.UtcNow.AddDays((r.NextDouble() * 10 - 5) * 365);
                HdDateTime hdt = dt;
                int        value = (int)(r.NextDouble() * (Int16.MaxValue * 2.0) + Int16.MinValue);
                HdDateTime r0 = HdDateTime.MinValue, r1 = HdDateTime.MinValue;
                bool       r0ok = false, r1ok = false;
                Exception  e0 = null, e1 = null;
                try
                {
                    r0   = a(hdt, value);
                    r0ok = true;
                }
                catch (Exception e)
                {
                    e0 = e;
                }

                try
                {
                    r1   = (HdDateTime)b(dt, value);
                    r1ok = true;
                }
                catch (Exception e)
                {
                    e1 = e;
                }

                Assert.True(r0ok == r1ok && (r0ok == false || r0 == r1),
                            $"a({hdt}, {value})/{r0ok} != b({(HdDateTime) dt}, {value})/{r1ok} {(r0ok == false ? e0 : null)} {(r1ok == false ? e1 : null)}");
            }
        }
Beispiel #22
0
        public void TestMinMaxConstantsExtra()
        {
            HdDateTime maxValue = HdDateTime.MaxValue;
            HdDateTime minValue = HdDateTime.MinValue;

            var nanosMin = 100 - ((DateTime)minValue.AddTicks(1) - minValue).TotalNanoseconds;
            var nanosMax = (maxValue.AddTicks(-1) - (DateTime)(maxValue.AddTicks(-1))).TotalNanoseconds;

            var secondNanosMin = 1000000000 + minValue.AddSeconds(1).EpochNanoseconds % 1000000000;
            var secondNanosMax = maxValue.EpochNanoseconds % 1000000000;

            Assert.True(nanosMax == maxValue.AddTicks(-1).TimestampModulo);
            Assert.True(nanosMin == minValue.AddTicks(1).TimestampModulo);

            Assert.True(nanosMax == secondNanosMax % 100);
            Assert.True(nanosMin == secondNanosMin % 100);

            Assert.AreEqual(minValue.EpochNanoseconds, new HdDateTime((DateTime)minValue.AddTicks(1), (Byte)nanosMin).AddTicks(-1).EpochNanoseconds);
            Assert.True(minValue == new HdDateTime((DateTime)minValue.AddTicks(1), (Byte)nanosMin).AddTicks(-1));
            Assert.AreEqual(maxValue.EpochNanoseconds, new HdDateTime((DateTime)maxValue.AddTicks(-1), (Byte)nanosMax).AddTicks(1).EpochNanoseconds);
            Assert.True(maxValue == new HdDateTime((DateTime)maxValue.AddTicks(-1), (Byte)nanosMax).AddTicks(1));

            Assert.AreEqual(maxValue.EpochNanoseconds, HdDateTime.FromEpochMilliseconds(maxValue.EpochNanoseconds / 1000000000 * 1000, secondNanosMax).EpochNanoseconds);
        }
Beispiel #23
0
        public void TestMinMaxConstants()
        {
            HdDateTime maxValue = HdDateTime.MaxValue;
            HdDateTime minValue = HdDateTime.MinValue;

            Assert.True(maxValue > minValue);
            Assert.True(maxValue > new HdDateTime(DateTime.Now));
            Assert.True(minValue < new HdDateTime(DateTime.Now));

            Assert.True(new HdDateTime(maxValue.EpochNanoseconds + 1) > maxValue);
            Assert.True(new HdDateTime(minValue.EpochNanoseconds - 1) < minValue);

            // False actually
            //Assert.True(maxValue - minValue > new TimeSpan(0));

            Random rnd = new Random();

            for (int i = 1000000; i != 0; --i)
            {
                var t = new HdDateTime(rnd.Next() & 0xFFFFFFFFL | rnd.Next() * 0x80000000L);
                Assert.True(maxValue >= t);
                Assert.True(minValue <= t);
            }
        }
Beispiel #24
0
 /// <summary>
 /// Sets null to Timestamp property.
 /// </summary>
 public void NullifyTimeStampMs()
 {
     this._timestamp = TypeConstants.TimestampNull;
 }
Beispiel #25
0
        public void TestParse()
        {
            CheckParse("2109", "yyyy", new HdDateTime(2109, 1, 1));
            CheckParse("1864", "yyyy", new HdDateTime(1864, 1, 1));

            CheckParse("197005", "yyyyMM", new HdDateTime(1970, 5, 1));
            CheckParse("19700531 ", "yyyyMMdd ", new HdDateTime(1970, 5, 31));

            CheckParse("19700531 13", "yyyyMMdd HH",
                       new HdDateTime(1970, 5, 31, 13, 0, 0));

            CheckParse("19700531 1342", "yyyyMMdd HHmm",
                       new HdDateTime(1970, 5, 31, 13, 42, 0));

            CheckParse("19700531 134259", "yyyyMMdd HHmmss",
                       new HdDateTime(1970, 5, 31, 13, 42, 59));

            CheckParse("19700101000000", "yyyyMMddHHmmss", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000", "yyyyMMddHHmmssf", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000", "yyyyMMddHHmmssff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000", "yyyyMMddHHmmssfff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000000", "yyyyMMddHHmmssffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000000", "yyyyMMddHHmmssfffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000000", "yyyyMMddHHmmssffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000000000000", "yyyyMMddHHmmssfffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("1970010100000000000000", "yyyyMMddHHmmssffffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("19700101000000000000000", "yyyyMMddHHmmssfffffffff", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197012345678901010000000", "yyyyfffffffffMMddHHmmss",
                       HdDateTime.FromEpochNanoseconds(123456789));
            CheckParse("197012345678901010000000123456789", "yyyyfffffffffMMddHHmmss",
                       HdDateTime.FromEpochNanoseconds(123456789));

            CheckParse("197001010000 5", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(5000));
            CheckParse("197001010000 0", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(0));
            CheckParse("197001010000 005", "yyyyMMddHHmm s", HdDateTime.FromEpochMilliseconds(5000));

            CheckParse("19700101 12:34:56", "yyyyMMdd H:m:s",
                       new HdDateTime(1970, 1, 1, 12, 34, 56));

            CheckParse("19700101 9:8:7", "yyyyMMdd H:m:s",
                       new HdDateTime(1970, 1, 1, 9, 8, 7));

            CheckParse("19700101 12:34:56", "yyyyMMdd HH:mm:ss",
                       new HdDateTime(1970, 1, 1, 12, 34, 56));

            CheckParse("197001 24T12:34:56", "yyyyMM ddTH:m:s",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));
            CheckParse("197001 24T12:34:56", "yyyyMM dd'T'H:m:s",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));

            CheckParse("197001 0024123456", "yyyyMM ddddHHmmss",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));
            CheckParse("197001 0000000024123456", "yyyyMM ddddddddddHHmmss",
                       new HdDateTime(1970, 1, 24, 12, 34, 56));

            CheckParse("1999-11-22 19:18:17", "y-M-d H:m:s",
                       new HdDateTime(1999, 11, 22, 19, 18, 17));

            // Fractions (Only fixed length patterns supported)
            CheckParse("197001010000 4.2", "yyyyMMddHHmm s.f", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.200000", "yyyyMMddHHmm s.ffffff", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.020", "yyyyMMddHHmm s.ff", HdDateTime.FromEpochMilliseconds(4020));
            CheckParse("197001010000 4.200000000", "yyyyMMddHHmm s.fffffffff", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.000000002", "yyyyMMddHHmm s.fffffffff", HdDateTime.FromEpochNanoseconds(4000000002L));

            CheckParse("197001010000 4.2", "yyyyMMddHHmm s.S", HdDateTime.FromEpochMilliseconds(4200));
            CheckParse("197001010000 4.123", "yyyyMMddHHmm s.SSS", HdDateTime.FromEpochMilliseconds(4123));
        }
Beispiel #26
0
        public void TestFormat2()
        {
            // Plain numbers
            CheckPrint("34627623,.45634", "34627623,.45634", HdDateTime.FromEpochMilliseconds(12));

            // Check quoted text
            CheckPrint("Abcmsy", "'Abcmsy'", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("00Abcmsy000", "00'Abcmsy'000", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("'Abc'msy", "'''Abc''msy'", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("0'0Abc''msy00'0", "0''0'Abc''''msy'00''0", HdDateTime.FromEpochMilliseconds(0));

            // Seconds
            CheckPrint("12", "s", HdDateTime.FromEpochMilliseconds(12000));
            CheckPrint("0", "s", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("00", "ss", HdDateTime.FromEpochMilliseconds(0));
            CheckPrint("005", "0ss", HdDateTime.FromEpochMilliseconds(65000));
            CheckPrint("000005", "ssssss", HdDateTime.FromEpochMilliseconds(65000));

            // Seconds & Fractions of Second. 'S' and 'f' are now synonyms
            CheckPrint("05.0001", "ss.ffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.00012", "ss.fffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.000123", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.123000", "ss.ffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.1230009", "ss.fffffff", HdDateTime.FromEpochNanoseconds(65_123_000_999L));
            CheckPrint("05.12300012", "ss.ffffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.123000123", "ss.fffffffff", HdDateTime.FromEpochNanoseconds(65_123_000_123L));
            CheckPrint("05.000000123", "ss.fffffffff", HdDateTime.FromEpochNanoseconds(65_000_000_123L));
            CheckPrint("5.000123000", "s.fffffffff", HdDateTime.FromEpochNanoseconds(65_000_123_000L));

            CheckPrint("12.3", "s.S", HdDateTime.FromEpochMilliseconds(12_300));
            CheckPrint("0.345", "s.SSS", HdDateTime.FromEpochNanoseconds(345_000_000));
            CheckPrint("00.023", "ss.SSS", HdDateTime.FromEpochMilliseconds(600_023));
            CheckPrint("05.123", "ss.SSS", HdDateTime.FromEpochMilliseconds(65_123));
            CheckPrint("05.123000", "ss.SSSSSS", HdDateTime.FromEpochMilliseconds(65_123));

            // Minutes
            CheckPrint("5", "m", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("7", "m", HdDateTime.FromEpochMilliseconds(425_000));
            CheckPrint("05", "mm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("00005", "0mmmm", HdDateTime.Now.Date.AddMinutes(425));

            // Hours
            CheckPrint("5", "H", HdDateTime.Now.Date.AddHours(48 + 5));
            CheckPrint("4", "H", HdDateTime.Now.Date.AddMinutes(245));
            CheckPrint("07", "HH", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("0007005", "0HHHmmm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("07:5.789", "HH:m.SSS", HdDateTime.Now.Date.AddMinutes(425).AddMilliseconds(789));

            CheckPrint("0007005", "0HHHmmm", HdDateTime.Now.Date.AddMinutes(425));
            CheckPrint("1999-4-1 0:7:5.656789", "yyyy-M-d H:m:s.SSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1999-4-1 0:7:5.656789", "yyyy-M-d H:m:s.SSSSSS",
                       new HdDateTime(1999, 4, 1, 0, 7, 5, 656789000));
            CheckPrint("990401000705656789", "yyMMddHHmmssSSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789000));
            CheckPrint("1999Apr01000705656789999", "yyyMMMddHHmmssSSSSSSSSS",
                       new HdDateTime(1999, 4, 1).AddSeconds(425).AddNanoseconds(656789999));

            CheckPrint("2002-January-01", "y-MMMM-dd", new HdDateTime(2002, 1, 1));
            CheckPrint("31 May 2002", "d MMMM yyy", new HdDateTime(2002, 5, 31));
            CheckPrint("31       May 2002", "dMMMMMMMMMM yyy", new HdDateTime(2002, 5, 31));
            CheckPrint("31  December 2002", "dMMMMMMMMMM yyy", new HdDateTime(2002, 12, 31));

            CheckPrint("1910-4-1 0:7:5.656789", "yyyy-M-d H:m:s.ffffff",
                       new HdDateTime(1910, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1910-4-1 0:7:5.656789", "yyyy-M-d H:m:s.ffffff",
                       new HdDateTime(1910, 4, 1).AddSeconds(425).AddNanoseconds(656789000));

            CheckPrint("1866-1-22 20:40:40.123456789", "yyyy-M-d H:m:s.fffffffff",
                       new HdDateTime(1866, 1, 22, 20, 40, 40, 123456789));
        }
Beispiel #27
0
 /// <summary>
 /// Reset all instance field to their default states.
 /// <returns>this.</returns>
 /// </summary>
 protected virtual IRecordInterface ResetImpl()
 {
     this._timestamp = TypeConstants.TimestampNull;
     this._symbol    = "";
     return(this);
 }
Beispiel #28
0
        public void TestAppend(MutableStringAppendTestType type)
        {
            if (type == MutableStringAppendTestType.Char)
            {
                s.Assign("sasd");
                s.Append('e');
                Assert.AreEqual(s, "sasde");
                s.Assign('e');
                Assert.AreEqual(s, "e");
                s.Add('t');
                Assert.AreEqual(s, "et");
            }
            if (type == MutableStringAppendTestType.String)
            {
                s.Assign("qwert");
                s.Append("yuiop");
                Assert.AreEqual(s, "qwertyuiop");
                s.Assign("qwerty");
                Assert.AreEqual(s, "qwerty");
            }
            if (type == MutableStringAppendTestType.Integer)
            {
                s.Assign("");
                s.Append(-123);
                Assert.AreEqual(s, "-123");
                s.Assign("");
                s.Append(124);
                Assert.AreEqual(s, "124");
                s.Assign(-123);
                Assert.AreEqual(s, "-123");
                s.Assign(124);
                Assert.AreEqual(s, "124");
            }
            if (type == MutableStringAppendTestType.MutableString)
            {
                s.Assign("aba");
                s1.Assign("caba");
                s.Append(s1);
                Assert.AreEqual(s, "abacaba");
                s1.Append(s);
                Assert.AreEqual(s1, "cabaabacaba");

                s.Assign(s1);
                Assert.AreEqual(s, "cabaabacaba");
            }
            if (type == MutableStringAppendTestType.ArrayOfChar)
            {
                s.Clear();
                s.Append(ar);
                Assert.AreEqual(s, "sswtuj1r");

                s.Assign(ar);
                Assert.AreEqual(s, "sswtuj1r");
            }
            if (type == MutableStringAppendTestType.ArrayOfCharWithOffset)
            {
                s.Clear();
                s.Append(ar, 2, 4);
                Assert.AreEqual(s, "wtuj");
                s.Append(ar, 0, 1);
                Assert.AreEqual(s, "wtujs");

                s.Assign(ar, 2, 4);
                Assert.AreEqual(s, "wtuj");
            }
            if (type == MutableStringAppendTestType.CharPtr)
            {
                unsafe
                {
                    fixed(char *ptr = ar)
                    {
                        s.Clear();
                        s.Append(ptr, 5);
                        Assert.AreEqual(s, "sswtu");

                        s.Assign(ptr, 5);
                        Assert.AreEqual(s, "sswtu");
                    }
                }
            }
            if (type == MutableStringAppendTestType.StringBuilder)
            {
                StringBuilder builder = new StringBuilder();
                builder.Append("qazxcvb");
                s.Clear();
                s.Append(builder);
                Assert.AreEqual(s, "qazxcvb");

                s.Assign(builder);
                Assert.AreEqual(s, "qazxcvb");
            }
            if (type == MutableStringAppendTestType.Long)
            {
                s.Assign("");
                s.Append((long)-123);
                Assert.AreEqual(s, "-123");
                s.Assign("");
                s.Append((long)124);
                Assert.AreEqual(s, "124");

                s.Assign((long)-123);
                Assert.AreEqual(s, "-123");
                s.Assign((long)124);
                Assert.AreEqual(s, "124");
            }
            if (type == MutableStringAppendTestType.Short)
            {
                s.Assign("");
                s.Append((short)-123);
                Assert.AreEqual(s, "-123");
                s.Assign("");
                s.Append((short)124);
                Assert.AreEqual(s, "124");

                s.Assign((short)-123);
                Assert.AreEqual(s, "-123");
                s.Assign((short)124);
                Assert.AreEqual(s, "124");
            }
            if (type == MutableStringAppendTestType.UTF8)
            {
                s.Clear();
                s.AppendUTF8(utf8);
                Assert.AreEqual(s, "AAAABa");
                s.Clear();
                s.AppendUTF8(utf8, 4, 2);
                Assert.AreEqual(s, "Ba");
                s.Clear();
                unsafe
                {
                    fixed(byte *ptr = utf8)
                    {
                        s.AppendUTF8(ptr, 6);
                        Assert.AreEqual(s, "AAAABa");
                    }
                }
                s.AssignUTF8(utf8);
                Assert.AreEqual(s, "AAAABa");
                s.AssignUTF8(utf8, 4, 2);
                Assert.AreEqual(s, "Ba");
                unsafe
                {
                    fixed(byte *ptr = utf8)
                    {
                        s.AssignUTF8(ptr, 6);
                        Assert.AreEqual(s, "AAAABa");
                    }
                }
            }
            if (type == MutableStringAppendTestType.UTF16)
            {
                String tempString = "abacaba";
                utf16 = UnicodeEncoding.Unicode.GetBytes(tempString);
                s.Clear();
                s.AppendUTF16(utf16);
                Assert.AreEqual(s, "abacaba");
                s.Clear();
                unsafe
                {
                    fixed(byte *ptr = utf16)
                    {
                        s.AppendUTF16(ptr, 4);
                        Assert.AreEqual(s, "ab");
                    }
                }
                s.Clear();
                s.AppendUTF16(utf16, 0, 4);
                Assert.AreEqual(s, "ab");

                s.AssignUTF16(utf16);
                Assert.AreEqual(s, "abacaba");
                unsafe
                {
                    fixed(byte *ptr = utf16)
                    {
                        s.AssignUTF16(ptr, 4);
                        Assert.AreEqual(s, "ab");
                    }
                }
                s.AssignUTF16(utf16, 0, 4);
                Assert.AreEqual(s, "ab");
            }
            if (type == MutableStringAppendTestType.UUID)
            {
                s.Clear();
                s.Assign(uuid, UUIDPrintFormat.LowerCase);
                s.Append(uuid, UUIDPrintFormat.LowerCase);
                Assert.AreEqual("01234567-89ab-cdef-1011-12131415161701234567-89ab-cdef-1011-121314151617", s);

                s.Clear();
                s.Assign(uuid, UUIDPrintFormat.UpperCase);
                s.Append(uuid, UUIDPrintFormat.UpperCase);
                Assert.AreEqual("01234567-89AB-CDEF-1011-12131415161701234567-89AB-CDEF-1011-121314151617", s);

                s.Clear();
                s.Assign(uuid, UUIDPrintFormat.LowerCaseWithoutDashes);
                s.Append(uuid, UUIDPrintFormat.LowerCaseWithoutDashes);
                Assert.AreEqual("0123456789abcdef10111213141516170123456789abcdef1011121314151617", s);

                s.Clear();
                s.Assign(uuid, UUIDPrintFormat.UpperCaseWithoutDashes);
                s.Append(uuid, UUIDPrintFormat.UpperCaseWithoutDashes);
                Assert.AreEqual("0123456789ABCDEF10111213141516170123456789ABCDEF1011121314151617", s);
            }

            if (type == MutableStringAppendTestType.DateTime)
            {
                s.Clear();
                DateTime dateTime = new DateTime(2016, 1, 1, 9, 7, 55, 555);
                s.Append(dateTime);
                Assert.AreEqual(s.ToString(), "01/01/2016 09:07:55.555");
                dateTime = new DateTime(2016, 10, 11, 19, 17, 55, 555);
                s.Assign(dateTime);
                Assert.AreEqual(s.ToString(), "10/11/2016 19:17:55.555");
            }
            if (type == MutableStringAppendTestType.HdDateTime)
            {
                s.Clear();
                HdDateTime dateTime = new HdDateTime(new DateTime(2016, 1, 1, 9, 7, 55, 555), 10);
                s.Append(dateTime);
                Assert.AreEqual(s.ToString(), "01/01/2016 09:07:55.555.10");
                dateTime = new HdDateTime(new DateTime(2016, 10, 11, 19, 17, 55, 555), 9);
                s.Assign(dateTime);
                Assert.AreEqual(s.ToString(), "10/11/2016 19:17:55.555.09");
            }
            if (type == MutableStringAppendTestType.TimeSpan)
            {
                s.Clear();
                TimeSpan timeSpan = new TimeSpan(10, 9, 7, 55, 555);
                s.Append(timeSpan);
                Assert.AreEqual(s.ToString(), "10.09:07:55.555");
                timeSpan = new TimeSpan(9, 19, 17, 55, 55);
                s.Assign(timeSpan);
                Assert.AreEqual(s.ToString(), "9.19:17:55.055");
            }
            if (type == MutableStringAppendTestType.HdTimeSpan)
            {
                s.Clear();
                HdTimeSpan timeSpan = new HdTimeSpan(new TimeSpan(10, 9, 7, 55, 555));
                s.Append(timeSpan);
                Assert.AreEqual(s.ToString(), "10.09:07:55.555.00");
                timeSpan = new HdTimeSpan(new TimeSpan(9, 19, 17, 55, 55));
                s.Assign(timeSpan);
                Assert.AreEqual(s.ToString(), "9.19:17:55.055.00");
            }
            if (type == MutableStringAppendTestType.Double)
            {
                s.Clear();
                s.Append((double)3.14);
                Assert.AreEqual((s.ToString() == "3.14" || s.ToString() == "3,14"), true);
                s.Assign((double)3.1459);
                Assert.AreEqual((s.ToString() == "3.1459" || s.ToString() == "3,1459"), true);
            }
            if (type == MutableStringAppendTestType.Float)
            {
                s.Clear();
                s.Append((float)3.14);
                Assert.AreEqual((s.ToString() == "3.14" || s.ToString() == "3,14"), true);
                s.Assign((float)3.1459);
                Assert.AreEqual((s.ToString() == "3.1459" || s.ToString() == "3,1459"), true);
            }
            if (type == MutableStringAppendTestType.Boolean)
            {
                s.Clear();
                s.Append(true);
                Assert.AreEqual(s.ToString(), "True");
                s.Assign(false);
                Assert.AreEqual(s.ToString(), "False");
            }
            if (type == MutableStringAppendTestType.Decimal)
            {
                s.Clear();
                s.Append((decimal)3.14);
                Assert.AreEqual((s.ToString() == "3.14" || s.ToString() == "3,14"), true);
                s.Assign((decimal)3.1459);
                Assert.AreEqual((s.ToString() == "3.1459" || s.ToString() == "3,1459"), true);
            }
            if (type == MutableStringAppendTestType.Object)
            {
                s.Clear();
                Tuple <int, int> tuple = new Tuple <int, int>(1, 1);
                s.Append(tuple);
                Assert.AreEqual(tuple.ToString(), s.ToString());
                s.Assign(tuple);
                Assert.AreEqual(tuple.ToString(), s.ToString());
            }
        }
Beispiel #29
0
 private void AddToBuilder(HdDateTime arg1, object arg2)
 {
     sb.Append(arg2.ToString());
 }
Beispiel #30
0
 /// <summary>
 /// Sets null to Timestamp property.
 /// </summary>
 public void NullifyNanoTime()
 {
     this._timestamp = TypeConstants.TimestampNull;
 }