CookComputing.XmlRpc.XmlRpcSerializer.ParseDateTime C# (CSharp) Method

ParseDateTime() private method

private ParseDateTime ( XmlNode node, Type ValueType, ParseStack parseStack, MappingAction mappingAction ) : Object
node System.Xml.XmlNode
ValueType System.Type
parseStack ParseStack
mappingAction MappingAction
return Object
        Object ParseDateTime(
            XmlNode node,
            Type ValueType,
            ParseStack parseStack,
            MappingAction mappingAction)
        {
            if (ValueType != null && ValueType != typeof(Object)
            && ValueType != typeof(System.DateTime)
            #if !FX1_0
            && ValueType != typeof(DateTime?)
            #endif
            && ValueType != typeof(XmlRpcDateTime))
              {
            throw new XmlRpcTypeMismatchException(parseStack.ParseType
              + " contains dateTime.iso8601 value where "
              + XmlRpcServiceInfo.GetXmlRpcTypeString(ValueType)
              + " expected " + StackDump(parseStack));
              }
              DateTime retVal;
              parseStack.Push("dateTime");
              try
              {
            XmlNode child = node.FirstChild;
            if (child == null)
            {
              if (MapEmptyDateTimeToMinValue)
            return DateTime.MinValue;
              else
            throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
              + " contains empty dateTime value "
              + StackDump(parseStack));
            }
            string s = child.Value;
            try
            {
              // XML-RPC spec yyyyMMddThh:mm:ss
              string dateTimeFormat = "yyyyMMdd'T'HH':'mm':'ss";
              if (AllowNonStandardDateTime)
              {
            if (s.IndexOf("T") == 8)
            {
              if (s.EndsWith("Z"))
              {
                // WordPress yyyyMMddThh:mm:ssZ
                dateTimeFormat = "yyyyMMdd'T'HH':'mm':'ss'Z'";
              }
              else if (s.EndsWith("-00") || s.EndsWith("-0000")
                || s.EndsWith("+00") || s.EndsWith("+0000"))
              {
                s = s.Substring(0, 17);
              }
            }
            else
            {
              if (s.EndsWith("Z"))
              {
                // TypePad yyyy-MM-ddThh:mm:ssZ
                dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'";
              }
              else
              {
                // other yyyy-MM-ddThh:mm:ss
                dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
              }
            }
              }
              if (MapZerosDateTimeToMinValue && s.StartsWith("0000")
            && (s == "00000000T00:00:00" || s == "0000-00-00T00:00:00Z"
            || s == "00000000T00:00:00Z" || s == "0000-00-00T00:00:00"))
            retVal = DateTime.MinValue;
              else
            retVal = DateTime.ParseExact(s, dateTimeFormat,
              DateTimeFormatInfo.InvariantInfo);
            }
            catch(Exception)
            {
              throw new XmlRpcInvalidXmlRpcException(parseStack.ParseType
            + " contains invalid dateTime value "
            + StackDump(parseStack));
            }
              }
              finally
              {
            parseStack.Pop();
              }
              if (ValueType == typeof(XmlRpcDateTime))
            return new XmlRpcDateTime(retVal);
              else
            return retVal;
        }