public void VisitDateTimeToken(DateTimeToken token) { this._sb.Append(token.Text); }
public void VisitDateTimeToken(DateTimeToken token) { }
public void Merge(DateTimePredicateAttribute spa) { Token = spa.Token != DateTimeToken.None ? spa.Token : Token; Upsert |= spa.Upsert; }
/// <summary> /// Parses a string into a <see cref="TimerStartToken"/>. /// </summary> /// <param name="str">A string representation of a <see cref="TimerStartToken"/>.</param> /// <param name="provider">An <see cref="IFormatProvider"/>.</param> /// <returns>The <see cref="TimerStartToken"/> parsed from the string.</returns> /// <exception cref="ArgumentNullException">If <paramref name="str"/> or <paramref name="provider"/> is /// <c>null</c>.</exception> /// <exception cref="FormatException">If <paramref name="str"/> is not a supported representation of a <see /// cref="TimerStartToken"/>.</exception> protected override TimerStartToken ParseInternal(string str, IFormatProvider provider) { foreach (PatternDefinition patternDefinition in GetAllDateTimePatternDefinitions(provider)) { try { Match match = Regex.Match(str, patternDefinition.Pattern, RegexOptions); if (match.Success) { DateTimeToken dateTimeToken = new DateTimeToken( patternDefinition.DateTokenParser.Parse(match, provider), patternDefinition.TimeTokenParser.Parse(match, provider)); if (dateTimeToken.IsValid) { return dateTimeToken; } } } catch { // Try the next pattern set continue; } } // Could not find a matching pattern throw new FormatException(); }
public void GetEndTimeWith034515And20150101At120000Returns20150102At034515() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 12, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new EmptyDateToken(), TimeToken = new NormalTimeToken { HourPeriod = HourPeriod.Am, Hour = 3, Minute = 45, Second = 15 } }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 1, 2, 3, 45, 15), endTime); }
public void GetEndTimeWithMidnightAnd20150101At000000Returns20150102At000000() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new EmptyDateToken(), TimeToken = new SpecialTimeToken { SpecialTime = SpecialTime.Midnight } }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 1, 2, 0, 0, 0), endTime); }
public void GetEndTimeWithChristmasDayAnd20151201At000000Returns20151225At000000() { // Arrange DateTime startTime = new DateTime(2015, 12, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new SpecialDateToken { SpecialDate = SpecialDate.ChristmasDay }, TimeToken = new EmptyTimeToken() }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 12, 25, 0, 0, 0), endTime); }
public void GetEndTimeWithNewYearsEveAnd20151201At000000Returns20151231At000000() { // Arrange DateTime startTime = new DateTime(2015, 12, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new SpecialDateToken { SpecialDate = SpecialDate.NewYearsEve }, TimeToken = new EmptyTimeToken() }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 12, 31, 0, 0, 0), endTime); }
public void GetEndTimeWithFebruary142016And20150101At000000Returns20160214At120000() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new NormalDateToken { Year = 2016, Month = 2, Day = 14 }, TimeToken = new EmptyTimeToken() }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2016, 2, 14, 0, 0, 0), endTime); }
public void GetEndTimeWithTomorrowAnd20150101At000000Returns20150102At120000() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new RelativeDateToken { RelativeDate = RelativeDate.Tomorrow }, TimeToken = new NormalTimeToken { HourPeriod = HourPeriod.Pm, Hour = 12, Minute = 0, Second = 0 } }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 1, 2, 12, 0, 0), endTime); }
public void GetEndTimeWithFridayNextWeekAnd20150101At000000Returns20150109At000000() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new DayOfWeekDateToken { DayOfWeek = DayOfWeek.Friday, DayOfWeekRelation = DayOfWeekRelation.NextWeek }, TimeToken = new EmptyTimeToken() }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 1, 9, 0, 0, 0), endTime); }
public void GetEndTimeWithMondayAfterNextAnd20150101At000000Returns20150112At000000() { // Arrange DateTime startTime = new DateTime(2015, 1, 1, 0, 0, 0); DateTimeToken dateTimeToken = new DateTimeToken { DateToken = new DayOfWeekDateToken { DayOfWeek = DayOfWeek.Monday, DayOfWeekRelation = DayOfWeekRelation.AfterNext }, TimeToken = new EmptyTimeToken() }; // Act DateTime endTime = dateTimeToken.GetEndTime(startTime); // Assert Assert.AreEqual(new DateTime(2015, 1, 12, 0, 0, 0), endTime); }
public void VisitDateTimeToken(DateTimeToken token) { _plainText += token.Text; }
public void VisitDateTimeToken(DateTimeToken token) { // not required with this implementation }
public override Core.Tokenization.Token Recognize(string s, int from, bool allowTokenBundles, ref int consumedLength) { int winningCalendar = -1; int winningPattern = -1; int winningLength = -1; DateTime winningValue = default(DateTime); for (int c = 0; c < _CalendarPatterns.Count; ++c) { for (int p = 0; p < _CalendarPatterns[c].Patterns.Count; ++p) { DateTime output; Match m = _CalendarPatterns[c].Patterns[p].Match(s, from, out output); if (m != null) { // don't check for winner if winning length too low if (m.Length < winningLength) { continue; } if (VerifyContextConstraints(s, m.Index + m.Length)) { DateTime localValue; if (output != default(DateTime)) { winningCalendar = c; winningLength = m.Length; winningPattern = p; winningValue = output; } else { if (DateTime.TryParse(s.Substring(from, m.Length), _CalendarPatterns[c].Culture, System.Globalization.DateTimeStyles.None, out localValue)) { winningCalendar = c; winningLength = m.Length; winningPattern = p; winningValue = localValue; } } } } } } if (winningPattern >= 0) { consumedLength = winningLength; DateTimeToken t = new DateTimeToken(s.Substring(from, winningLength), winningValue, _CalendarPatterns[winningCalendar].Patterns[winningPattern].PatternType); return(t); } else { return(null); } }