Exemple #1
0
        internal DateTimeOffset DateFromString(string dateTimeString, XmlReader reader)
        {
            try
            {
                DateTimeOffset dateTimeOffset       = default(DateTimeOffset);
                var            elementQualifiedName = new XmlQualifiedName(reader.LocalName, reader.NamespaceURI);
                var            xmlDateTimeData      = new XmlDateTimeData(dateTimeString, elementQualifiedName);
                object[]       args = new object[] { xmlDateTimeData, dateTimeOffset };
                foreach (Delegate dateTimeParser in DateTimeParser.GetInvocationList())
                {
                    if ((bool)dateTimeParser.Method.Invoke(dateTimeParser.Target, args))
                    {
                        dateTimeOffset = (DateTimeOffset)args[args.Length - 1];
                        return(dateTimeOffset);
                    }
                }
            }
            catch (Exception e)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDateTime), e));
            }

            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                      new XmlException(FeedUtils.AddLineInfo(reader, SR.ErrorParsingDateTime)));
        }
        public static bool DefaultRss20DateTimeParser(XmlDateTimeData XmlDateTimeData, out DateTimeOffset dateTimeOffset)
        {
            string dateTimeString = XmlDateTimeData.DateTimeString;

            // First check if DateTimeOffset default parsing can parse the date
            if (DateTimeOffset.TryParse(dateTimeString, out dateTimeOffset))
            {
                return(true);
            }

            // RSS specifies RFC822
            if (Rfc822DateTimeParser(dateTimeString, out dateTimeOffset))
            {
                return(true);
            }

            // Event though RCS3339 is for Atom, someone might be using this for RSS
            if (Rfc3339DateTimeParser(dateTimeString, out dateTimeOffset))
            {
                return(true);
            }

            return(false);
        }
 public static bool DefaultAtom10DateTimeParser(XmlDateTimeData XmlDateTimeData, out DateTimeOffset dateTimeOffset)
 {
     return(Rfc3339DateTimeParser(XmlDateTimeData.DateTimeString, out dateTimeOffset));
 }
 private bool NotImplementedDateTimeParser(XmlDateTimeData XmlDateTimeData, out DateTimeOffset dateTimeOffset)
 {
     dateTimeOffset = default;
     return(false);
 }