示例#1
0
        public void AddValidation(ClientModelValidationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            string propertyDisplayName = context.ModelMetadata.GetDisplayName();
            var    errorMessage        = FormatErrorMessage(propertyDisplayName);



            AddAttribute(context.Attributes, "data-val", "true");

            AddAttribute(context.Attributes, "data-val-valid-date-format", "The input date/datetime format is not valid! Please prefer: '01-Jan-2019' format.");
            AddAttribute(context.Attributes, "data-val-currenttime", $"{propertyDisplayName} can not be greater than today's date.");
            AddAttribute(context.Attributes, "data-val-maxage", errorMessage);

            var years  = Years.ToString(CultureInfo.InvariantCulture);
            var months = Months.ToString(CultureInfo.InvariantCulture);
            var days   = Days.ToString(CultureInfo.InvariantCulture);

            AddAttribute(context.Attributes, "data-val-maxage-years", years);
            AddAttribute(context.Attributes, "data-val-maxage-months", months);
            AddAttribute(context.Attributes, "data-val-maxage-days", days);
        }
示例#2
0
        /// <summary>Returns the string representation of the value of this instance.</summary>
        /// <param name="format">Format string using the usual characters to interpret custom datetime - as per standard Timespan custom formats</param>
        /// <returns>A string that represents the value of this instance.</returns>
        public String ToString(String format, IFormatProvider provider)
        {
            //parse and replace the format stuff
            MatchCollection matches = Regex.Matches(format, "([a-zA-z])\\1{0,}");

            for (int i = matches.Count - 1; i >= 0; i--)
            {
                Match m = matches[i];
                Int32 mIndex = m.Index, mLength = m.Length;

                if (mIndex > 0 && format[m.Index - 1] == '\\')
                {
                    if (m.Length == 1)
                    {
                        continue;
                    }
                    else
                    {
                        mIndex++;
                        mLength--;
                    }
                }
                switch (m.Value[0])
                {
                case 'y':
                    format = format.Substring(0, mIndex) + Years.ToString("D" + mLength) + format.Substring(mIndex + mLength);
                    break;

                case 'd':
                    format = format.Substring(0, mIndex) + Days.ToString("D" + mLength) + format.Substring(mIndex + mLength);
                    break;

                case 'h':
                    format = format.Substring(0, mIndex) + Hours.ToString("D" + mLength.Clamp(1, KSPDateStructure.HoursPerDay.ToString().Length)) + format.Substring(mIndex + mLength);
                    break;

                case 'm':
                    format = format.Substring(0, mIndex) + Minutes.ToString("D" + mLength.Clamp(1, KSPDateStructure.MinutesPerHour.ToString().Length)) + format.Substring(mIndex + mLength);
                    break;

                case 's':
                    format = format.Substring(0, mIndex) + Seconds.ToString("D" + mLength.Clamp(1, KSPDateStructure.SecondsPerMinute.ToString().Length)) + format.Substring(mIndex + mLength);
                    break;

                default:
                    break;
                }
            }

            //Now strip out the \ , but not multiple \\
            format = Regex.Replace(format, "\\\\(?=[a-z])", "");

            return(format);
            //if (KSPDateStructure.CalendarType == CalendarTypeEnum.Earth)
            //    return String.Format(format, _EarthDateTime);
            //else
            //    return String.Format(format, this); //"TEST";
        }
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            if (Signum == -1)
            {
                builder.Append("-");
            }

            builder.Append("P");
            if (Years != 0)
            {
                builder.Append(Years.ToString());
                builder.Append("Y");
            }
            if (Months != 0)
            {
                builder.Append(Months.ToString());
                builder.Append("M");
            }
            if (Weeks != 0)
            {
                builder.Append(Weeks.ToString());
                builder.Append("W");
            }
            if (Days != 0 || (Years == 0 && Months == 0 && Weeks == 0 && Hours == 0 && Minutes == 0 && Seconds == 0 && FractionOfSecond == 0))
            {
                builder.Append(Days.ToString());
                builder.Append("D");
            }
            if (!(Hours == 0 && Minutes == 0 && Seconds == 0 && FractionOfSecond == 0))
            {
                builder.Append("T");
                if (Hours != 0)
                {
                    builder.Append(Hours.ToString());
                    builder.Append("H");
                }
                if (Minutes != 0)
                {
                    builder.Append(Minutes.ToString());
                    builder.Append("M");
                }
                if (Seconds != 0 || FractionOfSecond != 0M)
                {
                    builder.Append(Seconds.ToString());
                    if (FractionOfSecond != 0)
                    {
                        builder.Append(FractionOfSecond.ToString().Substring(1));
                    }
                    builder.Append("S");
                }
            }
            return(builder.ToString());
        }
示例#4
0
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder("P");

            if (Years != 0)
            {
                sb.Append(Years.ToString());
                sb.Append("Y");
            }
            if (Months != 0)
            {
                sb.Append(Months.ToString());
                sb.Append("M");
            }
            if (Weeks != 0)
            {
                sb.Append(Weeks.ToString());
                sb.Append("W");
            }
            if (Days != 0)
            {
                sb.Append(Days.ToString());
                sb.Append("D");
            }
            if (Hours != 0 || Minutes != 0 || Seconds != 0 || Millis != 0)
            {
                sb.Append("T");
            }
            if (Hours != 0)
            {
                sb.Append(Hours.ToString());
                sb.Append("H");
            }
            if (Minutes != 0)
            {
                sb.Append(Minutes.ToString());
                sb.Append("M");
            }
            if (Seconds != 0 || Millis != 0)
            {
                sb.Append(Seconds.ToString());
                if (Millis != 0)
                {
                    sb.Append(".");
                    sb.Append(Millis.ToString("000"));
                }
                sb.Append("S");
            }
            return(sb.ToString());
        }
示例#5
0
        /// <summary>
        /// Output GEDCOM formatted text representing the age.
        /// </summary>
        /// <param name="tw">The writer to output to.</param>
        /// <param name="level">The GEDCOM level.</param>
        public void Output(TextWriter tw, int level)
        {
            tw.Write(Environment.NewLine);
            tw.Write(level);
            tw.Write(" AGE ");

            // never write out INFANT CHILD, this potentially loses information,
            // always write out < 1 or < 8  and includes months days if set
            if (StillBorn)
            {
                tw.Write("STILLBORN");
            }
            else
            {
                if (Equality < 0)
                {
                    tw.Write("< ");
                }
                else if (Equality > 0)
                {
                    tw.Write("> ");
                }

                if (Years != -1)
                {
                    tw.Write(Years.ToString());
                    tw.Write("y ");
                }

                if (Months != -1)
                {
                    tw.Write(Months.ToString());
                    tw.Write("m ");
                }
                else if (Days != -1)
                {
                    tw.Write(Days.ToString());
                    tw.Write("d");
                }
            }
        }
        /// <summary>
        /// Creates a key-value-pair list of all set parameter-values.
        /// Each key-value-pair consists of the parameter name as key and its value.
        /// </summary>
        /// <returns>A key-value-pair list of all set parameter-values.</returns>
        public virtual IDictionary <string, object> GetParameters()
        {
            var parameters = new Dictionary <string, object>();

            if (HasYearsSet)
            {
                parameters.Add("years", Years.ToString());
            }

            if (HasGenresSet)
            {
                parameters.Add("genres", string.Join(",", Genres));
            }

            if (HasLanguagesSet)
            {
                parameters.Add("languages", string.Join(",", Languages));
            }

            if (HasCountriesSet)
            {
                parameters.Add("countries", string.Join(",", Countries));
            }

            if (HasRuntimesSet())
            {
                var runtimes = Runtimes.Value;
                parameters.Add("runtimes", $"{runtimes.Begin.ToString()}-{runtimes.End.ToString()}");
            }

            if (HasRatingsSet())
            {
                var ratings = Ratings.Value;
                parameters.Add("ratings", $"{ratings.Begin.ToString()}-{ratings.End.ToString()}");
            }

            return(parameters);
        }
        /// <summary>Returns the string representation of the value of this instance.</summary>
        /// <param name="format">Format string using the usual characters to interpret custom datetime - as per standard Timespan custom formats</param>
        /// <param name="provider">Should be null in almost all cases.</param>
        /// <returns>A string that represents the value of this instance.</returns>
        public String ToString(String format, IFormatProvider provider)
        {
            //parse and replace the format stuff
            var matches = Regex.Matches(format, "([a-zA-z])\\1{0,}");

            for (var i = matches.Count - 1; i >= 0; i--)
            {
                var m       = matches[i];
                var mIndex  = m.Index;
                var mLength = m.Length;

                if (mIndex > 0 && format[m.Index - 1] == '\\')
                {
                    if (m.Length == 1)
                    {
                        continue;
                    }
                    else
                    {
                        mIndex++;
                        mLength--;
                    }
                }
                switch (m.Value[0])
                {
                case 'y':
                    format = format.Substring(0, mIndex) +
                             Years.ToString("D" + mLength) +
                             format.Substring(mIndex + mLength);
                    break;

                case 'd':
                    format = format.Substring(0, mIndex) +
                             Days.ToString("D" + mLength) +
                             format.Substring(mIndex + mLength);
                    break;

                case 'h':
                    var hpdLength = KSPDateStructure.HoursPerDay.ToString().Length;

                    format = format.Substring(0, mIndex) +
                             Hours.ToString("D" + mLength.Clamp(1, hpdLength)) +
                             format.Substring(mIndex + mLength);
                    break;

                case 'm':
                    var mphLength = KSPDateStructure.MinutesPerHour.ToString().Length;

                    format = format.Substring(0, mIndex) +
                             Minutes.ToString("D" + mLength.Clamp(1, mphLength)) +
                             format.Substring(mIndex + mLength);
                    break;

                case 's':
                    var spmLength = KSPDateStructure.SecondsPerMinute.ToString().Length;

                    format = format.Substring(0, mIndex) +
                             Seconds.ToString("D" + mLength.Clamp(1, spmLength)) +
                             format.Substring(mIndex + mLength);
                    break;

                default:
                    break;
                }
            }

            //Now strip out the \ , but not multiple \\
            format = Regex.Replace(format, "\\\\(?=[a-z])", "");

            return(format);
        }