Exemplo n.º 1
0
        private XsdDateTime ParseDate(string value, bool allowTz)
        {
            XsdDateTime tz = new XsdDateTime(DateTime.MinValue, TimeSpan.Zero, TimeSpan.Zero, false, false, false);

            int d1, d2;

            d1 = value.IndexOf('-');
            if (d1 != -1)
            {
                d2 = value.IndexOf('-', d1 + 1);
                if (d2 != -1)
                {
                    if (allowTz)
                    {
                        tz = ParseTZ(ref value, d2 + 1);
                    }
                }
            }

            string[] fields = value.Split('-');
            int      year, month, day;

            if (fields.Length != 3 ||
                !TryParse(fields[0], out year) ||
                !TryParse(fields[1], out month) ||
                !TryParse(fields[2], out day))
            {
                throw new FormatException("Date must look like CCYY-MM-DD");
            }

            return(new XsdDateTime(new DateTime(year, month, day), TimeSpan.Zero, tz.TimeZoneOffset, true, false, tz.HasTimeZoneOffset));
        }
Exemplo n.º 2
0
        private XsdDateTime ParseTime(string value, bool allowTz)
        {
            XsdDateTime tz = new XsdDateTime(DateTime.MinValue, TimeSpan.Zero, TimeSpan.Zero, false, false, false);

            if (allowTz)
            {
                tz = ParseTZ(ref value, 0);
            }

            string[] fields = value.Split(':');
            int      hour, minute;
            float    seconds;

            if (fields.Length != 3 ||
                !TryParse(fields[0], out hour) ||
                !TryParse(fields[1], out minute) ||
                !TryParse(fields[2], out seconds))
            {
                throw new FormatException("Time must look like HH:MM:SS[.SSS]");
            }

            return(new XsdDateTime(DateTime.MinValue, new TimeSpan(hour, minute, 0).Add(TimeSpan.FromSeconds(seconds)), tz.TimeZoneOffset, false, true, tz.HasTimeZoneOffset));
        }