示例#1
0
        public void Test_TryParseDateTime_InvalidFormat(string jsonData)
        {
            DateTime     value;
            TimeZoneInfo info = TimeZoneInfo.Local;
            bool         res  = CsvValueParser.TryParseDateTime(jsonData, info, out value);

            Assert.That(res, Is.False);
        }
示例#2
0
        public void Test_TryParseDateTime_Valid(bool provideTimeZone, string csvData, string expectedData)
        {
            // If csvData contains a timezone, then that timezone is used
            // Otherwise, if provideTimeZone=true, then the test timezone of +1 is used
            // Otherwise, if provideTimeZone=false, then the value is assumed to be UTC already

            TimeZoneInfo tz = null;

            if (provideTimeZone)
            {
                string   displayName  = "(GMT+01:00) ReadiNow/PlusOne";
                string   standardName = "Hammer Time";
                TimeSpan offset       = new TimeSpan(1, 00, 00);
                tz = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName);
            }

            DateTime value;
            DateTime expected = DateTime.Parse(expectedData, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
            bool     res      = CsvValueParser.TryParseDateTime(csvData, tz, out value);

            Assert.That(res, Is.True);
            Assert.That(value, Is.EqualTo(expected));
            Assert.That(value.Kind, Is.EqualTo(DateTimeKind.Utc));
        }