Exemple #1
0
            /// <summary>
            /// Parses a <see cref="Match"/> into a <see cref="TimeToken"/>.
            /// </summary>
            /// <param name="match">A <see cref="Match"/> representation of a <see cref="TimeToken"/>.</param>
            /// <param name="provider">An <see cref="IFormatProvider"/>.</param>
            /// <returns>The <see cref="TimeToken"/> parsed from the <see cref="Match"/>.</returns>
            /// <exception cref="ArgumentNullException">If <paramref name="match"/> or <paramref name="provider"/> is
            /// <c>null</c>.</exception>
            /// <exception cref="FormatException">If the <paramref name="match"/> is not a supported representation of
            /// a <see cref="TimeToken"/>.</exception>
            public TimeToken Parse(Match match, IFormatProvider provider)
            {
                if (match == null)
                {
                    throw new ArgumentNullException("match");
                }

                if (!match.Success)
                {
                    throw new FormatException();
                }

                TimeToken timeToken = this.ParseInternal(match, provider);

                if (!timeToken.IsValid)
                {
                    throw new FormatException();
                }

                return(timeToken);
            }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DateTimeToken"/> class.
 /// </summary>
 /// <param name="dateToken">The date part of an instant in time.</param>
 /// <param name="timeToken">The time part of an instant in time.</param>
 public DateTimeToken(DateToken dateToken, TimeToken timeToken)
 {
     this.DateToken = dateToken;
     this.TimeToken = timeToken;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PatternDefinition"/> class.
 /// </summary>
 /// <param name="dateTokenParser">The <see cref="DateToken.Parser"/> for the date token part of the
 /// pattern.</param>
 /// <param name="timeTokenParser">The <see cref="TimeToken.Parser"/> for the time token part of the
 /// pattern.</param>
 /// <param name="pattern">The regular expression that matches a <see cref="DateTimeToken"/>.</param>
 public PatternDefinition(DateToken.Parser dateTokenParser, TimeToken.Parser timeTokenParser, string pattern)
 {
     this.DateTokenParser = dateTokenParser;
     this.TimeTokenParser = timeTokenParser;
     this.Pattern = pattern;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DateTimeToken"/> class.
 /// </summary>
 /// <param name="dateToken">The date part of an instant in time.</param>
 /// <param name="timeToken">The time part of an instant in time.</param>
 public DateTimeToken(DateToken dateToken, TimeToken timeToken)
 {
     this.DateToken = dateToken;
     this.TimeToken = timeToken;
 }
            /// <summary>
            /// Returns a list of <see cref="PatternDefinition"/> objects representing the patterns supported by the
            /// combination of the specified <see cref="DateToken.Parser"/> and <see cref="TimeToken.Parser"/>.
            /// </summary>
            /// <param name="dateTokenParser">A <see cref="DateToken.Parser"/>.</param>
            /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
            /// <param name="provider">The <see cref="IFormatProvider"/> that will be used when parsing.</param>
            /// <returns>A list of <see cref="PatternDefinition"/> objects.</returns>
            private static List<PatternDefinition> GetDateTimePatternDefinitions(DateToken.Parser dateTokenParser, TimeToken.Parser timeTokenParser, IFormatProvider provider)
            {
                if (!dateTokenParser.IsCompatibleWith(timeTokenParser) || !timeTokenParser.IsCompatibleWith(dateTokenParser))
                {
                    return new List<PatternDefinition>();
                }

                List<PatternDefinition> list = new List<PatternDefinition>();

                foreach (string datePartPattern in dateTokenParser.GetPatterns(provider))
                {
                    foreach (string timePartPattern in timeTokenParser.GetPatterns(provider))
                    {
                        string dateTimePattern = GetDateTimePattern(datePartPattern, timePartPattern, provider);
                        list.Add(new PatternDefinition(dateTokenParser, timeTokenParser, dateTimePattern));

                        string timeDatePattern = GetTimeDatePattern(timePartPattern, datePartPattern, provider);
                        list.Add(new PatternDefinition(dateTokenParser, timeTokenParser, timeDatePattern));
                    }
                }

                return list;
            }
 /// <summary>
 /// Asserts that a <see cref="TimeToken"/> is an instance of the <see cref="EmptyTimeToken"/> class.
 /// </summary>
 /// <param name="actual">The actual <see cref="TimeToken"/>.</param>
 private static void AssertIsEmpty(TimeToken actual)
 {
     Assert.AreEqual(typeof(EmptyTimeToken), actual.GetType());
 }
 /// <summary>
 /// Asserts that a <see cref="TimeToken"/> is an instance of the <see cref="SpecialTimeToken"/> class and that
 /// its value is equal to the specified parameters.
 /// </summary>
 /// <param name="actual">The actual <see cref="TimeToken"/>.</param>
 /// <param name="expectedSpecialTime">The expected <see cref="SpecialTime"/>.</param>
 private static void AssertAreEqual(TimeToken actual, SpecialTime expectedSpecialTime)
 {
     Assert.AreEqual(typeof(SpecialTimeToken), actual.GetType());
     Assert.AreEqual(expectedSpecialTime, ((SpecialTimeToken)actual).SpecialTime);
 }
 /// <summary>
 /// Asserts that a <see cref="TimeToken"/> is an instance of the <see cref="NormalTimeToken"/> class and that
 /// its value is equal to the specified parameters.
 /// </summary>
 /// <param name="actual">The actual <see cref="TimeToken"/>.</param>
 /// <param name="expectedHourPeriod">The expected <see cref="HourPeriod"/>.</param>
 /// <param name="expectedHour">The expected hour.</param>
 /// <param name="expectedMinute">The expected minute.</param>
 /// <param name="expectedSecond">The expected second.</param>
 private static void AssertAreEqual(TimeToken actual, HourPeriod expectedHourPeriod, int expectedHour, int expectedMinute = 0, int expectedSecond = 0)
 {
     Assert.AreEqual(typeof(NormalTimeToken), actual.GetType());
     Assert.AreEqual(expectedHourPeriod, ((NormalTimeToken)actual).HourPeriod);
     Assert.AreEqual(expectedHour, ((NormalTimeToken)actual).Hour);
     Assert.AreEqual(expectedMinute, ((NormalTimeToken)actual).Minute);
     Assert.AreEqual(expectedSecond, ((NormalTimeToken)actual).Second);
 }
Exemple #9
0
 /// <summary>
 /// Returns a value indicating whether this parser can be used in conjunction with a specified <see
 /// cref="TimeToken.Parser"/>.
 /// </summary>
 /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
 /// <returns>A value indicating whether this parser can be used in conjunction with the specified <see
 /// cref="TimeToken.Parser"/>.</returns>
 public virtual bool IsCompatibleWith(TimeToken.Parser timeTokenParser)
 {
     return true;
 }
 /// <summary>
 /// Returns a value indicating whether this parser can be used in conjunction with a specified <see
 /// cref="TimeToken.Parser"/>.
 /// </summary>
 /// <param name="timeTokenParser">A <see cref="TimeToken.Parser"/>.</param>
 /// <returns>A value indicating whether this parser can be used in conjunction with the specified <see
 /// cref="TimeToken.Parser"/>.</returns>
 public override bool IsCompatibleWith(TimeToken.Parser timeTokenParser)
 {
     return !(timeTokenParser is EmptyTimeToken.Parser);
 }