Beispiel #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>
            protected override TimeToken ParseInternal(Match match, IFormatProvider provider)
            {
                SpecialTimeDefinition specialTimeDefinition = GetSpecialTimeDefinitionForMatch(match);

                if (specialTimeDefinition == null)
                {
                    throw new FormatException();
                }

                return(new SpecialTimeToken {
                    SpecialTime = specialTimeDefinition.SpecialTime
                });
            }
Beispiel #2
0
        /// <summary>
        /// Returns the next date and time after <paramref name="minDate"/> that is represented by this token.
        /// </summary>
        /// <remarks>
        /// This method may return a date and time that is before <paramref name="minDate"/> if there is no date and
        /// time after <paramref name="minDate"/> that is represented by this token.
        /// </remarks>
        /// <param name="minDate">The minimum date and time to return.</param>
        /// <param name="datePart">The date part of the date and time to return.</param>
        /// <returns>The next date and time after <paramref name="minDate"/> that is represented by this token.
        /// </returns>
        /// <exception cref="InvalidOperationException">If this token is not valid.</exception>
        public override DateTime ToDateTime(DateTime minDate, DateTime datePart)
        {
            this.ThrowIfNotValid();

            SpecialTimeDefinition specialTimeDefinition = this.GetSpecialTimeDefinition();

            return(new DateTime(
                       datePart.Year,
                       datePart.Month,
                       datePart.Day,
                       specialTimeDefinition.Hour,
                       specialTimeDefinition.Minute,
                       specialTimeDefinition.Second));
        }
Beispiel #3
0
        /// <summary>
        /// Returns a string that represents the current object.
        /// </summary>
        /// <param name="provider">An <see cref="IFormatProvider"/> to use.</param>
        /// <returns>A string that represents the current object.</returns>
        public override string ToString(IFormatProvider provider)
        {
            try
            {
                this.ThrowIfNotValid();

                SpecialTimeDefinition specialTimeDefinition = this.GetSpecialTimeDefinition();
                return(specialTimeDefinition.GetName(provider));
            }
            catch
            {
                return(this.GetType().ToString());
            }
        }