コード例 #1
0
 public void VisitDateTimeToken(DateTimeToken token)
 {
     this._sb.Append(token.Text);
 }
コード例 #2
0
 public void VisitDateTimeToken(DateTimeToken token)
 {
 }
コード例 #3
0
 public void Merge(DateTimePredicateAttribute spa)
 {
     Token   = spa.Token != DateTimeToken.None ? spa.Token : Token;
     Upsert |= spa.Upsert;
 }
コード例 #4
0
ファイル: DateTimeToken.cs プロジェクト: ZhuXiaomin/Hourglass
            /// <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();
            }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
		public void VisitDateTimeToken(DateTimeToken token)
		{
			_plainText += token.Text;
		}
コード例 #14
0
 public void VisitDateTimeToken(DateTimeToken token)
 {
     // not required with this implementation
 }
コード例 #15
0
        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);
            }
        }