示例#1
0
 public static bool TryParse(string s, out RqlDateTime dateTime)
 {
     try
     {
         dateTime = RqlDateTime.Parse(s);
         return(true);
     }
     catch (Exception)
     {
         dateTime = new RqlDateTime(new DateTime(0, DateTimeKind.Utc));
         return(false);
     }
 }
示例#2
0
 public static bool TryParse(string s, out RqlDateTime dateTime)
 {
     try
     {
         dateTime = RqlDateTime.Parse(s);
         return true;
     }
     catch (Exception)
     {
         dateTime = new RqlDateTime(new DateTime(0, DateTimeKind.Utc));
         return false;
     }
 }
示例#3
0
        public void TestRoundTripFromString()
        {
            var dateTimeString = "@2014-09-16T10:46:30Z";
            var rqlDateTime = new RqlDateTime(dateTimeString);
            var dateTime = (DateTime)rqlDateTime;

            Assert.AreEqual(DateTimeKind.Utc, dateTime.Kind);
            Assert.AreEqual(2014, dateTime.Year);
            Assert.AreEqual(9, dateTime.Month);
            Assert.AreEqual(16, dateTime.Day);
            Assert.AreEqual(10, dateTime.Hour);
            Assert.AreEqual(46, dateTime.Minute);
            Assert.AreEqual(30, dateTime.Second);
        }
示例#4
0
        public void TestRoundTripFromDateTime()
        {
            var originalDateTime = new DateTime(2014, 9, 16, 10, 51, 26, DateTimeKind.Utc);
            var rqlDateTime = new RqlDateTime(originalDateTime);
            var dateTime = (DateTime)rqlDateTime;

            Assert.AreEqual(DateTimeKind.Utc, dateTime.Kind);
            Assert.AreEqual(2014, dateTime.Year);
            Assert.AreEqual(9, dateTime.Month);
            Assert.AreEqual(16, dateTime.Day);
            Assert.AreEqual(10, dateTime.Hour);
            Assert.AreEqual(51, dateTime.Minute);
            Assert.AreEqual(26, dateTime.Second);
        }
示例#5
0
 public bool Equals(RqlDateTime other)
 {
     return dateTime.Equals(other.dateTime);
 }
示例#6
0
        public RqlToken Next()
        {
            if (stopToken != null)
            {
                return(stopToken);
            }

            if (nextToken != null)
            {
                RqlToken token = nextToken;

                nextToken = null;
                return(token);
            }

            char c = ReadChar();

            while (c != '\0' && Char.IsWhiteSpace(c))
            {
                c = ReadChar();
            }

            int tokenOffset = this.offset - 1;

            if (c == '\0')
            {
                return(stopToken = RqlToken.End(offset));
            }

            if (Char.IsLetter(c))
            {
                sb.Clear();
                sb.Append(c);

                c = ReadChar();

                bool lastCharWasDot = false;

                while (c != 0 && (Char.IsLetterOrDigit(c)) || c == '.')
                {
                    sb.Append(c);

                    if (c == '.')
                    {
                        if (lastCharWasDot)
                        {
                            goto Error;
                        }

                        lastCharWasDot = true;
                    }
                    else
                    {
                        lastCharWasDot = false;
                    }

                    c = ReadChar();
                }

                UnreadChar();

                string s = sb.ToString();

                if (s == "true")
                {
                    return(RqlToken.Constant(tokenOffset, (object)true));
                }
                else if (s == "false")
                {
                    return(RqlToken.Constant(tokenOffset, (object)false));
                }
                else if (s == "null")
                {
                    return(RqlToken.Constant(tokenOffset, null));
                }
                else
                {
                    return(RqlToken.Identifier(tokenOffset, s));
                }
            }
            else if (Char.IsDigit(c) || c == '-')
            {
                sb.Clear();
                sb.Append(c);
                c = ReadChar();

                if (sb[0] == '-' && !Char.IsDigit(c))
                {
                    goto Error;
                }

                while (Char.IsDigit(c))
                {
                    sb.Append(c);
                    c = ReadChar();
                }

                if (c == '.')
                {
                    sb.Append(c);
                    c = ReadChar();

                    while (Char.IsDigit(c))
                    {
                        sb.Append(c);
                        c = ReadChar();
                    }

                    UnreadChar();

                    Double n;

                    if (Double.TryParse(sb.ToString(), out n))
                    {
                        return(RqlToken.Constant(tokenOffset, n));
                    }
                }
                else
                {
                    UnreadChar();

                    Int32 n;

                    if (Int32.TryParse(sb.ToString(), out n))
                    {
                        return(RqlToken.Constant(tokenOffset, n));
                    }
                }
            }
            else if (c == '$')
            {
                sb.Clear();
                sb.Append(c);
                c = ReadChar();

                while (Char.IsLetterOrDigit(c))
                {
                    sb.Append(c);
                    c = ReadChar();
                }

                UnreadChar();

                if (sb.Length > 0)
                {
                    return(RqlToken.Constant(tokenOffset, new RqlId(sb.ToString())));
                }
            }
            else if (c == '@')
            {
                sb.Clear();
                sb.Append(c);
                c = ReadChar();

                while (c != 'Z')
                {
                    sb.Append(c);
                    c = ReadChar();
                }

                sb.Append(c);

                RqlDateTime dateTime;

                if (RqlDateTime.TryParse(sb.ToString(), out dateTime))
                {
                    return(RqlToken.Constant(tokenOffset, dateTime));
                }
            }
            else if (c == '~')
            {
                sb.Clear();
                sb.Append(c);
                c = ReadChar();

                while (c != 'S')
                {
                    sb.Append(c);
                    c = ReadChar();
                }

                sb.Append(c);

                RqlTimeSpan timeSpan;

                if (RqlTimeSpan.TryParse(sb.ToString(), out timeSpan))
                {
                    return(RqlToken.Constant(tokenOffset, timeSpan));
                }
            }
            else if (c == '\'')
            {
                sb.Clear();
                c = ReadChar();

                while (c != '\0' && c != '\'')
                {
                    sb.Append(c);
                    c = ReadChar();
                }

                if (c == '\'')
                {
                    return(RqlToken.Constant(tokenOffset, sb.ToString()));
                }
            }
            else
            {
                switch ((char)c)
                {
                case ',':
                    return(RqlToken.Comma(tokenOffset));

                case '(':
                    return(RqlToken.LeftParen(tokenOffset));

                case ')':
                    return(RqlToken.RightParen(tokenOffset));
                }
            }

Error:
            return(stopToken = RqlToken.Error(tokenOffset));
        }
示例#7
0
 public PostResponse(RqlDateTime created, RqlId id)
 {
     Created = created;
     Id = id;
 }
示例#8
0
 public PutResponse(RqlDateTime updated)
 {
     Updated = updated;
 }
示例#9
0
 public bool Equals(RqlDateTime other)
 {
     return(dateTime.Equals(other.dateTime));
 }