TryParseMicrosoftDate() private static method

private static TryParseMicrosoftDate ( Newtonsoft.Json.Utilities.StringReference text, long &ticks, System.TimeSpan &offset, DateTimeKind &kind ) : bool
text Newtonsoft.Json.Utilities.StringReference
ticks long
offset System.TimeSpan
kind DateTimeKind
return bool
        private static bool TryParseDateTimeMicrosoft(
            StringReference text,
            DateTimeZoneHandling dateTimeZoneHandling,
            out DateTime dt)
        {
            long         ticks;
            DateTimeKind kind;

            if (!DateTimeUtils.TryParseMicrosoftDate(text, out ticks, out TimeSpan _, out kind))
            {
                dt = new DateTime();
                return(false);
            }
            DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);

            switch (kind)
            {
            case DateTimeKind.Unspecified:
                dt = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified);
                break;

            case DateTimeKind.Local:
                dt = dateTime.ToLocalTime();
                break;

            default:
                dt = dateTime;
                break;
            }
            dt = DateTimeUtils.EnsureDateTime(dt, dateTimeZoneHandling);
            return(true);
        }
Beispiel #2
0
        private static bool TryParseDateTimeMicrosoft(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
        {
            long         num;
            DateTimeKind dateTimeKind;
            TimeSpan     timeSpan;

            if (!DateTimeUtils.TryParseMicrosoftDate(text, out num, out timeSpan, out dateTimeKind))
            {
                dt = new DateTime();
                return(false);
            }
            DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(num);

            if (dateTimeKind == DateTimeKind.Unspecified)
            {
                dt = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified);
            }
            else if (dateTimeKind == DateTimeKind.Local)
            {
                dt = dateTime.ToLocalTime();
            }
            else
            {
                dt = dateTime;
            }
            dt = DateTimeUtils.EnsureDateTime(dt, dateTimeZoneHandling);
            return(true);
        }
Beispiel #3
0
        // Token: 0x06000D25 RID: 3365 RVA: 0x0004CA54 File Offset: 0x0004AC54
        private static bool TryParseDateTimeOffsetMicrosoft(StringReference text, out DateTimeOffset dt)
        {
            long         javaScriptTicks;
            TimeSpan     timeSpan;
            DateTimeKind dateTimeKind;

            if (!DateTimeUtils.TryParseMicrosoftDate(text, out javaScriptTicks, out timeSpan, out dateTimeKind))
            {
                dt = default(DateTime);
                return(false);
            }
            dt = new DateTimeOffset(DateTimeUtils.ConvertJavaScriptTicksToDateTime(javaScriptTicks).Add(timeSpan).Ticks, timeSpan);
            return(true);
        }
        private static bool TryParseDateTimeOffsetMicrosoft(StringReference text, out DateTimeOffset dt)
        {
            long     ticks;
            TimeSpan offset;

            if (!DateTimeUtils.TryParseMicrosoftDate(text, out ticks, out offset, out DateTimeKind _))
            {
                dt = (DateTimeOffset) new DateTime();
                return(false);
            }
            DateTime dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);

            dt = new DateTimeOffset(dateTime.Add(offset).Ticks, offset);
            return(true);
        }
Beispiel #5
0
        private static bool TryParseDateTimeOffsetMicrosoft(StringReference text, out DateTimeOffset dt)
        {
            long         num;
            TimeSpan     timeSpan;
            DateTimeKind dateTimeKind;
            DateTime     dateTime;

            if (!DateTimeUtils.TryParseMicrosoftDate(text, out num, out timeSpan, out dateTimeKind))
            {
                dateTime = new DateTime();
                dt       = dateTime;
                return(false);
            }
            dateTime = DateTimeUtils.ConvertJavaScriptTicksToDateTime(num).Add(timeSpan);
            dt       = new DateTimeOffset(dateTime.Ticks, timeSpan);
            return(true);
        }