Ejemplo n.º 1
0
        /// <summary>
        /// Convert a DateTimeOffset value to its XML equivalent.
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTimeOffsetXml ToDateTimeOffsetXml(DateTimeOffset dateTime)
        {
            DateTimeOffsetXml newObject = new DateTimeOffsetXml();

            newObject.DateTime = dateTime.DateTime;
            newObject.Offset   = (int)dateTime.Offset.TotalMinutes;

            return(newObject);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert the DateTimeOffset XML structure to its native form
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTimeOffset FromDateTimeOffsetXml(DateTimeOffsetXml dateTime)
        {
            if (dateTime == null)
            {
                return(DateTimeOffset.MinValue);
            }

            var sourceDateTime = dateTime.DateTime;

            if (sourceDateTime.Kind != DateTimeKind.Unspecified)
            {
                sourceDateTime = DateTime.SpecifyKind(sourceDateTime, DateTimeKind.Unspecified); //otherwise the DTO onstructor will fail.
            }
            return(new DateTimeOffset(sourceDateTime, new TimeSpan(0, dateTime.Offset, 0)));
        }
Ejemplo n.º 3
0
        private static void DateTimeOffsetXmlToXmlWriter(XmlWriter xmlWriter, string elementName, DateTimeOffsetXml dateTimeOffsetXml)
        {
            if (dateTimeOffsetXml == null)
            {
                return;
            }

            xmlWriter.WriteStartElement(elementName);
            WriteXmlAttribute(xmlWriter, "DateTime", dateTimeOffsetXml.DateTime);
            WriteXmlAttribute(xmlWriter, "Offset", dateTimeOffsetXml.Offset);
            xmlWriter.WriteEndElement();
        }