public void testSIF2xTimeParsing() { SifFormatter formatter = new Sif2xFormatter(); String testValue = formatter.ToTimeString(null); Assert.IsNull(testValue, "Date value should be null"); DateTime now = DateTime.Now; DateTime assertedDate = new DateTime(now.Year, now.Month, now.Day, 21, 0, 59); Nullable <DateTime> assertedDateTime = new Nullable <DateTime>(assertedDate); String sifString = formatter.ToDateTimeString(assertedDateTime); AssertTimeParsing(assertedDateTime, formatter, sifString, "Re-Parse of original"); String test1 = "21:00:59"; AssertTimeParsing(assertedDateTime, formatter, test1, "Date Time"); DateTime UTcTime = assertedDate.ToUniversalTime(); String test2 = UTcTime.ToString("HH:mm:ss") + "Z"; AssertTimeParsing(assertedDateTime, formatter, test2, "UTC Time (Z)"); // test2 = UTcTime.ToString("HH:mm:ss") + "+0:00"; // AssertTimeParsing(assertedDateTime, formatter, test2, "UTC Time (+00:00)"); // Test the time, using Eastern time DateTime easternTime = UTcTime.AddHours(-5); String test3 = easternTime.ToString("HH:mm:ss") + "-05:00"; AssertTimeParsing(assertedDateTime, formatter, test3, "Eastern Time"); // Test the time, using european time DateTime europeanTime = UTcTime.AddHours(3); String test4 = europeanTime.ToString("HH:mm:s.s") + "+03:00"; AssertTimeParsing(assertedDateTime, formatter, test4, "European Time"); test4 = "2008-04-21T14:16:00.3651098Z"; DateTime t = formatter.ToDateTime(test4).Value; Console.WriteLine(t); }
public void testSIF2xDateTimeParsing() { SifFormatter formatter = new Sif2xFormatter(); String testValue = formatter.ToDateTimeString(null); Assert.IsNull(testValue, "Date value should be null"); DateTime assertedDate = new DateTime(1999, 9, 1, 22, 2, 4); TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(assertedDate); Console.Write("UTC Offset: "); Console.WriteLine(utcOffset); Console.WriteLine(); Nullable <DateTime> assertedDateTime = new Nullable <DateTime>(assertedDate); String sifString = formatter.ToDateTimeString(assertedDateTime); AssertDateTimeParsing(assertedDateTime, formatter, sifString, "Re-Parse of original"); String test1 = "1999-09-01T22:02:04"; AssertDateTimeParsing(assertedDateTime, formatter, test1, "Date Time"); DateTime UTcTime = assertedDate.ToUniversalTime(); String test2 = UTcTime.ToString("s") + "Z"; AssertDateTimeParsing(assertedDateTime, formatter, test2, "UTC Time (Z)"); // test2 = UTcTime.ToString("s") + "+0:00"; // AssertDateTimeParsing(assertedDateTime, formatter, test2, "UTC Time (+00:00)"); // Test the time, using Eastern time DateTime easternTime = UTcTime.AddHours(-5); String test3 = easternTime.ToString("s") + "-05:00"; AssertDateTimeParsing(assertedDateTime, formatter, test3, "Eastern Time"); // Test the time, using european time DateTime europeanTime = UTcTime.AddHours(3); String test4 = europeanTime.ToString("s") + "+03:00"; AssertDateTimeParsing(assertedDateTime, formatter, test4, "European Time"); }
public void testParsing() { SifFormatter SIF1x = new Sif1xFormatter(); SifFormatter SIF2x = new Sif2xFormatter(); Boolean BooleanValue = true; //mjn declare types as nullable Boolean?BooleanNull = null; int? intNull = null; assertBooleanParsing(SIF1x, "Yes", BooleanValue); Assert.AreEqual("", SIF1x.ToString(BooleanNull), "Null Bool Value"); //( (Boolean)null )); assertBooleanParsing(SIF2x, "true", BooleanValue); Assert.IsNull(SIF2x.ToString(BooleanNull), "Null Bool Value"); bool?testValue = SIF2x.ToBool("1"); Assert.IsTrue(testValue.Value, "Boolean Value"); testValue = SIF2x.ToBool("0"); Assert.IsFalse(testValue.Value, "Boolean Value"); float floatValue = 99.34f; assertFloatParsing(SIF1x, "99.34", floatValue); Assert.IsNull(SIF1x.ToString((float?)null)); assertFloatParsing(SIF2x, "99.34", floatValue); Assert.IsNull(SIF2x.ToString((float?)null)); floatValue = 321651.09934f; assertFloatParsing(SIF1x, "321651.1", floatValue); assertFloatParsing(SIF2x, "321651.1", floatValue); //INF, -INF and NaN assertFloatParsing(SIF1x, "INF", float.PositiveInfinity); assertFloatParsing(SIF1x, "-INF", float.NegativeInfinity); float?nan = SIF1x.ToFloat("NaN"); Assert.IsTrue(float.IsNaN(nan.Value)); assertFloatParsing(SIF2x, "INF", float.PositiveInfinity); assertFloatParsing(SIF2x, "-INF", float.NegativeInfinity); nan = SIF2x.ToFloat("NaN"); Assert.IsTrue(float.IsNaN(nan.Value)); int intValue = 9998877; // new int(9998877); assertintParsing(SIF1x, "9998877", intValue); Assertion.AssertEquals("Null int Value", "", SIF1x.ToString(intNull)); assertintParsing(SIF2x, "9998877", intValue); Assertion.AssertNull("Null int Value", SIF2x.ToString(intNull)); DateTime?sampleDate = new DateTime(1999, 10, 01); AssertDateParsing(SIF1x, "19991001", sampleDate); Assertion.AssertEquals("Null Value", "", SIF1x.ToDateString(null)); AssertDateParsing(SIF2x, "1999-10-01" /* + tzOffset */, sampleDate); Assertion.AssertNull("Null Date Value", SIF2x.ToDateString(null)); }