public static string Format(BirthDate bdate, BirthDateFormatInfo info)
 {
     if (bdate == null) throw new ArgumentNullException("bdate");
     if (info == null) info = new BirthDateFormatInfo();
     
     return Format(bdate, info.Pattern, info.RepresentMissingComponentsWithX);
 }
Esempio n. 2
0
            public static BirthDate Parse(string s, BirthDateFormatInfo info)
            {
                if (string.IsNullOrEmpty(s))
                {
                    throw new ArgumentNullException("s");
                }
                if (info == null)
                {
                    info = new BirthDateFormatInfo();
                }

                // First let's try to parse this as a regular date
                try
                {
                    var dt = DateTime.Parse(s, info.DateTimeFormatInfo);
                    return(new BirthDate(dt));
                }
                catch (Exception ex)
                {
                    var debugException = ex;
                    // Well, this means we probably have 'missing' components
                }

                // This did not work let's parse the string by hand
                return(Parse(s, info.Pattern, GetY2kPivot(info)));
            }
Esempio n. 3
0
 /// <summary>
 /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
 /// </summary>
 /// <param name="text">The text to parse.</param>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>A <see cref="BirthDate"/> object equivalent to the birth date specified in <paramref name="text"/>.</returns>
 public static BirthDate Parse(string text, BirthDateFormatInfo info)
 {
     if (string.IsNullOrEmpty(text))
     {
         throw new ArgumentNullException("text");
     }
     return(Parser.Parse(text, info ?? new BirthDateFormatInfo()));
 }
Esempio n. 4
0
        /// <summary>
        /// Similar to <see cref="Parse" /> but accepts <c>null</c> and empty strings
        /// and returns a <see cref="System.Nullable{Siti.BirthDate}" /> object.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <param name="info">An object containing formatting and parsing information.</param>
        /// <returns>
        /// An instance of <see cref="System.Nullable{Siti.BirthDate}" />
        /// </returns>
        public static BirthDate?ParseToNullable(string text, BirthDateFormatInfo info)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new BirthDate?());
            }

            var bdate = Parse(text, info);

            return(new BirthDate?(bdate));
        }
Esempio n. 5
0
        /// <summary>
        /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <param name="culture">The culture used to parse.</param>
        /// <returns>A <see cref="BirthDate"/> object equivalent to the birth date specified in <paramref name="text"/>.</returns>
        /// <exception cref="System.ArgumentNullException">text</exception>
        public static BirthDate Parse(string text, CultureInfo culture = null)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }

            var formatInfo = new BirthDateFormatInfo(culture, true);

            return(Parse(text, formatInfo));
        }
Esempio n. 6
0
            private static int GetY2kPivot(BirthDateFormatInfo info)
            {
                if (info == null ||
                    info.DateTimeFormatInfo == null ||
                    info.DateTimeFormatInfo.Calendar == null)
                {
                    return(defaultY2kPivot);
                }

                return(info.DateTimeFormatInfo.Calendar.TwoDigitYearMax - 2000);
            }
Esempio n. 7
0
            public static string Format(BirthDate bdate, BirthDateFormatInfo info)
            {
                if (bdate == null)
                {
                    throw new ArgumentNullException("bdate");
                }
                if (info == null)
                {
                    info = new BirthDateFormatInfo();
                }

                return(Format(bdate, info.Pattern, info.RepresentMissingComponentsWithX));
            }
Esempio n. 8
0
 /// <summary>
 /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
 /// The return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="text">The text to parse.</param>
 /// <param name="result">When this method returns, contains <see cref="BirthDate" /> object equivalent
 /// to the birth date contained in <paramref name="text" /> if the conversion succeeded;
 /// or <see cref="BirthDate.Empty" /> if the conversion failed.
 /// The conversion fails if <paramref name="text" /> is null or empty or is not
 /// in the correct format. This parameter is passed uninitialized.</param>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>
 ///   <c>True</c> if <paramref name="text" /> was converted successfully; otherwise, false.
 /// </returns>
 public static bool TryParse(string text, out BirthDate result, BirthDateFormatInfo info)
 {
     result = BirthDate.Empty;
     try
     {
         result = Parse(text, info);
         return(true);
     }
     catch (Exception ex)
     {
         var debugException = ex;
         return(false);
     }
 }
            public static BirthDate Parse(string s, BirthDateFormatInfo info)
            {
                if (string.IsNullOrEmpty(s)) throw new ArgumentNullException("s");
                if (info == null) info = new BirthDateFormatInfo();

                // First let's try to parse this as a regular date                
                try
                {
                    var dt = DateTime.Parse(s, info.DateTimeFormatInfo);
                    return new BirthDate(dt);
                }
                catch (Exception ex)
                {
                    var debugException = ex;
                    // Well, this means we probably have 'missing' components
                }

                // This did not work let's parse the string by hand
                return Parse(s, info.Pattern, GetY2kPivot(info));
            }
Esempio n. 10
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance formatted
 /// according to the specified <see cref="BirthDateFormatInfo"/> object.
 /// </summary>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public string ToString(BirthDateFormatInfo info)
 {
     return(Formatter.Format(this, info ?? new BirthDateFormatInfo()));
 }
Esempio n. 11
0
        /// <summary>
        /// Returns a <see cref="System.String" /> that represents this instance formatted
        /// according to the specified <paramref name="culture"/>.
        /// </summary>
        /// <param name="culture">The culture used for formatting.</param>
        /// <returns>
        /// A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public string ToString(CultureInfo culture)
        {
            var formatInfo = new BirthDateFormatInfo(culture, true);

            return(ToString(formatInfo));
        }
        /// <summary>
        /// Similar to <see cref="Parse" /> but accepts <c>null</c> and empty strings
        /// and returns a <see cref="System.Nullable{Siti.BirthDate}" /> object.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <param name="info">An object containing formatting and parsing information.</param>
        /// <returns>
        /// An instance of <see cref="System.Nullable{Siti.BirthDate}" />
        /// </returns>
        public static BirthDate? ParseToNullable(string text, BirthDateFormatInfo info)
        {
            if (string.IsNullOrEmpty(text)) return new BirthDate?();

            var bdate = Parse(text, info);
            return new BirthDate?(bdate);
        }
        /// <summary>
        /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <param name="culture">The culture used to parse.</param>
        /// <returns>A <see cref="BirthDate"/> object equivalent to the birth date specified in <paramref name="text"/>.</returns>
        /// <exception cref="System.ArgumentNullException">text</exception>
        public static BirthDate Parse(string text, CultureInfo culture = null)
        {
            if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text");

            var formatInfo = new BirthDateFormatInfo(culture, true);
            return Parse(text, formatInfo);
        }
 /// <summary>
 /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
 /// The return value indicates whether the conversion succeeded.
 /// </summary>
 /// <param name="text">The text to parse.</param>
 /// <param name="result">When this method returns, contains <see cref="BirthDate" /> object equivalent
 /// to the birth date contained in <paramref name="text" /> if the conversion succeeded;
 /// or <see cref="BirthDate.Empty" /> if the conversion failed.
 /// The conversion fails if <paramref name="text" /> is null or empty or is not
 /// in the correct format. This parameter is passed uninitialized.</param>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>
 ///   <c>True</c> if <paramref name="text" /> was converted successfully; otherwise, false.
 /// </returns>
 public static bool TryParse(string text, out BirthDate result, BirthDateFormatInfo info)
 {
     result = BirthDate.Empty;
     try
     {
         result = Parse(text, info);
         return true;
     }
     catch (Exception ex)
     {
         var debugException = ex;
         return false;
     }
 }
            private static int GetY2kPivot(BirthDateFormatInfo info)
            {
                if (info == null ||
                    info.DateTimeFormatInfo == null ||
                    info.DateTimeFormatInfo.Calendar == null) return defaultY2kPivot;

                return info.DateTimeFormatInfo.Calendar.TwoDigitYearMax - 2000;
            }
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance formatted 
 /// according to the specified <paramref name="culture"/>.
 /// </summary>
 /// <param name="culture">The culture used for formatting.</param>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public string ToString(CultureInfo culture)
 {
     var formatInfo = new BirthDateFormatInfo(culture, true);
     return ToString(formatInfo);
 }
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance formatted 
 /// according to the specified <see cref="BirthDateFormatInfo"/> object.
 /// </summary>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>
 /// A <see cref="System.String" /> that represents this instance.
 /// </returns>
 public string ToString(BirthDateFormatInfo info)
 {
     return Formatter.Format(this, info ?? new BirthDateFormatInfo());
 }
 /// <summary>
 /// Converts the string representation of a birth date to a <see cref="BirthDate" /> object.
 /// </summary>
 /// <param name="text">The text to parse.</param>
 /// <param name="info">An object containing formatting and parsing information.</param>
 /// <returns>A <see cref="BirthDate"/> object equivalent to the birth date specified in <paramref name="text"/>.</returns>
 public static BirthDate Parse(string text, BirthDateFormatInfo info)
 {
     if (string.IsNullOrEmpty(text)) throw new ArgumentNullException("text");
     return Parser.Parse(text, info ?? new BirthDateFormatInfo());
 }