예제 #1
0
        public void CombineStringsToDateTimeExcel()
        {
            var res = StringConversion.CombineObjectsToDateTime(new DateTime(2010, 01, 1), null,
                                                                new DateTime(2001, 02, 1, 07, 13, 55, 0), null, false, new Column().ValueFormatMutable, out _);

            Assert.AreEqual(new DateTime(2010, 01, 1, 07, 13, 55, 0), res);
        }
예제 #2
0
        public void CombineStringsToDateTimeExcelTest()
        {
            Assert.IsFalse(StringConversion.CombineObjectsToDateTime(null, null, null, null, true,
                                                                     new ValueFormatMutable {
                DateFormat = "yyyyMMdd", DateSeparator = "", TimeSeparator = ":"
            }, out _).HasValue);

            Assert.AreEqual(new DateTime(2010, 10, 10),
                            StringConversion.CombineObjectsToDateTime(new DateTime(2010, 10, 10),
                                                                      null,
                                                                      null, null, true, null, out _).Value);

            Assert.AreEqual(DateTime.FromOADate(0) + new TimeSpan(8, 12, 54),
                            StringConversion.CombineObjectsToDateTime(null,
                                                                      null,
                                                                      new DateTime(new TimeSpan(8, 12, 54).Ticks), null, false, null, out _).Value);
            Assert.AreEqual(new DateTime(2010, 10, 13),
                            StringConversion.CombineObjectsToDateTime(null,
                                                                      "2010/10/13",
                                                                      null, null, false,
                                                                      new ValueFormatMutable {
                DateFormat = "yyyy/MM/dd", DateSeparator = "/", TimeSeparator = ":"
            }, out _).Value);

            Assert.AreEqual(new DateTime(2010, 10, 10, 8, 12, 54),
                            StringConversion.CombineObjectsToDateTime(new DateTime(2010, 10, 10),
                                                                      null,
                                                                      new DateTime(new TimeSpan(8, 12, 54).Ticks), null, true, null, out _).Value);

            Assert.AreEqual(new DateTime(2010, 10, 10, 8, 12, 54),
                            StringConversion.CombineObjectsToDateTime(null, "20101010",
                                                                      new DateTime(new TimeSpan(8, 12, 54).Ticks), null, true,
                                                                      new ValueFormatMutable {
                DateFormat = "yyyyMMdd", DateSeparator = "", TimeSeparator = ":"
            }, out _).Value);

            Assert.AreEqual(new DateTime(2010, 10, 13, 8, 12, 54),
                            StringConversion.CombineObjectsToDateTime(null, "2010/10/13",
                                                                      new DateTime(new TimeSpan(8, 12, 54).Ticks).ToOADate(), null, true,
                                                                      new ValueFormatMutable {
                DateFormat = "yyyy/MM/dd", DateSeparator = "/", TimeSeparator = ":"
            }, out _).Value);

            Assert.AreEqual(new DateTime(2010, 10, 13, 8, 12, 54),
                            StringConversion.CombineObjectsToDateTime(new DateTime(2010, 10, 13).ToOADate(),
                                                                      null,
                                                                      new DateTime(new TimeSpan(8, 12, 54).Ticks).ToOADate(), null, true,
                                                                      new ValueFormatMutable {
                DateFormat = "yyyy/MM/dd", DateSeparator = "/", TimeSeparator = ":"
            }, out _).Value);

            // Pass in a time that is >23:59 to adjust date part
            Assert.AreEqual(new DateTime(2010, 10, 15, 5, 10, 00),
                            StringConversion.CombineObjectsToDateTime(null,
                                                                      "2010/10/14",
                                                                      null, "29:10:00", false,
                                                                      new ValueFormatMutable {
                DateFormat = "yyyy/MM/dd", DateSeparator = "/", TimeSeparator = ":"
            },
                                                                      out var issues)
                            .Value);
            // should issue a warning
            Assert.IsTrue(issues);
        }