Exemple #1
0
        private DateTime GetDate(CultureInfo doc, DateType date)
        {
            DateTime result = default(DateTime);

            if (date == null)
            {
                return(result);
            }

            bool bFailed = false;

            // try to fallback to the document format if the language was missing
            if (String.IsNullOrEmpty(date.lang))
            {
                if (doc != null && !doc.IsNeutralCulture)
                {
                    try {
                        result = XmlConvert.ToDateTime(date.Value,
                                                       new string[] { doc.DateTimeFormat.ShortDatePattern, "yyyy-MM-dd" });
                    } catch { bFailed = true; }
                }
            }
            else
            {
                doc = CultureInfo.CreateSpecificCulture(date.lang + "-" + date.lang);
                if (doc.IsNeutralCulture)
                {
                    bFailed = true;
                }
                else
                {
                    try {
                        result = XmlConvert.ToDateTime(date.Value,
                                                       new string[] { doc.DateTimeFormat.ShortDatePattern, "yyyy-MM-dd" });
                    } catch { bFailed = true; }
                }
            }
            if (bFailed)
            {
                return(default(DateTime));
            }

            return(result);
        }
Exemple #2
0
        private DateTime GetDate(CultureInfo doc, DateType date)
        {
            DateTime result = default(DateTime);
            if (date == null) return result;

            bool bFailed = false;

            // try to fallback to the document format if the language was missing
            if (String.IsNullOrEmpty(date.lang)) {
                if (doc != null && !doc.IsNeutralCulture) {
                    try {
                        result = XmlConvert.ToDateTime(date.Value,
                            new string[] { doc.DateTimeFormat.ShortDatePattern, "yyyy-MM-dd" });
                    } catch { bFailed = true; }
                }
            } else {
                doc = CultureInfo.CreateSpecificCulture(date.lang + "-" + date.lang);
                if (doc.IsNeutralCulture)
                    bFailed = true;
                else {
                    try {
                        result = XmlConvert.ToDateTime(date.Value,
                            new string[] { doc.DateTimeFormat.ShortDatePattern, "yyyy-MM-dd" });
                    } catch { bFailed = true; }
                }
            }
            if (bFailed)
                return default(DateTime);

            return result;
        }