This structure extends System.DateTime to support timeInTicks zone and Gregorian types scomponents of an Xsd Duration. It is used internally to support Xsd durations without loss of fidelity. XsdDuration structures are immutable once they've been created.
        internal override Exception TryParseValue(string s, XmlNameTable nameTable, IXmlNamespaceResolver nsmgr, out object typedValue)
        {
            typedValue = null;
            Exception exception = DatatypeImplementation.dateTimeFacetsChecker.CheckLexicalFacets(ref s, this);

            if (exception == null)
            {
                XsdDateTime time;
                if (!XsdDateTime.TryParse(s, this.dateTimeFlags, out time))
                {
                    return(new FormatException(Res.GetString("XmlConvert_BadFormat", new object[] { s, this.dateTimeFlags.ToString() })));
                }
                DateTime minValue = DateTime.MinValue;
                try
                {
                    minValue = (DateTime)time;
                }
                catch (ArgumentException exception2)
                {
                    return(exception2);
                }
                exception = DatatypeImplementation.dateTimeFacetsChecker.CheckValueFacets(minValue, this);
                if (exception == null)
                {
                    typedValue = minValue;
                    return(null);
                }
            }
            return(exception);
        }
 public XsdDateTime(string text, XsdDateTimeFlags kinds)
 {
     this = new XsdDateTime();
     Parser parser = new Parser();
     if (!parser.Parse(text, kinds))
     {
         throw new FormatException(Res.GetString("XmlConvert_BadFormat", new object[] { text, kinds }));
     }
     this.InitiateXsdDateTime(parser);
 }
 internal static bool TryParse(string text, XsdDateTimeFlags kinds, out XsdDateTime result)
 {
     Parser parser = new Parser();
     if (!parser.Parse(text, kinds))
     {
         result = new XsdDateTime();
         return false;
     }
     result = new XsdDateTime(parser);
     return true;
 }
Esempio n. 4
0
        public XsdDateTime(string text, XsdDateTimeFlags kinds)
        {
            this = new XsdDateTime();
            Parser parser = new Parser();

            if (!parser.Parse(text, kinds))
            {
                throw new FormatException(Res.GetString("XmlConvert_BadFormat", new object[] { text, kinds }));
            }
            this.InitiateXsdDateTime(parser);
        }
Esempio n. 5
0
        internal static bool TryParse(string text, XsdDateTimeFlags kinds, out XsdDateTime result)
        {
            Parser parser = default;

            if (!parser.Parse(text, kinds))
            {
                result = default;
                return(false);
            }
            result = new XsdDateTime(parser);
            return(true);
        }
Esempio n. 6
0
 public static int Compare(XsdDateTime left, XsdDateTime right)
 {
     if (left.extra == right.extra)
     {
         return(DateTime.Compare(left.dt, right.dt));
     }
     if (left.InternalTypeCode != right.InternalTypeCode)
     {
         throw new ArgumentException(Res.GetString("Sch_XsdDateTimeCompare", new object[] { left.TypeCode, right.TypeCode }));
     }
     return(DateTime.Compare(left.GetZuluDateTime(), right.GetZuluDateTime()));
 }
Esempio n. 7
0
 /// <summary>
 /// Compares two DateTime values, returning an integer that indicates
 /// their relationship.
 /// </summary>
 public static int Compare(XsdDateTime left, XsdDateTime right)
 {
     if (left._extra == right._extra)
     {
         return(DateTime.Compare(left._dt, right._dt));
     }
     else
     {
         // Xsd types should be the same for it to be comparable
         if (left.InternalTypeCode != right.InternalTypeCode)
         {
             throw new ArgumentException(SR.Format(SR.Sch_XsdDateTimeCompare, left.TypeCode, right.TypeCode));
         }
         // Convert both to UTC
         return(DateTime.Compare(left.GetZuluDateTime(), right.GetZuluDateTime()));
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Compares two DateTime values, returning an integer that indicates
        /// their relationship.
        /// </summary>
        public static int Compare(XsdDateTime left, XsdDateTime right) {
            if (left.extra == right.extra) {
                return DateTime.Compare(left.dt, right.dt);
            }
            else {
                // Xsd types should be the same for it to be comparable
                if (left.InternalTypeCode != right.InternalTypeCode) {
                    throw new ArgumentException(Res.GetString(Res.Sch_XsdDateTimeCompare, left.TypeCode, right.TypeCode));
                }
                // Convert both to UTC
                return DateTime.Compare(left.GetZuluDateTime(), right.GetZuluDateTime());

            }
        }
Esempio n. 9
0
 private XsdDateTime(Parser parser)
 {
     this = new XsdDateTime();
     this.InitiateXsdDateTime(parser);
 }
 private XsdDateTime(Parser parser)
 {
     this = new XsdDateTime();
     this.InitiateXsdDateTime(parser);
 }
 protected static string GMonthDayToString(DateTime value)
 {
     XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GMonthDay);
     return time.ToString();
 }
        public static string ToString(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
        {
            switch (dateTimeOption)
            {
                case XmlDateTimeSerializationMode.Local:
                    value = SwitchToLocalTime(value);
                    break;

                case XmlDateTimeSerializationMode.Utc:
                    value = SwitchToUtcTime(value);
                    break;

                case XmlDateTimeSerializationMode.Unspecified:
                    value = new DateTime(value.Ticks, DateTimeKind.Unspecified);
                    break;

                case XmlDateTimeSerializationMode.RoundtripKind:
                    break;

                default:
                    throw new ArgumentException(Res.GetString("Sch_InvalidDateTimeOption", new object[] { dateTimeOption, "dateTimeOption" }));
            }
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.DateTime);
            return time.ToString();
        }
 public static DateTimeOffset ToDateTimeOffset(string s)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     XsdDateTime time = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
     return (DateTimeOffset) time;
 }
Esempio n. 14
0
 public static DateTimeOffset ToDateTimeOffset(string s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     XsdDateTime xsdDateTime = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
     DateTimeOffset dateTimeOffset = (DateTimeOffset)xsdDateTime;
     return dateTimeOffset;
 }
 protected static string TimeToString(DateTime value)
 {
     XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.Time);
     return time.ToString();
 }
 protected static string GYearOffsetToString(DateTimeOffset value)
 {
     XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYear);
     return time.ToString();
 }
 protected static string GYearMonthToString(DateTime value)
 {
     XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYearMonth);
     return time.ToString();
 }
Esempio n. 18
0
        ///<include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.ToDateTime3"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static DateTime ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption)
        {
            XsdDateTime xsdDateTime = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
            DateTime dt = (DateTime)xsdDateTime;

            switch (dateTimeOption)
            {
                case XmlDateTimeSerializationMode.Local:
                    dt = SwitchToLocalTime(dt);
                    break;

                case XmlDateTimeSerializationMode.Utc:
                    dt = SwitchToUtcTime(dt);
                    break;

                case XmlDateTimeSerializationMode.Unspecified:
                    dt = new DateTime(dt.Ticks, DateTimeKind.Unspecified);
                    break;

                case XmlDateTimeSerializationMode.RoundtripKind:
                    break;

                default:
                    throw new ArgumentException(SR.Format(SR.Sch_InvalidDateTimeOption, dateTimeOption, "dateTimeOption"));
            }
            return dt;
        }
Esempio n. 19
0
        ///<include file='doc\XmlConvert.uex' path='docs/doc[@for="XmlConvert.ToString14"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public static string ToString(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
        {
            switch (dateTimeOption)
            {
                case XmlDateTimeSerializationMode.Local:
                    value = SwitchToLocalTime(value);
                    break;

                case XmlDateTimeSerializationMode.Utc:
                    value = SwitchToUtcTime(value);
                    break;

                case XmlDateTimeSerializationMode.Unspecified:
                    value = new DateTime(value.Ticks, DateTimeKind.Unspecified);
                    break;

                case XmlDateTimeSerializationMode.RoundtripKind:
                    break;

                default:
                    throw new ArgumentException(SR.Format(SR.Sch_InvalidDateTimeOption, dateTimeOption, nameof(dateTimeOption)));
            }
            XsdDateTime xsdDateTime = new XsdDateTime(value, XsdDateTimeFlags.DateTime);
            return xsdDateTime.ToString();
        }
        public static DateTime ToDateTime(string s, XmlDateTimeSerializationMode dateTimeOption)
        {
            XsdDateTime time = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
            DateTime time2 = (DateTime) time;
            switch (dateTimeOption)
            {
                case XmlDateTimeSerializationMode.Local:
                    return SwitchToLocalTime(time2);

                case XmlDateTimeSerializationMode.Utc:
                    return SwitchToUtcTime(time2);

                case XmlDateTimeSerializationMode.Unspecified:
                    return new DateTime(time2.Ticks, DateTimeKind.Unspecified);

                case XmlDateTimeSerializationMode.RoundtripKind:
                    return time2;
            }
            throw new ArgumentException(Res.GetString("Sch_InvalidDateTimeOption", new object[] { dateTimeOption, "dateTimeOption" }));
        }
Esempio n. 21
0
        protected static string GYearMonthToString(DateTime value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYearMonth);

            return(time.ToString());
        }
 public static string ToString(DateTimeOffset value)
 {
     XsdDateTime time = new XsdDateTime(value);
     return time.ToString();
 }
Esempio n. 23
0
        protected static string GYearOffsetToString(DateTimeOffset value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYear);

            return(time.ToString());
        }
Esempio n. 24
0
        protected static string TimeToString(DateTime value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.Time);

            return(time.ToString());
        }
 public static int Compare(XsdDateTime left, XsdDateTime right)
 {
     if (left.extra == right.extra)
     {
         return DateTime.Compare(left.dt, right.dt);
     }
     if (left.InternalTypeCode != right.InternalTypeCode)
     {
         throw new ArgumentException(Res.GetString("Sch_XsdDateTimeCompare", new object[] { left.TypeCode, right.TypeCode }));
     }
     return DateTime.Compare(left.GetZuluDateTime(), right.GetZuluDateTime());
 }