コード例 #1
0
        /// <summary>
        /// Parses a date time string.
        ///
        /// Is able to parse a date string with these formats:
        ///   - 'YYYYMMDD', 'YYYMMDD', 'YYMMDD' and 'YMMDD' (<seealso cref="ParseDate(string)"/>,
        ///   - CLR DateTime formats,
        ///   - and ISO 8601 formats.
        /// </summary>
        /// <param name="dateTimeString">The date time string.</param>
        /// <param name="kind">The <see cref="DateTimeKind"/> we expect to be parsed.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If <paramref name="dateTimeString"/> is null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="dateTimeString"/> is empty</exception>
        /// <exception cref="FormatException">If <paramref name="dateTimeString"/> cannot be parsed as a DateTime</exception>
        public static DateTime ParseDateTime(string dateTimeString,
                                             DateTimeKind kind = DateTimeKind.Utc)
        {
            dateTimeString.ExceptionIfNullOrTrimmedEmpty("dateTimeString");

            string dts = dateTimeString.Trim();

            if (dts == "0")
            {
                return(DateTime.MinValue);
            }

            if (dts.Length <= 8 && dts.All(Char.IsDigit))             // Full DbDate format: YYYYMMDD
            {
                return(ParseDate(dateTimeString).ToDateTime(kind));
            }

            var styles = DateTimeStyles.AllowWhiteSpaces;

            if (kind == DateTimeKind.Utc)
            {
                styles |= DateTimeStyles.AssumeUniversal;
            }

            DateTime clrDateTime;

            if (DateTime.TryParse(dts, CultureInfo.InvariantCulture, styles, out clrDateTime))
            {
                return(clrDateTime);
            }

            // last try: the common ISO 8601:
            return(DateTimeExt.ParseIso8601DateTime(dateTimeString));
        }
コード例 #2
0
        public void ParseChart(Chart chart)
        {
            if (chart.Series.Count == 0)
            {
                return;
            }

            // Modify our tab titel to include the Grid tab
            Title = $"{chart.Name} [Grid]";

            // Put all series into table dataholders containing all the points
            Series = chart.Series.Values.Select(s =>
            {
                var holder = new GridSerie {
                    Name = s.Name
                };
                holder.AddRange(s.Values.Select(p => new GridPoint
                {
                    // Use the actual timestamp as the X value
                    X = DateTimeExt.FromTimeStamp(p.x).ToString("yy-MM-dd HH:mm"),
                    Y = p.y
                }));
                return(holder);
            }).ToList();

            SelectedSeries = Series.First();
        }
コード例 #3
0
        public void DateTimeExtTestNegativeInfinityDate()
        {
            // Тест на бесконечное прошлое
            DateTimeExt dtextNegativeInfinity = new DateTimeExt(CS.TimeSingularity.NegativeInfinity, session);

            DateTimeExtFieldTest(dtextNegativeInfinity);
        }
コード例 #4
0
        public void DateTimeExtTestPositiveInfinityDate()
        {
            // Тест на бесконечное будущее
            DateTimeExt dtextPositiveInfinity = new DateTimeExt(CS.TimeSingularity.PositiveInfinity, session);

            DateTimeExtFieldTest(dtextPositiveInfinity);
        }
コード例 #5
0
        public void DateTimeExtTestMinDate()
        {
            // Тест минимального в C# значения стандартной даты
            DateTimeExt dtextMin = new DateTimeExt(System.DateTime.MinValue, session);

            DateTimeExtFieldTest(dtextMin);
        }
コード例 #6
0
        public void DateTimeExtTestMaxDate()
        {
            // Тест максимального в C# значения стандартной даты
            DateTimeExt dtextMax = new DateTimeExt(System.DateTime.MaxValue, session);

            DateTimeExtFieldTest(dtextMax);
        }
コード例 #7
0
        public void DateTimeExtTestStandartDate()
        {
            // Тест стандартной даты
            DateTimeExt dtextStandart = new DateTimeExt(System.DateTime.Now, session);

            DateTimeExtFieldTest(dtextStandart);
        }
コード例 #8
0
        public void DateTimeExtTest()
        {
            // Тест стандартной даты
            DateTimeExt dtextStandart = new DateTimeExt(System.DateTime.Now, session);

            DateTimeExtFieldTest(dtextStandart);

            // Тест минимального в C# значения стандартной даты
            DateTimeExt dtextMin = new DateTimeExt(System.DateTime.MinValue, session);

            DateTimeExtFieldTest(dtextMin);

            // Тест максимального в C# значения стандартной даты
            DateTimeExt dtextMax = new DateTimeExt(System.DateTime.MaxValue, session);

            DateTimeExtFieldTest(dtextMax);

            // Тест на бесконечное прошлое
            DateTimeExt dtextNegativeInfinity = new DateTimeExt(CS.TimeSingularity.NegativeInfinity, session);

            DateTimeExtFieldTest(dtextNegativeInfinity);

            // Тест на бесконечное будущее
            DateTimeExt dtextPositiveInfinity = new DateTimeExt(CS.TimeSingularity.PositiveInfinity, session);

            DateTimeExtFieldTest(dtextPositiveInfinity);
        }
コード例 #9
0
 public void Should_try_parse_as_utc()
 {
     DateTimeExt.TryParseAsUtc("2019-11-22 19:07:11", "yyyy-MM-dd HH:mm:ss", DateTimeStyles.AssumeLocal, out var parsed)
     .Should().BeTrue();
     parsed.Hour.Should().Be(19);
     parsed.Kind.Should().Be(DateTimeKind.Utc);
 }
コード例 #10
0
        public void ParseRfc2822DateTimeOptionalStrings()
        {
            DateTime dtUtcTime = new DateTime(2013, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc);

            // Optional: week day
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("20 Feb 13 05:21:00 GMT"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("20 Feb 13 06:21:00 A"));             // +1h

            // Optional: seconds in time
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 2013 05:21:00 GMT"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 2013 06:21 A"));             // +1h

            // Two digit year edge cases/rules:
            // namely 00 to 49 are equivalent to 2000 to 2049,
            // and 50 to 99 are equivalent to 1950 to 1999:

            Assert.AreEqual(new DateTime(2000, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc),
                            DateTimeExt.ParseRfc2822DateTime("20 Feb 00 05:21:00 GMT"));
            Assert.AreEqual(new DateTime(2049, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc),
                            DateTimeExt.ParseRfc2822DateTime("20 Feb 49 05:21:00 GMT"));
            Assert.AreEqual(new DateTime(1950, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc),
                            DateTimeExt.ParseRfc2822DateTime("20 Feb 50 05:21:00 GMT"));
            Assert.AreEqual(new DateTime(1999, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc),
                            DateTimeExt.ParseRfc2822DateTime("20 Feb 99 05:21:00 GMT"));
        }
コード例 #11
0
        /// <summary>
        /// Remove any files that are not found in the SockDrawer
        /// </summary>
        /// <param name="files"></param>
        private void CheckedForDeletedFiles(string[] files)
        {
            var stopWatch = new Stopwatch(MethodBase.GetCurrentMethod().Name);

            try
            {
                StatusUpdate(StatusModel.Update(null, "Checking for Deleted Files..."));
                DateTime _lastUpdate = DateTime.Now;

                // Using r.DefaultIfEmtpy will set the right values to null where there is no match - Sara
                var query = from f in XmlDal.CacheModel.Files
                            join p in files on f.Path equals p into r
                            from p in r.DefaultIfEmpty()
                            where p == null
                            select f.Path;

                var test    = query.ToList();
                var count   = test.Count;
                int current = 0;

                Parallel.ForEach(test, (path) => {
                    Interlocked.Increment(ref current);
                    if (DateTimeExt.EverySecond(ref _lastUpdate))
                    {
                        StatusUpdate(StatusModel.Update(null, $"Removing Deleted Files {current} of {count}"));
                    }
                    XmlDal.CacheModel.RemoveFile(path);
                });
            }
            finally
            {
                stopWatch.Stop();
            }
            StatusUpdate(StatusModel.AddPersistentDetail("Checking for Deleted Files, Complete... {0}", stopWatch.Duration.Value.ToShortReadableString()));
        }
コード例 #12
0
        public void ParseRfc2822DateTimeGMTStrings()
        {
            DateTime dtUtcTime = new DateTime(2013, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc);

            // returns the UTC time
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 GMT"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 Z"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 UT"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 +00:00"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 +0000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 -00:00"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 -0000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 +000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 +00"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 +0"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 -000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 -00"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:21:00 -0"));

            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 +1"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 +01"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:31:00 +010"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 15:21:00 +10"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 +100"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 +0100"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 +01:00"));

            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 04:21:00 -1"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 04:21:00 -01"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 05:11:00 -010"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Tue, 19 Feb 13 19:21:00 -10"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 04:21:00 -100"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 04:21:00 -0100"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 04:21:00 -01:00"));
        }
コード例 #13
0
        public void ParseRfc2822DateTimeLazy()
        {
            // this is a ISO8601 datetime:
            var got = DateTimeExt.ParseRfc2822DateTime("2013-06-05T04:20:09.123-0100");

            Assert.AreEqual(new DateTime(2013, 06, 05, 05, 20, 09, 123), got);
        }
コード例 #14
0
        public void Should_parse_as_utc()
        {
            var parsed = DateTimeExt.ParseAsUtc("2019-11-22 19:07:11", "yyyy-MM-dd HH:mm:ss");

            parsed.Hour.Should().Be(19);
            parsed.Kind.Should().Be(DateTimeKind.Utc);
        }
コード例 #15
0
        public void SetForOrderInProgress(Order order)
        {
            order.DateRegister = DateTimeExt.PastSince(DaysRanges.RegisterFreshAgo)
                                 .SetCredibleTime();

            DaysRanges.Durations.SetAsInProgress(order);
        }
コード例 #16
0
        /// <summary>
        /// Returns the difference between the target and source using the property "DATETIME"
        /// Returns null if both target and source do not have a "DATETIME" property
        /// </summary>
        private static TimeSpan?CalculateDateTimeDifference(DynamicObjectType targetProperty, DynamicObjectType sourceProperty)
        {
            if (targetProperty == null)
            {
                return(null);
            }

            var firstOrDefault = sourceProperty.Properties.FirstOrDefault(prop => prop.Name == Keywords.DATETIME);

            if (firstOrDefault != null)
            {
                var sourceDateTimeString =
                    firstOrDefault.Value.ToString();
                DateTime sourceDateTime;
                if (!DateTimeExt.TryParseWithTimeZoneRemoval(sourceDateTimeString, out sourceDateTime))
                {
                    return(null);
                }

                var dynamicProperty = targetProperty.Properties.FirstOrDefault(prop => prop.Name == Keywords.DATETIME);
                if (dynamicProperty != null)
                {
                    var targetDateTimeString =
                        dynamicProperty.Value.ToString();
                    DateTime targetDateTime;
                    if (!DateTimeExt.TryParseWithTimeZoneRemoval(targetDateTimeString, out targetDateTime))
                    {
                        return(null);
                    }

                    return(sourceDateTime - targetDateTime);
                }
            }
            return(null);
        }
コード例 #17
0
        public void Try_Parse_Returns_Null_And_False_When_String_Is_Null()
        {
            DateTime?dt;
            var      parsed = DateTimeExt.TryParse(null, out dt);

            Assert.IsTrue(parsed);
            Assert.IsNull(dt);
        }
コード例 #18
0
        public void Try_Parse_Returns_Null_And_False_When_String_Is_Not_Date()
        {
            DateTime?dt;
            var      parsed = DateTimeExt.TryParse("NOT A DATE", out dt);

            Assert.IsFalse(parsed);
            Assert.IsNull(dt);
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DbTimeStamp"/> class.
        /// </summary>
        /// <param name="dateTimeString">
        /// The date-time string in the  format ddd, dd MMM yyyy HH':'mm':'ss zzz as specified by Rfc2822.
        /// See also http://www.ietf.org/rfc/rfc2822.txt?number=2822.
        /// </param>
        /// <exception cref="FormatException">If the <paramref name="dateTimeString"/> is not a parsable date-time format</exception>
        public DbTimeStamp(string dateTimeString)
        {
            dateTimeString.ExceptionIfNullOrEmpty("dateTimeString");

            var parsed = DateTimeExt.ParseRfc2822DateTime(dateTimeString);

            _current = new DateTimeOffset(parsed.ToLocalTime());
        }
コード例 #20
0
        public void CreateTest()
        {
            var date = new DateTime(2019, 1, 2, 12, 0, 0);
            var mils = date.ToUnix();
            var from = DateTimeExt.FromUnix(mils);

            Assert.AreEqual(from, date.ToUniversalTime());
        }
コード例 #21
0
ファイル: FeedItem.cs プロジェクト: sthakuri/rss-news-reader
        public override string ToString()
        {
            string str = string.Format("{0} | Posted On: {1}", HeadLine, DateTimeExt.ToLovelyTime(PublishedDate));

            //str += Environment.NewLine;
            //str += Description;
            return(str);
        }
コード例 #22
0
 protected FileSystemData(string path, WIN32_FIND_DATA raw)
 {
     _raw  = raw;
     _path = path;
     _creationDateTimeUtc = DateTimeExt.FromFileTimeUtc(_raw.ftCreationTime);
     _lastAccessTimeUtc   = DateTimeExt.FromFileTimeUtc(_raw.ftLastAccessTime);
     _lastWriteTimeUtc    = DateTimeExt.FromFileTimeUtc(_raw.ftLastWriteTime);
 }
コード例 #23
0
        public void Encode(AvlData[] obj, IBitWriter writer)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            int length = obj.Length;

            if (length == 0)
            {
                throw new ArgumentException("0 AvlData to encode");
            }
            long num1 = Timestamp2Y2K(DateTimeExt.ToAvl(obj[0].DateTime));

            WriteBitSequence(writer, num1, 35);
            WriteBitSequence(writer, length, 5);
            long num2 = 0;
            long num3 = 0;

            for (int index = 0; index < length; ++index)
            {
                AvlData    avlData = obj[index];
                GpsElement gps     = avlData.GPS;
                bool       isValid = gps.IsValid;
                writer.WriteBit(isValid);
                if (isValid)
                {
                    long num4 = num2;
                    long num5 = num3;
                    gps  = avlData.GPS;
                    num2 = CompressGws(gps.X, -1800000000L, 1800000000L, 3600000000L, 2097151L);
                    gps  = avlData.GPS;
                    num3 = CompressGws(gps.Y, -900000000L, 900000000L, 1800000000L, 1048575L);
                    long num6 = num4 - num2;
                    long num7 = num5 - num3;
                    if (Math.Abs(num6) < 8191L && Math.Abs(num7) < 8191L)
                    {
                        writer.WriteBit(true);
                        WriteBitSequence(writer, num6 + 8191L, 14);
                        WriteBitSequence(writer, num7 + 8191L, 14);
                    }
                    else
                    {
                        writer.WriteBit(false);
                        WriteBitSequence(writer, num2, 21);
                        WriteBitSequence(writer, num3, 20);
                    }
                    IBitWriter writer1 = writer;
                    gps = avlData.GPS;
                    long speed = gps.Speed;
                    WriteBitSequence(writer1, speed, 8);
                }
            }
        }
コード例 #24
0
        public void ParseRfc2822DateTimeCaseIndependenceStrings()
        {
            DateTime dtUtcTime = new DateTime(2013, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc);

            // returns the UTC time
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("wEd, 20 Feb 13 05:21:00 GMT"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 fEb 13 06:21:00 A"));             // +1h
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 13 06:21:00 a"));             // +1h
        }
コード例 #25
0
 internal User(IntPtr pointer)
 {
     Name             = Functions.vp_string(pointer, StringAttributes.UserName);
     Email            = Functions.vp_string(pointer, StringAttributes.UserEmail);
     ID               = Functions.vp_int(pointer, IntAttributes.UserId);
     OnlineTime       = TimeSpan.FromSeconds(Functions.vp_int(pointer, IntAttributes.UserOnlineTime));
     RegistrationTime = DateTimeExt.FromUnixTimestampUTC(Functions.vp_int(pointer, IntAttributes.UserRegistrationTime));
     LastLogin        = DateTimeExt.FromUnixTimestampUTC(Functions.vp_int(pointer, IntAttributes.UserLastLogin));
 }
コード例 #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="amountOfTime"></param>
        /// <param name="timeGranule"></param>
        public static void Delay2(double amountOfTime,
                                  Rules.TimeIntervalTypesEnum timeGranule = Rules.TimeIntervalTypesEnum.MilliSeconds)
        {
            var dateSince = DateTime.Now;

            do
            {
                Thread.Sleep(1);
            } while (DateTimeExt.CalculateElapsedTime(dateSince, DateTime.Now, timeGranule) < amountOfTime);
        }
コード例 #27
0
        public AvlData Decode(IBitReader reader)
        {
            DateTime dateTime = reader != null?DateTimeExt.FromAvl(reader.ReadInt64()) : throw new ArgumentNullException(nameof(reader));

            AvlDataPriority priority = (AvlDataPriority)reader.ReadByte();
            GpsElement      gps      = DefaultGpsElementEncoding.Instance.Decode(reader);
            IoElement       data     = DefaultIOElementEncoding.Instance16.Decode(reader);

            return(new AvlData(priority, dateTime, gps, data));
        }
コード例 #28
0
ファイル: MaterialController.cs プロジェクト: avalise/MyReps
        public IActionResult Export([FromQuery] Bootstrap.BootstrapParams bootstrap)
        {
            var buffer = _materialServices.ExportList(bootstrap);

            if (buffer.IsNull())
            {
                return(File(JsonL((false, PubConst.File8)).ToBytes(), ContentType.ContentTypeJson));
            }
            return(File(buffer, ContentType.ContentTypeFile, DateTimeExt.GetDateTimeS(DateTimeExt.DateTimeFormatString) + "-" + EncoderUtil.UrlHttpUtilityEncoder("物料") + ".xlsx"));
        }
コード例 #29
0
        public void Try_Parse_Returns_Value_And_True_When_String_Is_Date()
        {
            var expected = Utility.RandomDateTime();

            DateTime?dt;
            var      parsed = DateTimeExt.TryParse(expected.ToString(), out dt);

            Assert.IsTrue(parsed);
            Assert.IsNotNull(dt);
            Assert.AreEqual(expected, dt.Value);
        }
コード例 #30
0
        public void ParseRfc2822DateTimeWithMultiSpacesStrings()
        {
            DateTime dtUtcTime = new DateTime(2013, 2, 20, 5, 21, 0, 0, DateTimeKind.Utc);

            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb   13 05:21:00 +0000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb   13 05:21:00+0000"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb   13 05:21:00+00:00"));
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20 Feb 2013 06:21:00   A"));          // +1h
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20   Feb 13 06:21:00 A"));            // +1h
            Assert.AreEqual(dtUtcTime, DateTimeExt.ParseRfc2822DateTime("Wed, 20   Feb 13 06:21:00A"));             // +1h
        }