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.
コード例 #1
0
        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);
        }
コード例 #2
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);
 }
コード例 #3
0
 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;
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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()));
 }
コード例 #7
0
ファイル: XsdDateTime.cs プロジェクト: berkaroad/dotnetcorefx
 /// <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()));
     }
 }
コード例 #8
0
ファイル: XsdDateTime.cs プロジェクト: uQr/referencesource
        /// <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());

            }
        }
コード例 #9
0
 private XsdDateTime(Parser parser)
 {
     this = new XsdDateTime();
     this.InitiateXsdDateTime(parser);
 }
コード例 #10
0
 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();
 }
コード例 #12
0
        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();
        }
コード例 #13
0
 public static DateTimeOffset ToDateTimeOffset(string s)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     XsdDateTime time = new XsdDateTime(s, XsdDateTimeFlags.AllXsd);
     return (DateTimeOffset) time;
 }
コード例 #14
0
ファイル: XmlConvert.cs プロジェクト: shiftkey-tester/corefx
 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();
 }
コード例 #18
0
ファイル: XmlConvert.cs プロジェクト: shiftkey-tester/corefx
        ///<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;
        }
コード例 #19
0
ファイル: XmlConvert.cs プロジェクト: dotnet/corefx
        ///<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();
        }
コード例 #20
0
        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" }));
        }
コード例 #21
0
        protected static string GYearMonthToString(DateTime value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYearMonth);

            return(time.ToString());
        }
コード例 #22
0
 public static string ToString(DateTimeOffset value)
 {
     XsdDateTime time = new XsdDateTime(value);
     return time.ToString();
 }
コード例 #23
0
        protected static string GYearOffsetToString(DateTimeOffset value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.GYear);

            return(time.ToString());
        }
コード例 #24
0
        protected static string TimeToString(DateTime value)
        {
            XsdDateTime time = new XsdDateTime(value, XsdDateTimeFlags.Time);

            return(time.ToString());
        }
コード例 #25
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());
 }