示例#1
0
        private void WriteConstructorDate(JsonReader reader)
        {
            if (!reader.Read())
            {
                throw new Exception("Unexpected end while reading date constructor.");
            }
            if (reader.TokenType != JsonToken.Integer)
            {
                throw new Exception("Unexpected token while reading date constructor. Expected Integer, got " + reader.TokenType);
            }

            long     ticks = (long)reader.Value;
            DateTime date  = JsonConvert.ConvertJavaScriptTicksToDateTime(ticks);

            if (!reader.Read())
            {
                throw new Exception("Unexpected end while reading date constructor.");
            }
            if (reader.TokenType != JsonToken.EndConstructor)
            {
                throw new Exception("Unexpected token while reading date constructor. Expected EndConstructor, got " + reader.TokenType);
            }

            WriteValue(date);
        }
示例#2
0
        private void ParseDate(string text)
        {
            string       value = text.Substring(6, text.Length - 8);
            DateTimeKind kind  = DateTimeKind.Utc;

            int index = value.IndexOf('+', 1);

            if (index == -1)
            {
                index = value.IndexOf('-', 1);
            }

            TimeSpan offset = TimeSpan.Zero;

            if (index != -1)
            {
                kind   = DateTimeKind.Local;
                offset = ReadOffset(value.Substring(index));
                value  = value.Substring(0, index);
            }

            long javaScriptTicks = long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);

            DateTime utcDateTime = JsonConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

#if !NET20
            if (_readType == ReadType.ReadAsDateTimeOffset)
            {
                SetToken(JsonToken.Date, new DateTimeOffset(utcDateTime.Add(offset).Ticks, offset));
            }
            else
#endif
            {
                DateTime dateTime;

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

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

                default:
                    dateTime = utcDateTime;
                    break;
                }

                SetToken(JsonToken.Date, dateTime);
            }
        }
示例#3
0
        private void ParseDate(string text)
        {
            string       text2        = text.Substring(6, text.Length - 8);
            DateTimeKind dateTimeKind = DateTimeKind.Utc;
            int          num          = text2.IndexOf('+', 1);

            if (num == -1)
            {
                num = text2.IndexOf('-', 1);
            }
            TimeSpan timeSpan = TimeSpan.Zero;

            if (num != -1)
            {
                dateTimeKind = DateTimeKind.Local;
                timeSpan     = this.ReadOffset(text2.Substring(num));
                text2        = text2.Substring(0, num);
            }
            long     javaScriptTicks = long.Parse(text2, NumberStyles.Integer, CultureInfo.InvariantCulture);
            DateTime dateTime        = JsonConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

            if (this._readType == JsonTextReader.ReadType.ReadAsDateTimeOffset)
            {
                this.SetToken(JsonToken.Date, new DateTimeOffset(dateTime.Add(timeSpan).Ticks, timeSpan));
            }
            else
            {
                DateTime dateTime2;
                if (dateTimeKind != DateTimeKind.Unspecified)
                {
                    if (dateTimeKind != DateTimeKind.Local)
                    {
                        dateTime2 = dateTime;
                    }
                    else
                    {
                        dateTime2 = dateTime.ToLocalTime();
                    }
                }
                else
                {
                    dateTime2 = DateTime.SpecifyKind(dateTime.ToLocalTime(), DateTimeKind.Unspecified);
                }
                this.SetToken(JsonToken.Date, dateTime2);
            }
        }
示例#4
0
        private void ParseDate(string text)
        {
            string       text2        = text.Substring(6, text.Length - 8);
            DateTimeKind dateTimeKind = DateTimeKind.Utc;
            int          num          = text2.IndexOf('+', 1);

            if (num == -1)
            {
                num = text2.IndexOf('-', 1);
            }
            TimeSpan timeSpan = TimeSpan.Zero;

            if (num != -1)
            {
                dateTimeKind = DateTimeKind.Local;
                timeSpan     = ReadOffset(text2.Substring(num));
                text2        = text2.Substring(0, num);
            }
            long     javaScriptTicks = long.Parse(text2, NumberStyles.Integer, CultureInfo.InvariantCulture);
            DateTime dateTime        = JsonConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

            if (_readType == ReadType.ReadAsDateTimeOffset)
            {
                SetToken(JsonToken.Date, new DateTimeOffset(dateTime.Add(timeSpan).Ticks, timeSpan));
                return;
            }
            DateTime dateTime2;

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

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

            default:
                dateTime2 = dateTime;
                break;
            }
            SetToken(JsonToken.Date, dateTime2);
        }
        private void ParseDate(string text)
        {
            string       text2        = text.Substring(6, text.get_Length() - 8);
            DateTimeKind dateTimeKind = 1;
            int          num          = text2.IndexOf('+', 1);

            if (num == -1)
            {
                num = text2.IndexOf('-', 1);
            }
            TimeSpan timeSpan = TimeSpan.Zero;

            if (num != -1)
            {
                dateTimeKind = 2;
                timeSpan     = this.ReadOffset(text2.Substring(num));
                text2        = text2.Substring(0, num);
            }
            long     javaScriptTicks = long.Parse(text2, 7, CultureInfo.get_InvariantCulture());
            DateTime dateTime        = JsonConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);

            if (this._readType == JsonTextReader.ReadType.ReadAsDateTimeOffset)
            {
                this.SetToken(JsonToken.Date, new DateTimeOffset(dateTime.Add(timeSpan).get_Ticks(), timeSpan));
            }
            else
            {
                DateTime dateTime2;
                switch (dateTimeKind)
                {
                case 0:
                    dateTime2 = DateTime.SpecifyKind(dateTime.ToLocalTime(), 0);
                    goto IL_E5;

                case 2:
                    dateTime2 = dateTime.ToLocalTime();
                    goto IL_E5;
                }
                dateTime2 = dateTime;
IL_E5:
                this.SetToken(JsonToken.Date, dateTime2);
            }
        }
        private void ParseDate(string text)
        {
            DateTime     dateTime;
            string       str          = text.Substring(6, text.Length - 8);
            DateTimeKind dateTimeKind = DateTimeKind.Utc;
            int          num          = str.IndexOf('+', 1);

            if (num == -1)
            {
                num = str.IndexOf('-', 1);
            }
            TimeSpan zero = TimeSpan.Zero;

            if (num != -1)
            {
                dateTimeKind = DateTimeKind.Local;
                zero         = this.ReadOffset(str.Substring(num));
                str          = str.Substring(0, num);
            }
            long     num1      = long.Parse(str, NumberStyles.Integer, CultureInfo.InvariantCulture);
            DateTime dateTime1 = JsonConvert.ConvertJavaScriptTicksToDateTime(num1);

            if (this._readType != JsonTextReader.ReadType.ReadAsDateTimeOffset)
            {
                if (dateTimeKind == DateTimeKind.Unspecified)
                {
                    dateTime = DateTime.SpecifyKind(dateTime1.ToLocalTime(), DateTimeKind.Unspecified);
                }
                else
                {
                    dateTime = (dateTimeKind == DateTimeKind.Local ? dateTime1.ToLocalTime() : dateTime1);
                }
                this.SetToken(JsonToken.Date, dateTime);
            }
            else
            {
                DateTime dateTime2 = dateTime1.Add(zero);
                this.SetToken(JsonToken.Date, new DateTimeOffset(dateTime2.Ticks, zero));
            }
        }
示例#7
0
        private void ParseDate(string text)
        {
            string       value = text.Substring(6, text.Length - 8);
            DateTimeKind kind  = DateTimeKind.Utc;

            int index = value.IndexOf('+', 1);

            if (index == -1)
            {
                index = value.IndexOf('-', 1);
            }

            if (index != -1)
            {
                kind  = DateTimeKind.Local;
                value = value.Substring(0, index);
            }

            long     javaScriptTicks = long.Parse(value, NumberStyles.Integer, CultureInfo.InvariantCulture);
            DateTime utcDateTime     = JsonConvert.ConvertJavaScriptTicksToDateTime(javaScriptTicks);
            DateTime dateTime;

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

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

            default:
                dateTime = utcDateTime;
                break;
            }

            SetToken(JsonToken.Date, dateTime);
        }
示例#8
0
        private void WriteConstructorDate(JsonReader reader)
        {
            if (!reader.Read())
            {
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", (Exception)null);
            }
            if (reader.TokenType != JsonToken.Integer)
            {
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected Integer, got " + (object)reader.TokenType, (Exception)null);
            }
            DateTime dateTime = JsonConvert.ConvertJavaScriptTicksToDateTime((long)reader.Value);

            if (!reader.Read())
            {
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", (Exception)null);
            }
            if (reader.TokenType != JsonToken.EndConstructor)
            {
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected EndConstructor, got " + (object)reader.TokenType, (Exception)null);
            }
            this.WriteValue(dateTime);
        }