public void TestTimeRoundTripFromString() { var timeSpanString = "~P0DT01H30M20.123S"; var rqlTimeSpan = new RqlTimeSpan(timeSpanString); var timeSpan = (TimeSpan)rqlTimeSpan; Assert.AreEqual(0, timeSpan.Days); Assert.AreEqual(1, timeSpan.Hours); Assert.AreEqual(30, timeSpan.Minutes); Assert.AreEqual(20, timeSpan.Seconds); Assert.AreEqual(123, timeSpan.Milliseconds); }
public void TestRoundTripFromTimeSpan() { var originalTimeSpan = new TimeSpan(12, 15, 6, 45, 27); var rqlTimeSpan = new RqlTimeSpan(originalTimeSpan); var timeSpan = (TimeSpan)rqlTimeSpan; Assert.AreEqual(12, timeSpan.Days); Assert.AreEqual(15, timeSpan.Hours); Assert.AreEqual(6, timeSpan.Minutes); Assert.AreEqual(45, timeSpan.Seconds); Assert.AreEqual(27, timeSpan.Milliseconds); }
public static bool TryParse(string s, out RqlTimeSpan timeSpan) { try { timeSpan = RqlTimeSpan.Parse(s); return true; } catch (Exception) { timeSpan = new RqlTimeSpan(new TimeSpan(0)); return false; } }
public static bool TryParse(string s, out RqlTimeSpan timeSpan) { try { timeSpan = RqlTimeSpan.Parse(s); return(true); } catch (Exception) { timeSpan = new RqlTimeSpan(new TimeSpan(0)); return(false); } }
public void TestRoundTripFromTimeSpanTimeOnly() { var originalTimeSpan = new TimeSpan(0, 1, 45, 27, 222); var rqlTimeSpan = new RqlTimeSpan(originalTimeSpan); Assert.AreEqual("~P0DT01H45M27.222S", rqlTimeSpan.ToString()); var timeSpan = (TimeSpan)rqlTimeSpan; Assert.AreEqual(0, timeSpan.Days); Assert.AreEqual(1, timeSpan.Hours); Assert.AreEqual(45, timeSpan.Minutes); Assert.AreEqual(27, timeSpan.Seconds); Assert.AreEqual(222, timeSpan.Milliseconds); }
public bool Equals(RqlTimeSpan other) { return this.timeSpan.Equals(other.timeSpan); }
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)); }
public bool Equals(RqlTimeSpan other) { return(this.timeSpan.Equals(other.timeSpan)); }