Example #1
0
        public void FixedDateStringParsesToDateTime(string date)
        {
            var dateParts = TimeUtils.ReplaceTimeZoneWithUtcOffset(date).Split(' ').ToList();
            var dateDay   = dateParts.ElementAt(0);
            var dateTime  = dateParts
                            .GetRange(1, dateParts.Count - 1)
                            .Aggregate((memo, next) => $"{memo} {next}");

            Assert.Equal("10/22/2015", dateDay);
            Assert.Equal("03:49 PM -5", dateTime);

            var parsedDay = DateTime.ParseExact(dateDay, TimeUtils.DATE_FORMAT, CultureInfo.CurrentCulture).ToUniversalTime();

            Assert.Equal(2015, parsedDay.Year);
            Assert.Equal(10, parsedDay.Month);
            Assert.Equal(22, parsedDay.Day);

            var parsedTime = DateTime.ParseExact(dateTime, TimeUtils.TIME_FORMAT, CultureInfo.CurrentCulture).ToUniversalTime();

            Assert.Equal(20, parsedTime.Hour);
            Assert.Equal(49, parsedTime.Minute);

            var parsedDate = TimeUtils.DateStringToDateTimeUtc(date);

            Assert.True(parsedDate.GetType() == typeof(DateTime));
        }
Example #2
0
        public async void ValidCsvStringsConvertCorrectly(string filePath)
        {
            var importer = new CsvImporter();

            var subscribers = await importer.ImportSubscribersAsync(filePath);

            Assert.Equal(4, subscribers.Count());

            var first = subscribers.ElementAt(0);

            Assert.Equal("504 555 5555", first.Contact);
            Assert.Equal(SubscriberType.Phone, first.Type);
            Assert.Equal(SubscriberOrigin.Direct, first.Origin);
            Assert.Equal(0, first.Subscriptions);
            Assert.Equal(TimeUtils.DateStringToDateTimeUtc("10/22/2015 03:49 PM CDT"), first.LastModified);

            var second = subscribers.ElementAt(1);

            Assert.Equal("*****@*****.**", second.Contact);
            Assert.Equal(SubscriberType.Email, second.Type);
            Assert.Equal(SubscriberOrigin.Direct, second.Origin);
            Assert.Equal(5, second.Subscriptions);
            Assert.Equal(TimeUtils.DateStringToDateTimeUtc("11/07/2016 11:35 AM CST"), second.LastModified);

            var third = subscribers.ElementAt(2);

            Assert.Equal("*****@*****.**", third.Contact);
            Assert.Equal(SubscriberType.Email, third.Type);
            Assert.Equal(SubscriberOrigin.Direct, third.Origin);
            Assert.Equal(18, third.Subscriptions);
            Assert.Equal(TimeUtils.DateStringToDateTimeUtc("11/30/2015 12:33 PM CST"), third.LastModified);

            var fourth = subscribers.ElementAt(3);

            Assert.Equal("*****@*****.**", fourth.Contact);
            Assert.Equal(SubscriberType.Email, fourth.Type);
            Assert.Equal(SubscriberOrigin.Upload, fourth.Origin);
            Assert.Equal(25, fourth.Subscriptions);
            Assert.Equal(TimeUtils.DateStringToDateTimeUtc("06/30/2015 01:03 PM CDT"), fourth.LastModified);
        }
Example #3
0
        public override object ConvertFromString(string text, IReaderRow row, MemberMapData propertyMapData)
        {
            var trimmed = text.Trim(new char[] { ' ', '"', '\n' });

            return(TimeUtils.DateStringToDateTimeUtc(trimmed));
        }